fix(es/decorator): Preserve state while traversing the module_items scope (#8556)

**Related issue:**

 - Closes #8551
This commit is contained in:
magic-akari 2024-01-25 16:44:02 +08:00 committed by GitHub
parent 5f9b7b4c8b
commit f416aff7d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 38 additions and 2 deletions

View File

@ -0,0 +1,13 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"transform": {
"decoratorVersion": "2022-03"
},
"target": "es2022"
},
"isModule": true
}

View File

@ -0,0 +1,7 @@
class C {
[Symbol.iterator]() { }
}
namespace NS {
export function f() { }
}

View File

@ -0,0 +1,10 @@
var _computedKey;
_computedKey = Symbol.iterator;
class C {
[_computedKey]() {}
}
var NS;
(function(NS) {
function f() {}
NS.f = f;
})(NS || (NS = {}));

View File

@ -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());
@ -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) {