From 33cd9eeafdfcd16e4f5b83d5b2f94c22ab5dcbcd Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Fri, 23 Jan 2015 23:46:43 +1100 Subject: [PATCH] don't hoist regenerator variable declarations in system module formatter --- lib/6to5/transformation/modules/system.js | 8 ++++++-- .../es6-modules-system/exports-generator/expected.js | 10 +++++----- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/6to5/transformation/modules/system.js b/lib/6to5/transformation/modules/system.js index fc5b13c6d4..dca8633f01 100644 --- a/lib/6to5/transformation/modules/system.js +++ b/lib/6to5/transformation/modules/system.js @@ -111,16 +111,20 @@ var hoistVariablesVisitor = { return; } + // ignore block hoisted nodes as these can be left in + if (node._blockHoist) return; + var nodes = []; - _.each(node.declarations, function (declar) { + for (var i = 0; i < node.declarations.length; i++) { + var declar = node.declarations[i]; hoistDeclarators.push(t.variableDeclarator(declar.id)); if (declar.init) { // no initializer so we can just hoist it as-is var assign = t.expressionStatement(t.assignmentExpression("=", declar.id, declar.init)); nodes.push(assign); } - }); + } // for (var i in test) // for (var i = 0;;) diff --git a/test/fixtures/transformation/es6-modules-system/exports-generator/expected.js b/test/fixtures/transformation/es6-modules-system/exports-generator/expected.js index c29c847f06..fd897196b1 100644 --- a/test/fixtures/transformation/es6-modules-system/exports-generator/expected.js +++ b/test/fixtures/transformation/es6-modules-system/exports-generator/expected.js @@ -1,8 +1,7 @@ System.register([], function (_export) { "use strict"; - var generator; - _export("generator", generator = regeneratorRuntime.mark(function generator() { + var 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: @@ -13,11 +12,12 @@ System.register([], function (_export) { return context$1$0.stop(); } }, generator, this); - })); + }); + + _export("generator", generator); return { setters: [], - execute: function () { - } + execute: function () {} }; });