Skip to content

Commit f416aff

Browse files
authored
fix(es/decorator): Preserve state while traversing the module_items scope (#8556)
**Related issue:** - Closes #8551
1 parent 5f9b7b4 commit f416aff

File tree

4 files changed

+38
-2
lines changed

4 files changed

+38
-2
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"jsc": {
3+
"parser": {
4+
"syntax": "typescript",
5+
"decorators": true
6+
},
7+
"transform": {
8+
"decoratorVersion": "2022-03"
9+
},
10+
"target": "es2022"
11+
},
12+
"isModule": true
13+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class C {
2+
[Symbol.iterator]() { }
3+
}
4+
5+
namespace NS {
6+
export function f() { }
7+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
var _computedKey;
2+
_computedKey = Symbol.iterator;
3+
class C {
4+
[_computedKey]() {}
5+
}
6+
var NS;
7+
(function(NS) {
8+
function f() {}
9+
NS.f = f;
10+
})(NS || (NS = {}));

crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,10 @@ impl VisitMut for Decorator202203 {
14991499
}
15001500

15011501
fn visit_mut_module_items(&mut self, n: &mut Vec<ModuleItem>) {
1502-
let old_extra_lets = self.extra_lets.take();
1502+
let extra_vars = self.extra_vars.take();
1503+
let extra_lets = self.extra_lets.take();
1504+
let pre_class_inits = self.pre_class_inits.take();
1505+
let extra_exports = self.extra_exports.take();
15031506

15041507
let mut new = Vec::with_capacity(n.len());
15051508

@@ -1559,7 +1562,10 @@ impl VisitMut for Decorator202203 {
15591562
n.visit_mut_with(&mut IdentRenamer::new(&self.rename_map));
15601563
}
15611564

1562-
self.extra_lets = old_extra_lets;
1565+
self.extra_vars = extra_vars;
1566+
self.extra_lets = extra_lets;
1567+
self.pre_class_inits = pre_class_inits;
1568+
self.extra_exports = extra_exports;
15631569
}
15641570

15651571
fn visit_mut_private_prop(&mut self, p: &mut PrivateProp) {

0 commit comments

Comments
 (0)