diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs index 1495e4e5481..ebceac33015 100644 --- a/crates/swc_ecma_preset_env/src/lib.rs +++ b/crates/swc_ecma_preset_env/src/lib.rs @@ -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()); diff --git a/crates/swc_ecma_transforms_compat/src/es2015/object_super.rs b/crates/swc_ecma_transforms_compat/src/es2015/object_super.rs index 646f1b92275..e8589534bb4 100644 --- a/crates/swc_ecma_transforms_compat/src/es2015/object_super.rs +++ b/crates/swc_ecma_transforms_compat/src/es2015/object_super.rs @@ -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 { - key.visit_mut_with(self); + 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(_) => (), } } } diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs b/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs index 31fb28f1d42..0ca9be72e6d 100644 --- a/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs +++ b/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs @@ -30,7 +30,7 @@ test!( const obj = { test: 2, - + get() { return super.test; }, @@ -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" + }); + } +}; +"# +);