Skip to content

Commit 9bf932c

Browse files
mischniclukesandberg
authored andcommitted
Turbopack: fix scope hoisting variable renaming bug (#81640)
1 parent 6d0ffcc commit 9bf932c

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

turbopack/crates/turbopack-ecmascript/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,7 +2062,7 @@ fn hygiene_rename_only(
20622062
}
20632063
// Copied from `hygiene_with_config`'s HygieneRenamer, but added an `preserved_exports`
20642064
impl swc_core::ecma::transforms::base::rename::Renamer for HygieneRenamer<'_> {
2065-
type Target = Atom;
2065+
type Target = Id;
20662066

20672067
const MANGLE: bool = false;
20682068
const RESET_N: bool = true;
@@ -2081,7 +2081,7 @@ fn hygiene_rename_only(
20812081
self.preserved_exports.contains(orig) || orig.1.has_mark(self.is_import_mark)
20822082
}
20832083
}
2084-
swc_core::ecma::transforms::base::rename::renamer(
2084+
swc_core::ecma::transforms::base::rename::renamer_keep_contexts(
20852085
swc_core::ecma::transforms::base::hygiene::Config {
20862086
top_level_mark: top_level_mark.unwrap_or_default(),
20872087
..Default::default()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { foo } from './internal/index.js'
2+
3+
it('should correctly rename imports', () => {
4+
expect(foo({})).toBe(true)
5+
})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import './patch-other.js'
2+
import { patch as patch2 } from './patch.js'
3+
4+
export const bar = (patch) => patch + 1
5+
export const foo = (patch) => patch !== patch2
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function patch() {
2+
return 2
3+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function patch() {
2+
return 1
3+
}

0 commit comments

Comments
 (0)