Fix super method call in private instance method calling overridden method (#9801)
* Fix super method call in private instance method calling overridden method * Change return value in test fixtures * Update tests to verify that overridden method is not called
This commit is contained in:
parent
ae9b25ac69
commit
3c11a4a930
@ -501,7 +501,9 @@ function replaceThisContext(path, ref, superRef, file, loose) {
|
|||||||
file,
|
file,
|
||||||
getObjectRef() {
|
getObjectRef() {
|
||||||
state.needsClassRef = true;
|
state.needsClassRef = true;
|
||||||
return path.node.static ? ref : t.thisExpression();
|
return path.node.static
|
||||||
|
? ref
|
||||||
|
: t.memberExpression(ref, t.identifier("prototype"));
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
replacer.replace();
|
replacer.replace();
|
||||||
|
|||||||
@ -1,10 +1,14 @@
|
|||||||
class Base {
|
class Base {
|
||||||
superMethod() {
|
superMethod() {
|
||||||
return 1017;
|
return 'good';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sub extends Base {
|
class Sub extends Base {
|
||||||
|
superMethod() {
|
||||||
|
return 'bad';
|
||||||
|
}
|
||||||
|
|
||||||
#privateMethod() {
|
#privateMethod() {
|
||||||
return super.superMethod();
|
return super.superMethod();
|
||||||
}
|
}
|
||||||
@ -14,4 +18,4 @@ class Sub extends Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expect((new Sub()).publicMethod()).toEqual(1017);
|
expect((new Sub()).publicMethod()).toEqual('good');
|
||||||
|
|||||||
@ -1,10 +1,14 @@
|
|||||||
class Base {
|
class Base {
|
||||||
superMethod() {
|
superMethod() {
|
||||||
return 1017;
|
return 'good';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sub extends Base {
|
class Sub extends Base {
|
||||||
|
superMethod() {
|
||||||
|
return 'bad';
|
||||||
|
}
|
||||||
|
|
||||||
#privateMethod() {
|
#privateMethod() {
|
||||||
return super.superMethod();
|
return super.superMethod();
|
||||||
}
|
}
|
||||||
@ -12,4 +16,4 @@ class Sub extends Base {
|
|||||||
publicMethod() {
|
publicMethod() {
|
||||||
return this.#privateMethod();
|
return this.#privateMethod();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
class Base {
|
class Base {
|
||||||
superMethod() {
|
superMethod() {
|
||||||
return 1017;
|
return 'good';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -13,6 +13,10 @@ class Sub extends Base {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
superMethod() {
|
||||||
|
return 'bad';
|
||||||
|
}
|
||||||
|
|
||||||
publicMethod() {
|
publicMethod() {
|
||||||
return babelHelpers.classPrivateFieldLooseBase(this, _privateMethod)[_privateMethod]();
|
return babelHelpers.classPrivateFieldLooseBase(this, _privateMethod)[_privateMethod]();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,10 +1,14 @@
|
|||||||
class Base {
|
class Base {
|
||||||
superMethod() {
|
superMethod() {
|
||||||
return 1017;
|
return 'good';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sub extends Base {
|
class Sub extends Base {
|
||||||
|
superMethod() {
|
||||||
|
return 'bad';
|
||||||
|
}
|
||||||
|
|
||||||
#privateMethod() {
|
#privateMethod() {
|
||||||
return super.superMethod();
|
return super.superMethod();
|
||||||
}
|
}
|
||||||
@ -14,4 +18,4 @@ class Sub extends Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expect((new Sub()).publicMethod()).toEqual(1017);
|
expect((new Sub()).publicMethod()).toEqual('good');
|
||||||
|
|||||||
@ -1,10 +1,14 @@
|
|||||||
class Base {
|
class Base {
|
||||||
superMethod() {
|
superMethod() {
|
||||||
return 1017;
|
return 'good';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sub extends Base {
|
class Sub extends Base {
|
||||||
|
superMethod() {
|
||||||
|
return 'bad';
|
||||||
|
}
|
||||||
|
|
||||||
#privateMethod() {
|
#privateMethod() {
|
||||||
return super.superMethod();
|
return super.superMethod();
|
||||||
}
|
}
|
||||||
@ -12,4 +16,4 @@ class Sub extends Base {
|
|||||||
publicMethod() {
|
publicMethod() {
|
||||||
return this.#privateMethod();
|
return this.#privateMethod();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
class Base {
|
class Base {
|
||||||
superMethod() {
|
superMethod() {
|
||||||
return 1017;
|
return 'good';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -12,6 +12,10 @@ class Sub extends Base {
|
|||||||
_privateMethod.add(this);
|
_privateMethod.add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
superMethod() {
|
||||||
|
return 'bad';
|
||||||
|
}
|
||||||
|
|
||||||
publicMethod() {
|
publicMethod() {
|
||||||
return babelHelpers.classPrivateMethodGet(this, _privateMethod, _privateMethod2).call(this);
|
return babelHelpers.classPrivateMethodGet(this, _privateMethod, _privateMethod2).call(this);
|
||||||
}
|
}
|
||||||
@ -21,5 +25,5 @@ class Sub extends Base {
|
|||||||
var _privateMethod = new WeakSet();
|
var _privateMethod = new WeakSet();
|
||||||
|
|
||||||
var _privateMethod2 = function _privateMethod2() {
|
var _privateMethod2 = function _privateMethod2() {
|
||||||
return babelHelpers.get(babelHelpers.getPrototypeOf(this), "superMethod", this).call(this);
|
return babelHelpers.get(babelHelpers.getPrototypeOf(Sub.prototype), "superMethod", this).call(this);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,8 +1,14 @@
|
|||||||
class Base {
|
class Base {
|
||||||
static basePublicStaticMethod() { return 1017; }
|
static basePublicStaticMethod() {
|
||||||
|
return 'good';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sub extends Base {
|
class Sub extends Base {
|
||||||
|
static basePublicStaticMethod() {
|
||||||
|
return 'bad';
|
||||||
|
}
|
||||||
|
|
||||||
static #subStaticPrivateMethod() {
|
static #subStaticPrivateMethod() {
|
||||||
return super.basePublicStaticMethod();
|
return super.basePublicStaticMethod();
|
||||||
}
|
}
|
||||||
@ -12,4 +18,4 @@ class Sub extends Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(Sub.check()).toEqual(1017);
|
expect(Sub.check()).toEqual('good');
|
||||||
|
|||||||
@ -1,8 +1,14 @@
|
|||||||
class Base {
|
class Base {
|
||||||
static basePublicStaticMethod() { return 1017; }
|
static basePublicStaticMethod() {
|
||||||
|
return 'good';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sub extends Base {
|
class Sub extends Base {
|
||||||
|
static basePublicStaticMethod() {
|
||||||
|
return 'bad';
|
||||||
|
}
|
||||||
|
|
||||||
static #subStaticPrivateMethod() {
|
static #subStaticPrivateMethod() {
|
||||||
return super.basePublicStaticMethod();
|
return super.basePublicStaticMethod();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
class Base {
|
class Base {
|
||||||
static basePublicStaticMethod() {
|
static basePublicStaticMethod() {
|
||||||
return 1017;
|
return 'good';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sub extends Base {
|
class Sub extends Base {
|
||||||
|
static basePublicStaticMethod() {
|
||||||
|
return 'bad';
|
||||||
|
}
|
||||||
|
|
||||||
static check() {
|
static check() {
|
||||||
babelHelpers.classPrivateFieldLooseBase(Sub, _subStaticPrivateMethod)[_subStaticPrivateMethod]();
|
babelHelpers.classPrivateFieldLooseBase(Sub, _subStaticPrivateMethod)[_subStaticPrivateMethod]();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,14 @@
|
|||||||
class Base {
|
class Base {
|
||||||
static basePublicStaticMethod() { return 1017; }
|
static basePublicStaticMethod() {
|
||||||
|
return 'good';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sub extends Base {
|
class Sub extends Base {
|
||||||
|
static basePublicStaticMethod() {
|
||||||
|
return 'bad';
|
||||||
|
}
|
||||||
|
|
||||||
static #subStaticPrivateMethod() {
|
static #subStaticPrivateMethod() {
|
||||||
return super.basePublicStaticMethod();
|
return super.basePublicStaticMethod();
|
||||||
}
|
}
|
||||||
@ -12,4 +18,4 @@ class Sub extends Base {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
expect(Sub.check()).toEqual(1017);
|
expect(Sub.check()).toEqual('good');
|
||||||
|
|||||||
@ -1,8 +1,14 @@
|
|||||||
class Base {
|
class Base {
|
||||||
static basePublicStaticMethod() { return 1017; }
|
static basePublicStaticMethod() {
|
||||||
|
return 'good';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sub extends Base {
|
class Sub extends Base {
|
||||||
|
static basePublicStaticMethod() {
|
||||||
|
return 'bad';
|
||||||
|
}
|
||||||
|
|
||||||
static #subStaticPrivateMethod() {
|
static #subStaticPrivateMethod() {
|
||||||
return super.basePublicStaticMethod();
|
return super.basePublicStaticMethod();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
class Base {
|
class Base {
|
||||||
static basePublicStaticMethod() {
|
static basePublicStaticMethod() {
|
||||||
return 1017;
|
return 'good';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class Sub extends Base {
|
class Sub extends Base {
|
||||||
|
static basePublicStaticMethod() {
|
||||||
|
return 'bad';
|
||||||
|
}
|
||||||
|
|
||||||
static check() {
|
static check() {
|
||||||
babelHelpers.classStaticPrivateMethodGet(Sub, Sub, _subStaticPrivateMethod).call(Sub);
|
babelHelpers.classStaticPrivateMethodGet(Sub, Sub, _subStaticPrivateMethod).call(Sub);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user