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: support optionalCall in replace super handler #12238

Merged
merged 1 commit into from Oct 22, 2020
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
14 changes: 14 additions & 0 deletions packages/babel-helper-replace-supers/src/index.js
Expand Up @@ -166,6 +166,16 @@ const specHandlers = {
false,
);
},

optionalCall(superMember, args) {
const thisRefs = this._getThisRefs();
return optimiseCall(
this._get(superMember, thisRefs),
t.cloneNode(thisRefs.this),
args,
true,
);
},
};

const looseHandlers = {
Expand Down Expand Up @@ -223,6 +233,10 @@ const looseHandlers = {
call(superMember, args) {
return optimiseCall(this.get(superMember), t.thisExpression(), args, false);
},

optionalCall(superMember, args) {
return optimiseCall(this.get(superMember), t.thisExpression(), args, true);
},
};

type ReplaceSupersOptionsBase = {|
Expand Down
@@ -0,0 +1,6 @@
class Test extends Foo {
constructor() {
super.foo?.bar;
super.foo?.();
}
}
@@ -0,0 +1,10 @@
{
"plugins": [
["external-helpers", { "helperVersion": "7.100.0" }],
["proposal-optional-chaining", { "loose": true }],
"transform-function-name",
["transform-classes", { "loose": true }],
["transform-spread", { "loose": true }],
"transform-block-scoping"
]
}
@@ -0,0 +1,17 @@
var Test = /*#__PURE__*/function (_Foo) {
"use strict";

babelHelpers.inheritsLoose(Test, _Foo);

function Test() {
var _Foo$prototype$foo, _Foo$prototype$foo2;

var _this;

(_Foo$prototype$foo = _Foo.prototype.foo) == null ? void 0 : _Foo$prototype$foo.bar;
(_Foo$prototype$foo2 = _Foo.prototype.foo) == null ? void 0 : _Foo$prototype$foo2.call(babelHelpers.assertThisInitialized(_this));
return babelHelpers.assertThisInitialized(_this);
}

return Test;
}(Foo);
@@ -0,0 +1,6 @@
class Test extends Foo {
constructor() {
super.foo?.bar;
super.foo?.();
}
}
@@ -0,0 +1,10 @@
{
"plugins": [
["external-helpers", { "helperVersion": "7.100.0" }],
"proposal-optional-chaining",
"transform-function-name",
"transform-classes",
"transform-spread",
"transform-block-scoping"
]
}
@@ -0,0 +1,20 @@
var Test = /*#__PURE__*/function (_Foo) {
"use strict";

babelHelpers.inherits(Test, _Foo);

var _super = babelHelpers.createSuper(Test);

function Test() {
var _babelHelpers$get, _babelHelpers$get2;

var _thisSuper, _thisSuper2, _this;

babelHelpers.classCallCheck(this, Test);
(_babelHelpers$get = babelHelpers.get((_thisSuper = babelHelpers.assertThisInitialized(_this), babelHelpers.getPrototypeOf(Test.prototype)), "foo", _thisSuper)) === null || _babelHelpers$get === void 0 ? void 0 : _babelHelpers$get.bar;
(_babelHelpers$get2 = babelHelpers.get((_thisSuper2 = babelHelpers.assertThisInitialized(_this), babelHelpers.getPrototypeOf(Test.prototype)), "foo", _thisSuper2)) === null || _babelHelpers$get2 === void 0 ? void 0 : _babelHelpers$get2.call(_thisSuper2);
return babelHelpers.possibleConstructorReturn(_this);
}

return Test;
}(Foo);