Skip to content

Commit 5536500

Browse files
committed
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.
1 parent 4777e60 commit 5536500

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/stylemacro.jl

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ macro styled_str(raw_content::String)
145145
nothing
146146
end
147147

148+
hygienic_eval(expr) = Core.eval(__module__, Expr(:var"hygienic-scope", expr, @__MODULE__))
149+
148150
function addpart!(state, stop::Int)
149151
if state.point[] > stop+state.offset[]+ncodeunits(state.content[stop])-1
150152
return state.point[] = nextind(state.content, stop) + state.offset[]
@@ -537,7 +539,7 @@ macro styled_str(raw_content::String)
537539
if needseval
538540
:(Pair{Symbol, Any}(:face, $face))
539541
else
540-
Pair{Symbol, Any}(:face, eval(face))
542+
Pair{Symbol, Any}(:face, hygienic_eval(face))
541543
end))
542544
end
543545

@@ -669,7 +671,7 @@ macro styled_str(raw_content::String)
669671
elseif state.interpolated[]
670672
:(annotatedstring($(state.parts...)))
671673
else
672-
annotatedstring(map(eval, state.parts)...) |> Base.annotatedstring_optimize!
674+
annotatedstring(map(hygienic_eval, state.parts)...) |> Base.annotatedstring_optimize!
673675
end
674676
end
675677

0 commit comments

Comments
 (0)