Workaround bad #__PURE__ annotation placement on IIFEs (#6999)

Based on a fix suggested by @kzc
This commit is contained in:
Diogo Franco 2017-12-08 23:51:48 +09:00 committed by Henry Zhu
parent 2958548c2c
commit 82357d79a7
5 changed files with 26 additions and 3 deletions

View File

@ -68,6 +68,8 @@ export default function(path: NodePath, file: Object, helpers: Object) {
wrapAwait: helpers.wrapAwait,
});
const isIIFE = path.parentPath.isCallExpression({ callee: path.node });
path.node.async = false;
path.node.generator = true;
@ -79,7 +81,7 @@ export default function(path: NodePath, file: Object, helpers: Object) {
path.parentPath.isObjectProperty() ||
path.parentPath.isClassProperty();
if (!isProperty) {
if (!isProperty && !isIIFE) {
annotateAsPure(
path.isDeclaration() ? path.get("declarations.0.init") : path,
);

View File

@ -0,0 +1,4 @@
(async function() { await 'ok' })();
(async () => { await 'ok' })();
async function notIIFE() { await 'ok' }
notIIFE();

View File

@ -0,0 +1,19 @@
let notIIFE =
/*#__PURE__*/
(() => {
var _ref3 = babelHelpers.asyncToGenerator(function* () {
yield 'ok';
});
return function notIIFE() {
return _ref3.apply(this, arguments);
};
})();
babelHelpers.asyncToGenerator(function* () {
yield 'ok';
})();
babelHelpers.asyncToGenerator(function* () {
yield 'ok';
})();
notIIFE();

View File

@ -1,6 +1,5 @@
var _coroutine = require("bluebird").coroutine;
/*#__PURE__*/
_coroutine(function* () {
yield foo();
})();

View File

@ -1,4 +1,3 @@
/*#__PURE__*/
babelHelpers.asyncToGenerator(function* () {
var _iteratorNormalCompletion = true;
var _didIteratorError = false;