Don't loose "this" in helper-call-delegate (#9601)

This commit is contained in:
Nicolò Ribaudo 2019-02-28 00:34:48 +01:00 committed by GitHub
parent 5c8cc0d536
commit 9aec606c69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 77 additions and 1 deletions

View File

@ -41,7 +41,7 @@ export default function(path: NodePath, scope = path.scope) {
path.traverse(visitor, state);
if (state.foundArguments) {
if (state.foundArguments || state.foundThis) {
callee = t.memberExpression(container, t.identifier("apply"));
args = [];

View File

@ -0,0 +1,6 @@
export class Test {
invite(options: { privacy: string } = {}) {
const privacy = options.privacy || "Private"
console.log(this)
}
}

View File

@ -0,0 +1,4 @@
{
"plugins": ["transform-typescript"],
"presets": ["env"]
}

View 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;

View File

@ -0,0 +1,8 @@
var a;
class Test {
invite(p = a) {
let a;
this;
}
}

View 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;
}();