Skip to content

Commit

Permalink
Fix optional method chaining in derived classes (#10694)
Browse files Browse the repository at this point in the history
  • Loading branch information
shrirambalaji authored and existentialism committed Nov 12, 2019
1 parent d9fd079 commit ecad667
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
2 changes: 2 additions & 0 deletions packages/babel-plugin-proposal-optional-chaining/src/index.js
Expand Up @@ -82,6 +82,8 @@ export default declare((api, options) => {
let context = scope.maybeGenerateMemoised(object);
if (context) {
chain.object = t.assignmentExpression("=", context, object);
} else if (t.isSuper(object)) {
context = t.thisExpression();
} else {
context = object;
}
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";
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);
}

}

0 comments on commit ecad667

Please sign in to comment.