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:
Mattias Buelens 2019-04-01 00:50:29 +02:00 committed by Justin Ridgewell
parent ae9b25ac69
commit 3c11a4a930
13 changed files with 78 additions and 20 deletions

View File

@ -501,7 +501,9 @@ function replaceThisContext(path, ref, superRef, file, loose) {
file,
getObjectRef() {
state.needsClassRef = true;
return path.node.static ? ref : t.thisExpression();
return path.node.static
? ref
: t.memberExpression(ref, t.identifier("prototype"));
},
});
replacer.replace();

View File

@ -1,10 +1,14 @@
class Base {
superMethod() {
return 1017;
return 'good';
}
}
class Sub extends Base {
superMethod() {
return 'bad';
}
#privateMethod() {
return super.superMethod();
}
@ -14,4 +18,4 @@ class Sub extends Base {
}
}
expect((new Sub()).publicMethod()).toEqual(1017);
expect((new Sub()).publicMethod()).toEqual('good');

View File

@ -1,10 +1,14 @@
class Base {
superMethod() {
return 1017;
return 'good';
}
}
class Sub extends Base {
superMethod() {
return 'bad';
}
#privateMethod() {
return super.superMethod();
}
@ -12,4 +16,4 @@ class Sub extends Base {
publicMethod() {
return this.#privateMethod();
}
}
}

View File

@ -1,6 +1,6 @@
class Base {
superMethod() {
return 1017;
return 'good';
}
}
@ -13,6 +13,10 @@ class Sub extends Base {
});
}
superMethod() {
return 'bad';
}
publicMethod() {
return babelHelpers.classPrivateFieldLooseBase(this, _privateMethod)[_privateMethod]();
}

View File

@ -1,10 +1,14 @@
class Base {
superMethod() {
return 1017;
return 'good';
}
}
class Sub extends Base {
superMethod() {
return 'bad';
}
#privateMethod() {
return super.superMethod();
}
@ -14,4 +18,4 @@ class Sub extends Base {
}
}
expect((new Sub()).publicMethod()).toEqual(1017);
expect((new Sub()).publicMethod()).toEqual('good');

View File

@ -1,10 +1,14 @@
class Base {
superMethod() {
return 1017;
return 'good';
}
}
class Sub extends Base {
superMethod() {
return 'bad';
}
#privateMethod() {
return super.superMethod();
}
@ -12,4 +16,4 @@ class Sub extends Base {
publicMethod() {
return this.#privateMethod();
}
}
}

View File

@ -1,6 +1,6 @@
class Base {
superMethod() {
return 1017;
return 'good';
}
}
@ -12,6 +12,10 @@ class Sub extends Base {
_privateMethod.add(this);
}
superMethod() {
return 'bad';
}
publicMethod() {
return babelHelpers.classPrivateMethodGet(this, _privateMethod, _privateMethod2).call(this);
}
@ -21,5 +25,5 @@ class Sub extends Base {
var _privateMethod = new WeakSet();
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);
};

View File

@ -1,8 +1,14 @@
class Base {
static basePublicStaticMethod() { return 1017; }
static basePublicStaticMethod() {
return 'good';
}
}
class Sub extends Base {
static basePublicStaticMethod() {
return 'bad';
}
static #subStaticPrivateMethod() {
return super.basePublicStaticMethod();
}
@ -12,4 +18,4 @@ class Sub extends Base {
}
}
expect(Sub.check()).toEqual(1017);
expect(Sub.check()).toEqual('good');

View File

@ -1,8 +1,14 @@
class Base {
static basePublicStaticMethod() { return 1017; }
static basePublicStaticMethod() {
return 'good';
}
}
class Sub extends Base {
static basePublicStaticMethod() {
return 'bad';
}
static #subStaticPrivateMethod() {
return super.basePublicStaticMethod();
}

View File

@ -1,11 +1,15 @@
class Base {
static basePublicStaticMethod() {
return 1017;
return 'good';
}
}
class Sub extends Base {
static basePublicStaticMethod() {
return 'bad';
}
static check() {
babelHelpers.classPrivateFieldLooseBase(Sub, _subStaticPrivateMethod)[_subStaticPrivateMethod]();
}

View File

@ -1,8 +1,14 @@
class Base {
static basePublicStaticMethod() { return 1017; }
static basePublicStaticMethod() {
return 'good';
}
}
class Sub extends Base {
static basePublicStaticMethod() {
return 'bad';
}
static #subStaticPrivateMethod() {
return super.basePublicStaticMethod();
}
@ -12,4 +18,4 @@ class Sub extends Base {
}
}
expect(Sub.check()).toEqual(1017);
expect(Sub.check()).toEqual('good');

View File

@ -1,8 +1,14 @@
class Base {
static basePublicStaticMethod() { return 1017; }
static basePublicStaticMethod() {
return 'good';
}
}
class Sub extends Base {
static basePublicStaticMethod() {
return 'bad';
}
static #subStaticPrivateMethod() {
return super.basePublicStaticMethod();
}

View File

@ -1,11 +1,15 @@
class Base {
static basePublicStaticMethod() {
return 1017;
return 'good';
}
}
class Sub extends Base {
static basePublicStaticMethod() {
return 'bad';
}
static check() {
babelHelpers.classStaticPrivateMethodGet(Sub, Sub, _subStaticPrivateMethod).call(Sub);
}