Skip to content

Commit f0d5b25

Browse files
ararslandevmotion
andauthored
Cover more cases for baremodule use (#34)
* Cover more cases for baremodule use * Interpolate `Core.eval` calls Co-Authored-By: David Widmann <[email protected]> Co-authored-by: David Widmann <[email protected]>
1 parent fd87dbf commit f0d5b25

File tree

3 files changed

+32
-11
lines changed

3 files changed

+32
-11
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Reexport"
22
uuid = "189a3867-3050-52da-a836-e630ba90ab69"
33
authors = ["Simon Kornblith <[email protected]>"]
4-
version = "1.2.1"
4+
version = "1.2.2"
55

66
[compat]
77
julia = "1"

src/Reexport.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,20 @@ function reexport(m::Module, ex::Expr)
1818
ex.head === :toplevel && all(e -> isa(e, Expr) && e.head === :using, ex.args) ||
1919
error("@reexport: syntax error")
2020

21+
eval = GlobalRef(Core, :eval)
22+
2123
if ex.head === :module
2224
# @reexport {using, import} module Foo ... end
2325
modules = Any[ex.args[2]]
2426
ex = Expr(:toplevel, ex, :(using .$(ex.args[2])))
2527
elseif ex.head in (:using, :import) && ex.args[1].head == :(:)
2628
# @reexport {using, import} Foo: bar, baz
2729
symbols = [e.args[end] for e in ex.args[1].args[2:end]]
28-
return Expr(:toplevel, ex, :(eval(Expr(:export, $symbols...))))
30+
return Expr(:toplevel, ex, :($eval($m, Expr(:export, $symbols...))))
2931
elseif ex.head === :import && all(e -> e.head === :., ex.args)
3032
# @reexport import Foo.bar, Baz.qux
3133
symbols = Any[e.args[end] for e in ex.args]
32-
return Expr(:toplevel, ex, :(eval(Expr(:export, $symbols...))))
34+
return Expr(:toplevel, ex, :($eval($m, Expr(:export, $symbols...))))
3335
else
3436
# @reexport using Foo, Bar, Baz
3537
modules = Any[e.args[end] for e in ex.args]
@@ -38,7 +40,7 @@ function reexport(m::Module, ex::Expr)
3840
names = GlobalRef(@__MODULE__, :exported_names)
3941
out = Expr(:toplevel, ex)
4042
for mod in modules
41-
push!(out.args, :(Core.eval($m, Expr(:export, $names($mod)...))))
43+
push!(out.args, :($eval($m, Expr(:export, $names($mod)...))))
4244
end
4345
return out
4446
end

test/runtests.jl

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,30 @@ end
219219
@test Set(names(X15)) == Set([:X15, :a])
220220
end
221221

222-
baremodule B16
223-
using Reexport
224-
@reexport using Test
225-
end
226-
using .B16
227-
@testset "baremodule" begin
228-
@test Base.isexported(B16, Symbol("@test"))
222+
module X16
223+
using Reexport, Test
224+
baremodule A
225+
using Reexport
226+
@reexport using Test
227+
end
228+
baremodule B
229+
using Reexport
230+
@reexport using Test: @testset
231+
end
232+
baremodule C
233+
using Reexport
234+
@reexport import Test.@test
235+
end
236+
baremodule D
237+
using Reexport
238+
# Ensure that there are no module name conflicts with Core
239+
baremodule Core
240+
end
241+
end
242+
@testset "baremodule" begin
243+
@test Base.isexported(A, Symbol("@test"))
244+
@test Reexport.exported_names(B) == [Symbol("@testset"), :B]
245+
@test Reexport.exported_names(C) == [Symbol("@test"), :C]
246+
@test Reexport.exported_names(D) == [:D]
247+
end
229248
end

0 commit comments

Comments
 (0)