diff --git a/crates/turbopack-ecmascript/src/lib.rs b/crates/turbopack-ecmascript/src/lib.rs index ea2d6e7ed3536..1a953ee00594a 100644 --- a/crates/turbopack-ecmascript/src/lib.rs +++ b/crates/turbopack-ecmascript/src/lib.rs @@ -803,7 +803,14 @@ async fn gen_content_with_visitors( for visitor in root_visitors { program.visit_mut_with(&mut visitor.create()); } - program.visit_mut_with(&mut swc_core::ecma::transforms::base::hygiene::hygiene()); + program.visit_mut_with( + &mut swc_core::ecma::transforms::base::hygiene::hygiene_with_config( + swc_core::ecma::transforms::base::hygiene::Config { + top_level_mark: eval_context.top_level_mark, + ..Default::default() + }, + ), + ); program.visit_mut_with(&mut swc_core::ecma::transforms::base::fixer::fixer(None)); // we need to remove any shebang before bundling as it's only valid as the first diff --git a/crates/turbopack-tests/tests/execution/turbopack/renaming/eval/input/index.js b/crates/turbopack-tests/tests/execution/turbopack/renaming/eval/input/index.js new file mode 100644 index 0000000000000..6eb723ffc7200 --- /dev/null +++ b/crates/turbopack-tests/tests/execution/turbopack/renaming/eval/input/index.js @@ -0,0 +1,21 @@ +module; // <- This is important! + +it("should not rename variables when eval is used", () => { + const modules = { + x: (module) => { + "use strict"; + return eval("module"); + }, + }; + const moduleArrowFunction = (module) => { + "use strict"; + return eval("module"); + }; + function moduleFunciton(module) { + "use strict"; + return eval("module"); + } + expect(modules.x(42)).toBe(42); + expect(moduleArrowFunction(42)).toBe(42); + expect(moduleFunciton(42)).toBe(42); +});