fix(es/compat): Fix is_setter in parameters pass (#7348)

**Description:**

x-ref: https://vercel.slack.com/archives/C02HY34AKME/p1682667306929829
This commit is contained in:
Donny/강동윤 2023-05-02 11:11:42 +09:00 committed by GitHub
parent 11c1f2c7b3
commit e0de83e862
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 38 additions and 0 deletions

View File

@ -437,6 +437,33 @@ impl VisitMut for Params {
self.in_prop = old_in_prop; self.in_prop = old_in_prop;
} }
fn visit_mut_class_method(&mut self, m: &mut ClassMethod) {
if let MethodKind::Setter = m.kind {
let f = &mut m.function;
if f.body.is_none() {
return;
}
let old_in_subclass = self.in_subclass;
let old_in_prop = self.in_prop;
self.in_subclass = false;
self.in_prop = false;
f.visit_mut_children_with(self);
let mut body = f.body.take().unwrap();
self.visit_mut_fn_like(&mut f.params, &mut body, true);
f.body = Some(body);
self.in_subclass = old_in_subclass;
self.in_prop = old_in_prop;
} else {
m.visit_mut_children_with(self);
}
}
// same for private prop // same for private prop
fn visit_mut_private_prop(&mut self, prop: &mut PrivateProp) { fn visit_mut_private_prop(&mut self, prop: &mut PrivateProp) {
let old_in_prop = self.in_prop; let old_in_prop = self.in_prop;

View File

@ -0,0 +1,5 @@
class Test {
set property(value = null) {
// oh no, will generate code that is a SyntaxError
}
}

View File

@ -0,0 +1,6 @@
class Test {
set property(value) {
if (value === void 0) value = null;
// oh no, will generate code that is a SyntaxError
}
}