Merge pull request #3312 from erikdesjardins/hoist-async
Fix T6882 (async functions are not hoisted)
This commit is contained in:
commit
a757e26005
@ -87,6 +87,7 @@ function plainFunction(path: NodePath, callId: Object) {
|
||||
t.callExpression(container, [])
|
||||
)
|
||||
]);
|
||||
declar._blockHoist = true;
|
||||
|
||||
retFunction.id = asyncFnId;
|
||||
path.replaceWith(declar);
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
function normalFunction() {}
|
||||
|
||||
async function foo() {
|
||||
var wat = await bar();
|
||||
}
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
function normalFunction() {}
|
||||
|
||||
let foo = function () {
|
||||
var ref = babelHelpers.asyncToGenerator(function* () {
|
||||
var wat = yield bar();
|
||||
|
||||
@ -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);
|
||||
|
||||
3
packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T6882/exec.js
vendored
Normal file
3
packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/T6882/exec.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
foo();
|
||||
|
||||
async function foo() {}
|
||||
3
packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/options.json
vendored
Normal file
3
packages/babel-plugin-transform-async-to-generator/test/fixtures/regression/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["external-helpers", "transform-es2015-block-scoping", "transform-regenerator", "transform-async-to-generator"]
|
||||
}
|
||||
@ -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);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user