Skip to content

Commit

Permalink
fix: Use hygiene_with_config instead of hygiene (#8848)
Browse files Browse the repository at this point in the history
### Description

<!--
  ✍️ Write a short summary of your work.
  If necessary, include relevant screenshots.
-->

### Testing Instructions

<!--
  Give a quick description of steps to test your changes.
-->

---------

Co-authored-by: 강동윤 (Donny) <[email protected]>
  • Loading branch information
sokra and kdy1 authored Jul 29, 2024
1 parent 496def6 commit aeecec6
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
9 changes: 8 additions & 1 deletion crates/turbopack-ecmascript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
});

0 comments on commit aeecec6

Please sign in to comment.