Skip to content

Commit

Permalink
fix(es/decorator): Preserve state while traversing the module_items
Browse files Browse the repository at this point in the history
… scope (#8556)

**Related issue:**

 - Closes #8551
  • Loading branch information
magic-akari authored Jan 25, 2024
1 parent 5f9b7b4 commit f416aff
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 2 deletions.
13 changes: 13 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8551/input/.swcrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"transform": {
"decoratorVersion": "2022-03"
},
"target": "es2022"
},
"isModule": true
}
7 changes: 7 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8551/input/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class C {
[Symbol.iterator]() { }
}

namespace NS {
export function f() { }
}
10 changes: 10 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8551/output/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var _computedKey;
_computedKey = Symbol.iterator;
class C {
[_computedKey]() {}
}
var NS;
(function(NS) {
function f() {}
NS.f = f;
})(NS || (NS = {}));
10 changes: 8 additions & 2 deletions crates/swc_ecma_transforms_proposal/src/decorator_2022_03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1499,7 +1499,10 @@ impl VisitMut for Decorator202203 {
}

fn visit_mut_module_items(&mut self, n: &mut Vec<ModuleItem>) {
let old_extra_lets = self.extra_lets.take();
let extra_vars = self.extra_vars.take();
let extra_lets = self.extra_lets.take();
let pre_class_inits = self.pre_class_inits.take();
let extra_exports = self.extra_exports.take();

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

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

self.extra_lets = old_extra_lets;
self.extra_vars = extra_vars;
self.extra_lets = extra_lets;
self.pre_class_inits = pre_class_inits;
self.extra_exports = extra_exports;
}

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

0 comments on commit f416aff

Please sign in to comment.