Skip to content

Commit

Permalink
Fix super method call in private instance method calling overridden m…
Browse files Browse the repository at this point in the history
…ethod (#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
  • Loading branch information
MattiasBuelens authored and jridgewell committed Mar 31, 2019
1 parent ae9b25a commit 3c11a4a
Show file tree
Hide file tree
Showing 13 changed files with 78 additions and 20 deletions.
Expand Up @@ -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();
Expand Down
@@ -1,10 +1,14 @@
class Base {
superMethod() {
return 1017;
return 'good';
}
}

class Sub extends Base {
superMethod() {
return 'bad';
}

#privateMethod() {
return super.superMethod();
}
Expand All @@ -14,4 +18,4 @@ class Sub extends Base {
}
}

expect((new Sub()).publicMethod()).toEqual(1017);
expect((new Sub()).publicMethod()).toEqual('good');
@@ -1,15 +1,19 @@
class Base {
superMethod() {
return 1017;
return 'good';
}
}

class Sub extends Base {
superMethod() {
return 'bad';
}

#privateMethod() {
return super.superMethod();
}

publicMethod() {
return this.#privateMethod();
}
}
}
@@ -1,6 +1,6 @@
class Base {
superMethod() {
return 1017;
return 'good';
}

}
Expand All @@ -13,6 +13,10 @@ class Sub extends Base {
});
}

superMethod() {
return 'bad';
}

publicMethod() {
return babelHelpers.classPrivateFieldLooseBase(this, _privateMethod)[_privateMethod]();
}
Expand Down
@@ -1,10 +1,14 @@
class Base {
superMethod() {
return 1017;
return 'good';
}
}

class Sub extends Base {
superMethod() {
return 'bad';
}

#privateMethod() {
return super.superMethod();
}
Expand All @@ -14,4 +18,4 @@ class Sub extends Base {
}
}

expect((new Sub()).publicMethod()).toEqual(1017);
expect((new Sub()).publicMethod()).toEqual('good');
@@ -1,15 +1,19 @@
class Base {
superMethod() {
return 1017;
return 'good';
}
}

class Sub extends Base {
superMethod() {
return 'bad';
}

#privateMethod() {
return super.superMethod();
}

publicMethod() {
return this.#privateMethod();
}
}
}
@@ -1,6 +1,6 @@
class Base {
superMethod() {
return 1017;
return 'good';
}

}
Expand All @@ -12,6 +12,10 @@ class Sub extends Base {
_privateMethod.add(this);
}

superMethod() {
return 'bad';
}

publicMethod() {
return babelHelpers.classPrivateMethodGet(this, _privateMethod, _privateMethod2).call(this);
}
Expand All @@ -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);
};
@@ -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();
}
Expand All @@ -12,4 +18,4 @@ class Sub extends Base {
}
}

expect(Sub.check()).toEqual(1017);
expect(Sub.check()).toEqual('good');
@@ -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();
}
Expand Down
@@ -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]();
}
Expand Down
@@ -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();
}
Expand All @@ -12,4 +18,4 @@ class Sub extends Base {
}
}

expect(Sub.check()).toEqual(1017);
expect(Sub.check()).toEqual('good');
@@ -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();
}
Expand Down
@@ -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);
}
Expand Down

0 comments on commit 3c11a4a

Please sign in to comment.