From 2ee6557bac72d904b50d52d62ecf4f0cd4a7404d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Helmut=20H=C3=A4nsel?= Date: Mon, 25 Nov 2024 01:21:35 +0100 Subject: [PATCH] make striplines non-recursive by default --- src/ReactiveTools.jl | 8 ++++---- src/Tools.jl | 12 ++++++------ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ReactiveTools.jl b/src/ReactiveTools.jl index a408198..7b45334 100644 --- a/src/ReactiveTools.jl +++ b/src/ReactiveTools.jl @@ -447,9 +447,9 @@ function parse_macros(expr::Expr, storage::LittleDict, m::Module) source = filter(x -> x isa LineNumberNode, expr.args) source = isempty(source) ? "" : last(source) - expr = striplines!(copy(expr)) + striplines!(expr) params = expr.args[2:end] - + if fn != :mixin if length(params) == 1 expr = params @@ -460,7 +460,7 @@ function parse_macros(expr::Expr, storage::LittleDict, m::Module) end reactive = flag != :non_reactive - var, ex = parse_expression(params[1], mode, source) + var, ex = parse_expression(expr[1], mode, source) storage[var] = ex elseif fn == :mixin mixin, prefix, postfix = parse_mixin_params(params) @@ -590,8 +590,8 @@ Return a list of all non-internal variable names used in a vector of var definit """ function get_varnames(app_expr::Vector, context::Module) varnames = copy(Stipple.AUTOFIELDS) - app_expr = striplines(app_expr) for ex in app_expr + ex isa LineNumberNode && continue if ex.args[1] ∈ [Symbol("@in"), Symbol("@out"), Symbol("@jsfunction"), Symbol("@private")] res = Stipple.parse_expression(ex) push!(varnames, res isa Symbol ? res : res[1]) diff --git a/src/Tools.jl b/src/Tools.jl index 1ef4e47..5d3294c 100644 --- a/src/Tools.jl +++ b/src/Tools.jl @@ -217,22 +217,22 @@ end Remove all line number nodes from an expression or vector of expressions. See also `striplines`. """ -function striplines!(ex::Expr) +function striplines!(ex::Expr; recursive::Bool = false) for i in reverse(eachindex(ex.args)) - if isa(ex.args[i], LineNumberNode) + if isa(ex.args[i], LineNumberNode) && (ex.head != :macrocall || i > 1) deleteat!(ex.args, i) - elseif isa(ex.args[i], Expr) + elseif isa(ex.args[i], Expr) && recursive striplines!(ex.args[i]) end end ex end -function striplines!(exprs::Vector) +function striplines!(exprs::Vector; recursive::Bool = false) for i in reverse(eachindex(exprs)) if isa(exprs[i], LineNumberNode) deleteat!(exprs, i) - elseif isa(exprs[i], Expr) + elseif isa(exprs[i], Expr) && recursive striplines!(exprs[i]) end end @@ -244,4 +244,4 @@ end Return a copy of an expression with all line number nodes removed. See also `striplines!`. """ -striplines(ex) = striplines!(copy(ex)) \ No newline at end of file +striplines(ex; recursive::Bool = false) = striplines!(copy(ex); recursive) \ No newline at end of file