fix(es/compat): Visit non-method properties in a nested object literal (#4094)

This commit is contained in:
Austaras 2022-03-19 22:11:54 +08:00 committed by GitHub
parent 544a3416ee
commit f5b9600b2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 3 deletions

View File

@ -193,6 +193,7 @@ where
es2015::spread(es2015::spread::Config { loose }),
true
);
let pass = add!(pass, ObjectSuper, es2015::object_super());
let pass = add!(pass, FunctionName, es2015::function_name());
let pass = add!(pass, ArrowFunctions, es2015::arrow());
let pass = add!(pass, DuplicateKeys, es2015::duplicate_keys());

View File

@ -135,8 +135,17 @@ impl VisitMut for SuperReplacer {
fn visit_mut_object_lit(&mut self, obj: &mut ObjectLit) {
for prop_or_spread in obj.props.iter_mut() {
if let PropOrSpread::Prop(prop) = prop_or_spread {
if let Prop::Method(MethodProp { key, function: _ }) = &mut **prop {
match &mut **prop {
Prop::Method(MethodProp { key, .. })
| Prop::Getter(GetterProp { key, .. })
| Prop::Setter(SetterProp { key, .. }) => key.visit_mut_with(self),
Prop::KeyValue(KeyValueProp { key, value }) => {
key.visit_mut_with(self);
if !(value.is_fn_expr() || value.is_class()) {
value.visit_mut_with(self)
}
}
Prop::Shorthand(_) | Prop::Assign(_) => (),
}
}
}

View File

@ -202,3 +202,41 @@ test!(
};
Object.setPrototypeOf(obj, Base);"#
);
test!(
syntax(),
|_| tr(),
nested_object,
r#"
function f0() {
}
f0.prototype = {
name: 'Nicholas',
age: 29,
job: 'Software Engineer',
sayName() {
v0[args](1, {
v9: v7 => super.v3(v27),
foo: a,
done: 'a'
});
}
};
"#,
r#"
var _obj;
function f0() {}
f0.prototype = _obj = {
name: "Nicholas",
age: 29,
job: "Software Engineer",
sayName: function sayName() {
v0[args](1, {
v9: (v7)=>_get(_getPrototypeOf(_obj), "v3", this).call(this, v27),
foo: a,
done: "a"
});
}
};
"#
);