Merge pull request #3312 from erikdesjardins/hoist-async

Fix T6882 (async functions are not hoisted)
This commit is contained in:
Henry Zhu 2016-02-05 15:32:26 -05:00
commit a757e26005
7 changed files with 20 additions and 10 deletions

View File

@ -87,6 +87,7 @@ function plainFunction(path: NodePath, callId: Object) {
t.callExpression(container, [])
)
]);
declar._blockHoist = true;
retFunction.id = asyncFnId;
path.replaceWith(declar);

View File

@ -1,5 +1,3 @@
function normalFunction() {}
async function foo() {
var wat = await bar();
}

View File

@ -1,5 +1,3 @@
function normalFunction() {}
let foo = function () {
var ref = babelHelpers.asyncToGenerator(function* () {
var wat = yield bar();

View File

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

View File

@ -0,0 +1,3 @@
foo();
async function foo() {}

View File

@ -0,0 +1,3 @@
{
"plugins": ["external-helpers", "transform-es2015-block-scoping", "transform-regenerator", "transform-async-to-generator"]
}

View File

@ -399,14 +399,21 @@ export default function () {
hoistedExportsNode = buildExportsAssignment(t.identifier(name), hoistedExportsNode).expression;
}
topNodes.unshift(t.expressionStatement(hoistedExportsNode));
const node = t.expressionStatement(hoistedExportsNode);
node._blockHoist = 3;
topNodes.unshift(node);
}
// add __esModule declaration if this file has any exports
if (hasExports && !strict) {
let buildTemplate = buildExportsModuleDeclaration;
if (this.opts.loose) buildTemplate = buildLooseExportsModuleDeclaration;
topNodes.unshift(buildTemplate());
const declar = buildTemplate();
declar._blockHoist = 3;
topNodes.unshift(declar);
}
path.unshiftContainer("body", topNodes);