fix: support optionalCall in replace super handler (#12238)

This commit is contained in:
Huáng Jùnliàng 2020-10-22 16:09:19 -04:00 committed by GitHub
parent d51aa6d761
commit d6816f0e6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 83 additions and 0 deletions

View File

@ -166,6 +166,16 @@ const specHandlers = {
false, false,
); );
}, },
optionalCall(superMember, args) {
const thisRefs = this._getThisRefs();
return optimiseCall(
this._get(superMember, thisRefs),
t.cloneNode(thisRefs.this),
args,
true,
);
},
}; };
const looseHandlers = { const looseHandlers = {
@ -223,6 +233,10 @@ const looseHandlers = {
call(superMember, args) { call(superMember, args) {
return optimiseCall(this.get(superMember), t.thisExpression(), args, false); return optimiseCall(this.get(superMember), t.thisExpression(), args, false);
}, },
optionalCall(superMember, args) {
return optimiseCall(this.get(superMember), t.thisExpression(), args, true);
},
}; };
type ReplaceSupersOptionsBase = {| type ReplaceSupersOptionsBase = {|

View File

@ -0,0 +1,6 @@
class Test extends Foo {
constructor() {
super.foo?.bar;
super.foo?.();
}
}

View File

@ -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"
]
}

View File

@ -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);

View File

@ -0,0 +1,6 @@
class Test extends Foo {
constructor() {
super.foo?.bar;
super.foo?.();
}
}

View File

@ -0,0 +1,10 @@
{
"plugins": [
["external-helpers", { "helperVersion": "7.100.0" }],
"proposal-optional-chaining",
"transform-function-name",
"transform-classes",
"transform-spread",
"transform-block-scoping"
]
}

View File

@ -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);