mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 14:16:12 +03:00
fix(es/compat): Visit non-method properties in a nested object literal (#4094)
This commit is contained in:
parent
544a3416ee
commit
f5b9600b2b
@ -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());
|
||||
|
@ -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(_) => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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"
|
||||
});
|
||||
}
|
||||
};
|
||||
"#
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user