Exporting symbols of imported module

Suppose I write a module A that imports another module B but I want users that do using A to also have access of symbols exported from B.
If I do

module B
import A
export A.x
end

then I get

ERROR: LoadError: syntax: extra token "." after end of expression

Is there any workaround ?

See Decide what to export · Issue #1761 · jump-dev/JuMP.jl · GitHub for the context.

Yes:

julia> module A
       foo() = 42
       end
Main.A

julia> module B
       import ..A   # Would be simply `import A` if A were in the load path rather than in Main
       const foo = A.foo
       export foo
       end
Main.B

julia> using .B

julia> foo()
42

Note that this is better than the alternative of import A: foo; export foo because it allows tab completion of A.<TAB> to work. (A binding must not be marked as imported-from-another-module for tab completion to consider it.)

Thank you for your answer. However, I would like to export all symbols exported by A (like what could be done by @reexport import A if Reexport were to support this syntax). With your solution, this would mean doing import A; const foo = A.foo for all symbols exported by A which is equivalent to using A. Is it possible to do it without making the symbols of A accessible inside module B ?

Not that I’m aware of.

Why do you want to do this? It seems a little odd to decide that the user wants those symbols after doing using B, even though they’re never available within B.

For a JuMP extension like SumOfSquares, we would like to user to only have to do using SumOfSquares and not using SumOfSquares, JuMP hence we are doing @reexport using JuMP (see Reexport JuMP by blegat · Pull Request #68 · jump-dev/SumOfSquares.jl · GitHub).
However, we would like to recommend all non-“throw-away script” to do import JuMP instead of using JuMP (see style point on using vs import by mlubin · Pull Request #1778 · jump-dev/JuMP.jl · GitHub).
Hence we would like to do import JuMP in JuMP extensions but also reexport all JuMP symbols (see Decide what to export · Issue #1761 · jump-dev/JuMP.jl · GitHub).

Looking at the code, I think there’s no way to “export without import” because using brings in bindings from the source module which have the exportp flag set:

seems reasonable enough.