diff --git a/src/babel/transformation/transformers/es6/for-of.js b/src/babel/transformation/transformers/es6/for-of.js index fd67d272a5..46b54a8be9 100644 --- a/src/babel/transformation/transformers/es6/for-of.js +++ b/src/babel/transformation/transformers/es6/for-of.js @@ -17,9 +17,6 @@ export function ForOfStatement(node, parent, scope, file) { var loop = build.loop; var block = loop.body; - // inherit comments from the original loop - t.inheritsComments(loop, node); - // ensure that it's a block so we can take all its statements t.ensureBlock(node); @@ -32,6 +29,7 @@ export function ForOfStatement(node, parent, scope, file) { block.body = block.body.concat(node.body.body); t.inherits(loop, node); + t.inherits(loop.body, node.body); if (build.replaceParent) { this.parentPath.replaceWithMultiple(build.node); diff --git a/test/core/fixtures/transformation/misc/regression-1169/actual.js b/test/core/fixtures/transformation/misc/regression-1169/actual.js new file mode 100644 index 0000000000..1846454a90 --- /dev/null +++ b/test/core/fixtures/transformation/misc/regression-1169/actual.js @@ -0,0 +1,11 @@ +function foo() { + let input = ['a', 'b', 'c'] + let output = {} + + for (let c of input) { + let name = c + output[name] = name + } + + return output +} diff --git a/test/core/fixtures/transformation/misc/regression-1169/expected.js b/test/core/fixtures/transformation/misc/regression-1169/expected.js new file mode 100644 index 0000000000..f9d3032932 --- /dev/null +++ b/test/core/fixtures/transformation/misc/regression-1169/expected.js @@ -0,0 +1,33 @@ +'use strict'; + +function foo() { + var input = ['a', 'b', 'c']; + var output = {}; + + var _iteratorNormalCompletion = true; + var _didIteratorError = false; + var _iteratorError = undefined; + + try { + for (var _iterator = input[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { + var c = _step.value; + + var _name = c; + output[_name] = _name; + } + } catch (err) { + _didIteratorError = true; + _iteratorError = err; + } finally { + try { + if (!_iteratorNormalCompletion && _iterator['return']) { + _iterator['return'](); + } + } finally { + if (_didIteratorError) { + throw _iteratorError; + } + } + } + + return output;