diff --git a/src/babel/transformation/modules/system.js b/src/babel/transformation/modules/system.js index 20a39f97ca..835a344a24 100644 --- a/src/babel/transformation/modules/system.js +++ b/src/babel/transformation/modules/system.js @@ -6,6 +6,10 @@ import each from "lodash/collection/each"; import map from "lodash/collection/map"; import * as t from "../../types"; +var canHoist = function (node, file) { + return node._blockHoist && !file.transformers.runtime.canTransform(); +} + var hoistVariablesVisitor = { enter(node, parent, scope, hoistDeclarators) { if (t.isFunction(node)) { @@ -20,7 +24,7 @@ var hoistVariablesVisitor = { } // ignore block hoisted nodes as these can be left in - if (node._blockHoist) return; + if (canHoist(node, scope.file)) return; var nodes = []; @@ -55,7 +59,7 @@ var hoistFunctionsVisitor = { enter(node, parent, scope, handlerBody) { if (t.isFunction(node)) this.skip(); - if (t.isFunctionDeclaration(node) || node._blockHoist) { + if (t.isFunctionDeclaration(node) || canHoist(node, scope.file)) { handlerBody.push(node); this.remove(); } diff --git a/test/core/fixtures/transformation/es6.modules-system/exports-generator/actual.js b/test/core/fixtures/transformation/es6.modules-system/exports-generator/actual.js deleted file mode 100644 index 18cc16452e..0000000000 --- a/test/core/fixtures/transformation/es6.modules-system/exports-generator/actual.js +++ /dev/null @@ -1,3 +0,0 @@ -export function* generator() { - yield 1; -} \ No newline at end of file diff --git a/test/core/fixtures/transformation/es6.modules-system/exports-generator/expected.js b/test/core/fixtures/transformation/es6.modules-system/exports-generator/expected.js deleted file mode 100644 index 60d886680a..0000000000 --- a/test/core/fixtures/transformation/es6.modules-system/exports-generator/expected.js +++ /dev/null @@ -1,26 +0,0 @@ -System.register([], function (_export) { - var generator; - - _export("generator", generator); - - return { - setters: [], - execute: function () { - "use strict"; - - generator = regeneratorRuntime.mark(function generator() { - return regeneratorRuntime.wrap(function generator$(context$1$0) { - while (1) switch (context$1$0.prev = context$1$0.next) { - case 0: - context$1$0.next = 2; - return 1; - - case 2: - case "end": - return context$1$0.stop(); - } - }, generator, this); - }); - } - }; -}); \ No newline at end of file diff --git a/test/core/fixtures/transformation/runtime/modules-system/actual.js b/test/core/fixtures/transformation/runtime/modules-system/actual.js index d4f5786183..34353bc650 100644 --- a/test/core/fixtures/transformation/runtime/modules-system/actual.js +++ b/test/core/fixtures/transformation/runtime/modules-system/actual.js @@ -1 +1,5 @@ foo(...bar); + +export function* generator() { + yield 1; +} diff --git a/test/core/fixtures/transformation/runtime/modules-system/expected.js b/test/core/fixtures/transformation/runtime/modules-system/expected.js index 3ccf69068d..adcb2aaba3 100644 --- a/test/core/fixtures/transformation/runtime/modules-system/expected.js +++ b/test/core/fixtures/transformation/runtime/modules-system/expected.js @@ -1,14 +1,32 @@ -System.register(["babel-runtime/helpers/to-consumable-array"], function (_export) { - var _toConsumableArray; +System.register(["babel-runtime/helpers/to-consumable-array", "babel-runtime/regenerator"], function (_export) { + var _toConsumableArray, _regeneratorRuntime, generator; return { setters: [function (_babelRuntimeHelpersToConsumableArray) { _toConsumableArray = _babelRuntimeHelpersToConsumableArray["default"]; + }, function (_babelRuntimeRegenerator) { + _regeneratorRuntime = _babelRuntimeRegenerator["default"]; }], execute: function () { "use strict"; + generator = _regeneratorRuntime.mark(function generator() { + return _regeneratorRuntime.wrap(function generator$(context$1$0) { + while (1) switch (context$1$0.prev = context$1$0.next) { + case 0: + context$1$0.next = 2; + return 1; + + case 2: + case "end": + return context$1$0.stop(); + } + }, generator, this); + }); + + _export("generator", generator); + foo.apply(undefined, _toConsumableArray(bar)); } }; -}); \ No newline at end of file +});