Revert special arrow wrapper and avoid shadowing arguments.

This commit is contained in:
Logan Smyth
2016-03-05 22:28:49 -08:00
parent 51ddeade8a
commit 42d3844f24
13 changed files with 50 additions and 73 deletions

View File

@@ -6,7 +6,7 @@ import template from "babel-template";
import * as t from "babel-types";
let buildWrapper = template(`
(function () {
(() => {
var ref = FUNCTION;
return function NAME(PARAMS) {
return ref.apply(this, arguments);
@@ -15,7 +15,7 @@ let buildWrapper = template(`
`);
let namedBuildWrapper = template(`
(function () {
(() => {
var ref = FUNCTION;
function NAME(PARAMS) {
return ref.apply(this, arguments);
@@ -24,15 +24,6 @@ let namedBuildWrapper = template(`
})
`);
let arrowBuildWrapper = template(`
(() => {
var ref = FUNCTION, _this = this;
return function(PARAMS) {
return ref.apply(_this, arguments);
};
})
`);
let awaitVisitor = {
ArrowFunctionExpression(path) {
if (!path.node.async) {
@@ -69,19 +60,12 @@ function plainFunction(path: NodePath, callId: Object) {
if (path.isArrowFunctionExpression()) {
path.arrowFunctionToShadowed();
wrapper = arrowBuildWrapper;
} else if (!isDeclaration && asyncFnId) {
wrapper = namedBuildWrapper;
}
node.async = false;
node.generator = true;
// Either the wrapped generator is invoked with `.apply(this, arguments)` or it has no params,
// so it should capture `arguments`
if (node.shadow) {
// node.shadow may be `true` or an object
node.shadow = Object.assign({}, node.shadow, { arguments: false });
}
node.id = null;

View File

@@ -1,19 +1,17 @@
let TestClass = {
name: "John Doe",
testMethodFailure() {
return new Promise((() => {
var _this2 = this;
var ref = babelHelpers.asyncToGenerator(function* (resolve) {
console.log(_this2);
setTimeout(resolve, 1000);
}),
_this = this;
return function (_x) {
return ref.apply(_this, arguments);
};
})());
}
};
let TestClass = {
name: "John Doe",
testMethodFailure() {
var _this = this;
return new Promise((() => {
var ref = babelHelpers.asyncToGenerator(function* (resolve) {
console.log(_this);
setTimeout(resolve, 1000);
});
return function (_x) {
return ref.apply(this, arguments);
};
})());
}
};

View File

@@ -1,27 +1,24 @@
let s = function () {
let s = (() => {
var ref = babelHelpers.asyncToGenerator(function* (x) {
var _this2 = this;
var _this = this;
let t = (() => {
var ref = babelHelpers.asyncToGenerator(function* (y, a) {
let r = (() => {
var ref = babelHelpers.asyncToGenerator(function* (z, b) {
yield z;
return _this2.x;
}),
_this = _this2;
return _this.x;
});
return function r(_x4, _x5) {
return ref.apply(_this, arguments);
return ref.apply(this, arguments);
};
})();
yield r();
return _this2.g(r);
}),
_this = this;
return _this.g(r);
});
return function t(_x2, _x3) {
return ref.apply(_this, arguments);
return ref.apply(this, arguments);
};
})();
@@ -31,4 +28,4 @@ let s = function () {
return function s(_x) {
return ref.apply(this, arguments);
};
}();
})();

View File

@@ -1,8 +1,8 @@
var foo = function () {
var foo = (() => {
var ref = babelHelpers.asyncToGenerator(function* () {
var wat = yield bar();
});
return function foo() {
return ref.apply(this, arguments);
};
}();
})();

View File

@@ -1,4 +1,4 @@
var foo = function () {
var foo = (() => {
var ref = babelHelpers.asyncToGenerator(function* () {
console.log(bar);
});
@@ -8,4 +8,4 @@ var foo = function () {
}
return bar;
}();
})();

View File

@@ -1,6 +1,6 @@
let foo = function () {
let foo = (() => {
var ref = babelHelpers.asyncToGenerator(function* (bar) {});
return function foo(_x) {
return ref.apply(this, arguments);
};
}();
})();

View File

@@ -1,8 +1,8 @@
let foo = function () {
let foo = (() => {
var ref = babelHelpers.asyncToGenerator(function* () {
var wat = yield bar();
});
return function foo() {
return ref.apply(this, arguments);
};
}();
})();

View File

@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
});
exports.foo = undefined;
let foo = exports.foo = function () {
let foo = exports.foo = (() => {
var ref = babelHelpers.asyncToGenerator(function* () {});
return function foo() {
return ref.apply(this, arguments);
};
}();
})();
var _bar = require('bar');

View File

@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
let foo = exports.foo = function () {
let foo = exports.foo = (() => {
var ref = babelHelpers.asyncToGenerator(function* () {});
return function foo() {
return ref.apply(this, arguments);
};
}();
})();

View File

@@ -20,10 +20,9 @@ class Test {
setTimeout((() => {
var ref = babelHelpers.asyncToGenerator(function* (arg) {
console.log(_this2);
}),
_this = _this2;
});
return function (_x) {
return ref.apply(_this, arguments);
return ref.apply(this, arguments);
};
})());
})();
@@ -50,10 +49,9 @@ class Test {
setTimeout((() => {
var ref = babelHelpers.asyncToGenerator(function* (arg) {
console.log(_this4);
}),
_this = _this4;
});
return function (_x2) {
return ref.apply(_this, arguments);
return ref.apply(this, arguments);
};
})());
})();

View File

@@ -1,5 +1,5 @@
import { coroutine as _coroutine } from "bluebird";
var foo = function () {
var foo = (() => {
var ref = _coroutine(function* () {
var wat = yield bar();
});
@@ -7,4 +7,4 @@ var foo = function () {
return function foo() {
return ref.apply(this, arguments);
};
}();
})();

View File

@@ -1,5 +1,5 @@
import { coroutine as _coroutine } from "bluebird";
var foo = function () {
var foo = (() => {
var ref = _coroutine(function* () {
console.log(bar);
});
@@ -9,4 +9,4 @@ var foo = function () {
}
return bar;
}();
})();

View File

@@ -1,6 +1,6 @@
import { coroutine as _coroutine } from "bluebird";
let foo = function () {
let foo = (() => {
var ref = _coroutine(function* () {
var wat = yield bar();
});
@@ -8,4 +8,4 @@ let foo = function () {
return function foo() {
return ref.apply(this, arguments);
};
}();
})();