Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix super method call in private instance method calling overridden method #9801

Merged
merged 3 commits into from Mar 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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