[2765] transform-async-to-generator doesn't work for this inside arrow
function
This commit is contained in:
parent
570b50c895
commit
f2fdc74d1b
@ -14,11 +14,22 @@ let buildWrapper = template(`
|
|||||||
})
|
})
|
||||||
`);
|
`);
|
||||||
|
|
||||||
|
let arrowBuildWrapper = template(`
|
||||||
|
(() => {
|
||||||
|
var ref = FUNCTION;
|
||||||
|
return (PARAMS) => ref.apply(this, arguments);
|
||||||
|
})
|
||||||
|
`);
|
||||||
|
|
||||||
let awaitVisitor = {
|
let awaitVisitor = {
|
||||||
Function(path) {
|
Function(path) {
|
||||||
path.skip();
|
path.skip();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
ArrowFunctionExpression(path) {
|
||||||
|
path.arrowFunctionToShadowed();
|
||||||
|
},
|
||||||
|
|
||||||
AwaitExpression({ node }) {
|
AwaitExpression({ node }) {
|
||||||
node.type = "YieldExpression";
|
node.type = "YieldExpression";
|
||||||
}
|
}
|
||||||
@ -42,9 +53,11 @@ function classOrObjectMethod(path: NodePath, callId: Object) {
|
|||||||
|
|
||||||
function plainFunction(path: NodePath, callId: Object) {
|
function plainFunction(path: NodePath, callId: Object) {
|
||||||
let node = path.node;
|
let node = path.node;
|
||||||
|
let wrapper = buildWrapper;
|
||||||
|
|
||||||
if (path.isArrowFunctionExpression()) {
|
if (path.isArrowFunctionExpression()) {
|
||||||
path.arrowFunctionToShadowed();
|
path.arrowFunctionToShadowed();
|
||||||
|
wrapper = arrowBuildWrapper;
|
||||||
}
|
}
|
||||||
|
|
||||||
node.async = false;
|
node.async = false;
|
||||||
@ -60,7 +73,7 @@ function plainFunction(path: NodePath, callId: Object) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let built = t.callExpression(callId, [node]);
|
let built = t.callExpression(callId, [node]);
|
||||||
let container = buildWrapper({
|
let container = wrapper({
|
||||||
FUNCTION: built,
|
FUNCTION: built,
|
||||||
PARAMS: node.params.map(() => path.scope.generateUidIdentifier("x"))
|
PARAMS: node.params.map(() => path.scope.generateUidIdentifier("x"))
|
||||||
}).expression;
|
}).expression;
|
||||||
|
|||||||
@ -0,0 +1,11 @@
|
|||||||
|
let TestClass = {
|
||||||
|
name: "John Doe",
|
||||||
|
|
||||||
|
testMethodFailure()
|
||||||
|
{
|
||||||
|
return new Promise(async (resolve) => {
|
||||||
|
console.log(this);
|
||||||
|
setTimeout(resolve, 1000);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -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);
|
||||||
|
})());
|
||||||
|
}
|
||||||
|
};
|
||||||
@ -0,0 +1,6 @@
|
|||||||
|
class Class {
|
||||||
|
async method() {
|
||||||
|
this;
|
||||||
|
() => this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
class Class {
|
||||||
|
method() {
|
||||||
|
var _this = this;
|
||||||
|
|
||||||
|
return babelHelpers.asyncToGenerator(function* () {
|
||||||
|
_this;
|
||||||
|
(function () {
|
||||||
|
return _this;
|
||||||
|
});
|
||||||
|
})();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user