Don't loose "this" in helper-call-delegate (#9601)
This commit is contained in:
parent
5c8cc0d536
commit
9aec606c69
@ -41,7 +41,7 @@ export default function(path: NodePath, scope = path.scope) {
|
|||||||
|
|
||||||
path.traverse(visitor, state);
|
path.traverse(visitor, state);
|
||||||
|
|
||||||
if (state.foundArguments) {
|
if (state.foundArguments || state.foundThis) {
|
||||||
callee = t.memberExpression(container, t.identifier("apply"));
|
callee = t.memberExpression(container, t.identifier("apply"));
|
||||||
args = [];
|
args = [];
|
||||||
|
|
||||||
|
|||||||
6
packages/babel-plugin-transform-parameters/test/fixtures/parameters/iife-this-9385/input.mjs
vendored
Normal file
6
packages/babel-plugin-transform-parameters/test/fixtures/parameters/iife-this-9385/input.mjs
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
export class Test {
|
||||||
|
invite(options: { privacy: string } = {}) {
|
||||||
|
const privacy = options.privacy || "Private"
|
||||||
|
console.log(this)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,4 @@
|
|||||||
|
{
|
||||||
|
"plugins": ["transform-typescript"],
|
||||||
|
"presets": ["env"]
|
||||||
|
}
|
||||||
35
packages/babel-plugin-transform-parameters/test/fixtures/parameters/iife-this-9385/output.js
vendored
Normal file
35
packages/babel-plugin-transform-parameters/test/fixtures/parameters/iife-this-9385/output.js
vendored
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
|
Object.defineProperty(exports, "__esModule", {
|
||||||
|
value: true
|
||||||
|
});
|
||||||
|
exports.Test = void 0;
|
||||||
|
|
||||||
|
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||||
|
|
||||||
|
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||||
|
|
||||||
|
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||||
|
|
||||||
|
var Test =
|
||||||
|
/*#__PURE__*/
|
||||||
|
function () {
|
||||||
|
function Test() {
|
||||||
|
_classCallCheck(this, Test);
|
||||||
|
}
|
||||||
|
|
||||||
|
_createClass(Test, [{
|
||||||
|
key: "invite",
|
||||||
|
value: function invite() {
|
||||||
|
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||||
|
return function () {
|
||||||
|
var privacy = options.privacy || "Private";
|
||||||
|
console.log(this);
|
||||||
|
}.apply(this);
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
|
||||||
|
return Test;
|
||||||
|
}();
|
||||||
|
|
||||||
|
exports.Test = Test;
|
||||||
8
packages/babel-plugin-transform-parameters/test/fixtures/parameters/iife-this/input.js
vendored
Normal file
8
packages/babel-plugin-transform-parameters/test/fixtures/parameters/iife-this/input.js
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
var a;
|
||||||
|
|
||||||
|
class Test {
|
||||||
|
invite(p = a) {
|
||||||
|
let a;
|
||||||
|
this;
|
||||||
|
}
|
||||||
|
}
|
||||||
23
packages/babel-plugin-transform-parameters/test/fixtures/parameters/iife-this/output.js
vendored
Normal file
23
packages/babel-plugin-transform-parameters/test/fixtures/parameters/iife-this/output.js
vendored
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
var a;
|
||||||
|
|
||||||
|
var Test =
|
||||||
|
/*#__PURE__*/
|
||||||
|
function () {
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
function Test() {
|
||||||
|
babelHelpers.classCallCheck(this, Test);
|
||||||
|
}
|
||||||
|
|
||||||
|
babelHelpers.createClass(Test, [{
|
||||||
|
key: "invite",
|
||||||
|
value: function invite() {
|
||||||
|
var p = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : a;
|
||||||
|
return function () {
|
||||||
|
var a;
|
||||||
|
this;
|
||||||
|
}.apply(this);
|
||||||
|
}
|
||||||
|
}]);
|
||||||
|
return Test;
|
||||||
|
}();
|
||||||
Loading…
x
Reference in New Issue
Block a user