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 optional method chaining in derived classes #10694

Merged
Show file tree
Hide file tree
Changes from 3 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
4 changes: 4 additions & 0 deletions packages/babel-plugin-proposal-optional-chaining/src/index.js
Expand Up @@ -86,6 +86,10 @@ export default declare((api, options) => {
context = object;
}

if (t.isSuper(context)) {
shrirambalaji marked this conversation as resolved.
Show resolved Hide resolved
context = t.thisExpression();
}

node.arguments.unshift(t.cloneNode(context));
JLHwung marked this conversation as resolved.
Show resolved Hide resolved
node.callee = t.memberExpression(
node.callee,
Expand Down
@@ -0,0 +1,12 @@
"use strict";
class Base {
method() {
return 'Hello!';
}
}

class Derived extends Base {
method() {
return super.method?.()
}
}
@@ -0,0 +1,3 @@
{
"plugins": [["proposal-optional-chaining", { "loose": true }]]
}
@@ -0,0 +1,15 @@
"use strict";

class Base {
method() {
return 'Hello!';
}

}

class Derived extends Base {
method() {
return super.method == null ? void 0 : super.method();
}

}
@@ -0,0 +1,12 @@
"use strict";
shrirambalaji marked this conversation as resolved.
Show resolved Hide resolved
class Base {
method() {
return 'Hello!';
}
}

class Derived extends Base {
method() {
return super.method?.()
}
}
@@ -0,0 +1,17 @@
"use strict";

class Base {
method() {
return 'Hello!';
}

}

class Derived extends Base {
method() {
var _super$method;

return (_super$method = super.method) === null || _super$method === void 0 ? void 0 : _super$method.call(this);
}

}