mirror of
https://github.com/swc-project/swc.git
synced 2024-11-28 11:13:43 +03:00
fix(es/compat): Handle super
in a private method (#5613)
This commit is contained in:
parent
8d44b71b6c
commit
35d3558535
14
crates/swc/tests/fixture/issues-5xxx/5596/input/.swcrc
Normal file
14
crates/swc/tests/fixture/issues-5xxx/5596/input/.swcrc
Normal file
@ -0,0 +1,14 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "ecmascript"
|
||||
},
|
||||
"target": "es2021",
|
||||
"minify": {
|
||||
"compress": false,
|
||||
"mangle": false
|
||||
},
|
||||
"loose": false
|
||||
},
|
||||
"minify": false
|
||||
}
|
21
crates/swc/tests/fixture/issues-5xxx/5596/input/index.js
Normal file
21
crates/swc/tests/fixture/issues-5xxx/5596/input/index.js
Normal file
@ -0,0 +1,21 @@
|
||||
class Base {
|
||||
superMethod() {
|
||||
return 'good';
|
||||
}
|
||||
}
|
||||
|
||||
class Sub extends Base {
|
||||
superMethod() {
|
||||
return 'bad';
|
||||
}
|
||||
|
||||
#privateMethod() {
|
||||
return super.superMethod();
|
||||
}
|
||||
|
||||
publicMethod() {
|
||||
return this.#privateMethod();
|
||||
}
|
||||
}
|
||||
|
||||
(new Sub()).publicMethod().toEqual('good');
|
26
crates/swc/tests/fixture/issues-5xxx/5596/output/index.js
Normal file
26
crates/swc/tests/fixture/issues-5xxx/5596/output/index.js
Normal file
@ -0,0 +1,26 @@
|
||||
import _class_private_method_get from "@swc/helpers/src/_class_private_method_get.mjs";
|
||||
import _class_private_method_init from "@swc/helpers/src/_class_private_method_init.mjs";
|
||||
import _get from "@swc/helpers/src/_get.mjs";
|
||||
import _get_prototype_of from "@swc/helpers/src/_get_prototype_of.mjs";
|
||||
class Base {
|
||||
superMethod() {
|
||||
return 'good';
|
||||
}
|
||||
}
|
||||
var _privateMethod = new WeakSet();
|
||||
class Sub extends Base {
|
||||
superMethod() {
|
||||
return 'bad';
|
||||
}
|
||||
publicMethod() {
|
||||
return _class_private_method_get(this, _privateMethod, privateMethod).call(this);
|
||||
}
|
||||
constructor(...args){
|
||||
super(...args);
|
||||
_class_private_method_init(this, _privateMethod);
|
||||
}
|
||||
}
|
||||
function privateMethod() {
|
||||
return _get(_get_prototype_of(Sub.prototype), "superMethod", this).call(this);
|
||||
}
|
||||
new Sub().publicMethod().toEqual('good');
|
@ -742,7 +742,7 @@ impl<C: Comments> ClassProperties<C> {
|
||||
constructor = Some(c);
|
||||
}
|
||||
|
||||
ClassMember::PrivateMethod(method) => {
|
||||
ClassMember::PrivateMethod(mut method) => {
|
||||
let is_static = method.is_static;
|
||||
let prop_span = method.span;
|
||||
|
||||
@ -875,6 +875,20 @@ impl<C: Comments> ClassProperties<C> {
|
||||
})
|
||||
};
|
||||
|
||||
method.function.visit_mut_with(&mut SuperFieldAccessFolder {
|
||||
class_name: &class_ident,
|
||||
vars: &mut vars,
|
||||
constructor_this_mark: None,
|
||||
is_static,
|
||||
folding_constructor: false,
|
||||
in_injected_define_property_call: false,
|
||||
in_nested_scope: false,
|
||||
this_alias_mark: None,
|
||||
constant_super: self.c.constant_super,
|
||||
super_class: &super_ident,
|
||||
in_pat: false,
|
||||
});
|
||||
|
||||
private_method_fn_decls.push(Stmt::Decl(Decl::Fn(FnDecl {
|
||||
ident: fn_name,
|
||||
function: method.function,
|
||||
|
Loading…
Reference in New Issue
Block a user