fix: support optionalCall in replace super handler (#12238)
This commit is contained in:
parent
d51aa6d761
commit
d6816f0e6c
@ -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 = {
|
||||
@ -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 = {|
|
||||
|
||||
@ -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);
|
||||
Loading…
x
Reference in New Issue
Block a user