@@ -28,8 +28,29 @@ function remove_pluto_exprs(ex)
2828end
2929remove_pluto_exprs (ex, args... ) = remove_pluto_exprs (ex)
3030
31+ # This will substitute PackageName with the correct path pointed to the loaded module
32+ function modify_package_using! (ex:: Expr , loc, package_dict:: Dict , eval_module:: Module )
33+ Meta. isexpr (ex, (:using , :import )) || return true
34+ package_name = Symbol (package_dict[" name" ])
35+ package_exprs = if length (ex. args) === 1
36+ # We are in the form import PkgName: vars...
37+ package_expr, _ = extract_import_args (ex)
38+ [package_expr]
39+ else
40+ # We are in the form import PkgA, PkgB
41+ ex. args
42+ end
43+ for package_expr in package_exprs
44+ package_expr_args = package_expr. args
45+ extracted_package_name = first (package_expr_args)
46+ if extracted_package_name === package_name
47+ prepend! (package_expr_args, modname_path (fromparent_module[]))
48+ end
49+ end
50+ return true
51+ end
52+
3153# This will simply make the using/import statements of the calling package point to the parent module
32- modify_extension_using! (x, args... ) = true
3354function modify_extension_using! (ex:: Expr , loc, package_dict:: Dict , eval_module:: Module )
3455 Meta. isexpr (ex, (:using , :import )) || return true
3556 has_extensions (package_dict) || return true
@@ -46,10 +67,7 @@ function modify_extension_using!(ex::Expr, loc, package_dict::Dict, eval_module:
4667 package_expr, _ = extract_import_args (ex)
4768 package_expr_args = package_expr. args
4869 extracted_package_name = first (package_expr_args)
49- if extracted_package_name === package_name
50- # We just add .. to the name because the extension module was added to the toplevel of the parent
51- prepend! (package_expr_args, (:., :.))
52- elseif extracted_package_name === weakdep
70+ if extracted_package_name === weakdep
5371 # We first add :_LoadedModules_
5472 pushfirst! (package_expr_args, :_LoadedModules_ )
5573 # We also add the module path of the fromparent_module which contains _LoadedModules_
@@ -77,7 +95,7 @@ function process_expr!(ex, loc, dict, eval_module)
7795 ex isa Expr || return true # Apart from Nothing, we keep everything that is not an expr
7896 _is_block (ex) && return process_block! (ex, loc, dict, eval_module)
7997 _is_include (ex) && error (" A call to include not at toplevel was found around line $loc . This is not permitted" )
80- keep = all ((remove_pluto_exprs, modify_extension_using!)) do f
98+ keep = all ((remove_pluto_exprs, modify_package_using!, modify_extension_using!)) do f
8199 f (ex, loc, dict, eval_module)
82100 end
83101end
0 commit comments