From 9f804f8e5247b6b49d84801df7107a6493e58663 Mon Sep 17 00:00:00 2001 From: TEC Date: Tue, 24 Oct 2023 01:15:08 +0800 Subject: [PATCH] Replace within-module eval with hygienic eval The use of eval makes precompilation funky due to the within-module eval during precompilation. Evaluation within the calling module doesn't work either because macro hygiene hasn't been applied yet. The solution: apply hygiene ourselves then eval within the calling module. --- src/stylemacro.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/stylemacro.jl b/src/stylemacro.jl index e03a5217..baa68b07 100644 --- a/src/stylemacro.jl +++ b/src/stylemacro.jl @@ -145,6 +145,8 @@ macro styled_str(raw_content::String) nothing end + hygienic_eval(expr) = Core.eval(__module__, Expr(:var"hygienic-scope", expr, @__MODULE__)) + function addpart!(state, stop::Int) if state.point[] > stop+state.offset[]+ncodeunits(state.content[stop])-1 return state.point[] = nextind(state.content, stop) + state.offset[] @@ -537,7 +539,7 @@ macro styled_str(raw_content::String) if needseval :(Pair{Symbol, Any}(:face, $face)) else - Pair{Symbol, Any}(:face, eval(face)) + Pair{Symbol, Any}(:face, hygienic_eval(face)) end)) end @@ -669,7 +671,7 @@ macro styled_str(raw_content::String) elseif state.interpolated[] :(annotatedstring($(state.parts...))) else - annotatedstring(map(eval, state.parts)...) |> Base.annotatedstring_optimize! + annotatedstring(map(hygienic_eval, state.parts)...) |> Base.annotatedstring_optimize! end end