From 4da3a56c5c3038867f153e5b7491f583bdcd6bd4 Mon Sep 17 00:00:00 2001 From: Paul Berg Date: Mon, 9 Sep 2024 09:58:52 +0200 Subject: [PATCH] doreimports after moving variables (#2955) --- .../src/evaluation/deleting globals.jl | 6 ++-- test/React.jl | 36 +++++++++++++++++++ 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/runner/PlutoRunner/src/evaluation/deleting globals.jl b/src/runner/PlutoRunner/src/evaluation/deleting globals.jl index b918d80fe8..0e8ce45536 100644 --- a/src/runner/PlutoRunner/src/evaluation/deleting globals.jl +++ b/src/runner/PlutoRunner/src/evaluation/deleting globals.jl @@ -34,13 +34,11 @@ function move_vars( old_workspace = getfield(Main, old_workspace_name) new_workspace = getfield(Main, new_workspace_name) - do_reimports(new_workspace, module_imports_to_move) - for cell_id in cells_to_macro_invalidate delete!(cell_expanded_exprs, cell_id) end foreach(unregister_js_link, cells_to_js_link_invalidate) - + # TODO: delete Core.eval(new_workspace, :(import ..($(old_workspace_name)))) @@ -96,6 +94,8 @@ function move_vars( end end + do_reimports(new_workspace, module_imports_to_move) + revise_if_possible(new_workspace) end diff --git a/test/React.jl b/test/React.jl index 4aa0bac071..1015c7f7ac 100644 --- a/test/React.jl +++ b/test/React.jl @@ -1053,4 +1053,40 @@ import Pluto.Configuration: Options, EvaluationOptions @test startswith(notebook.cells[2].output.body[:msg], "syntax:") end end + + @testset "using .LocalModule" begin + notebook = Notebook(Cell.([ + """ + begin + @eval module LocalModule + const x = :exported + export x + end + using .LocalModule + end + """, + "x" + ])) + update_run!(🍭, notebook, notebook.cells) + @test notebook.cells[1] |> noerror + @test notebook.cells[2] |> noerror + + output_2 = notebook.cells[2].output.body + @test contains(output_2, "exported") + + setcode!( + notebook.cells[1], + """ + begin + @eval module LocalModule + const x = :not_exported + end + using .LocalModule + end + """, + ) + + update_run!(🍭, notebook, [notebook.cells[1]]) + @test expecterror(UndefVarError(:x), notebook.cells[end]) + end end