From 8dc71379136f7380460355592a9f94428b76f3bf Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Tue, 9 Aug 2022 21:46:34 +0800 Subject: [PATCH] Disallow import index in closures also. --- src/parser.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/parser.rs b/src/parser.rs index dfedd301..d305bb1b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -1360,8 +1360,15 @@ impl Engine { #[cfg(not(feature = "no_module"))] { - new_state.imports.clone_from(&state.imports); + // Do not allow storing an index to a globally-imported module + // just in case the function is separated from this `AST`. + // + // Keep them in `global_imports` instead so that strict variables + // mode will not complain. new_state.global_imports.clone_from(&state.global_imports); + new_state + .global_imports + .extend(state.imports.iter().cloned()); } #[cfg(not(feature = "unchecked"))]