Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Use hygiene_with_config instead of hygiene #8848

Merged
merged 2 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moduleFunciton -> moduleFunction

"use strict";
return eval("module");
}
expect(modules.x(42)).toBe(42);
expect(moduleArrowFunction(42)).toBe(42);
expect(moduleFunciton(42)).toBe(42);
});
Loading