[2765] transform-async-to-generator doesn't work for this inside arrow

function
This commit is contained in:
horpto 2016-01-10 21:52:04 +05:00
parent 570b50c895
commit f2fdc74d1b
5 changed files with 58 additions and 1 deletions

View File

@ -14,11 +14,22 @@ let buildWrapper = template(`
})
`);
let arrowBuildWrapper = template(`
(() => {
var ref = FUNCTION;
return (PARAMS) => ref.apply(this, arguments);
})
`);
let awaitVisitor = {
Function(path) {
path.skip();
},
ArrowFunctionExpression(path) {
path.arrowFunctionToShadowed();
},
AwaitExpression({ node }) {
node.type = "YieldExpression";
}
@ -42,9 +53,11 @@ function classOrObjectMethod(path: NodePath, callId: Object) {
function plainFunction(path: NodePath, callId: Object) {
let node = path.node;
let wrapper = buildWrapper;
if (path.isArrowFunctionExpression()) {
path.arrowFunctionToShadowed();
wrapper = arrowBuildWrapper;
}
node.async = false;
@ -60,7 +73,7 @@ function plainFunction(path: NodePath, callId: Object) {
}
let built = t.callExpression(callId, [node]);
let container = buildWrapper({
let container = wrapper({
FUNCTION: built,
PARAMS: node.params.map(() => path.scope.generateUidIdentifier("x"))
}).expression;

View File

@ -0,0 +1,11 @@
let TestClass = {
name: "John Doe",
testMethodFailure()
{
return new Promise(async (resolve) => {
console.log(this);
setTimeout(resolve, 1000);
});
}
};

View File

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

View File

@ -0,0 +1,6 @@
class Class {
async method() {
this;
() => this;
}
}

View File

@ -0,0 +1,12 @@
class Class {
method() {
var _this = this;
return babelHelpers.asyncToGenerator(function* () {
_this;
(function () {
return _this;
});
})();
}
}