Skip to content

Commit

Permalink
make striplines non-recursive by default
Browse files Browse the repository at this point in the history
  • Loading branch information
hhaensel committed Nov 25, 2024
1 parent 30690b8 commit 2ee6557
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/ReactiveTools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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])
Expand Down
12 changes: 6 additions & 6 deletions src/Tools.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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))
striplines(ex; recursive::Bool = false) = striplines!(copy(ex); recursive)

0 comments on commit 2ee6557

Please sign in to comment.