From 4142003bbd2fe3f862f9ddfde05274ee003de2cc Mon Sep 17 00:00:00 2001 From: Erik Desjardins Date: Wed, 3 Feb 2016 11:23:32 -0500 Subject: [PATCH] Hoist initial `exports.foo = undefined` and `__esModule` declarations above hoisted async functions --- .../src/index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js index 097f17f7ce..86db8756b1 100644 --- a/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js +++ b/packages/babel-plugin-transform-es2015-modules-commonjs/src/index.js @@ -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);