Skip to content

Commit

Permalink
Fix replacing for-of if inside label (babel#4736)
Browse files Browse the repository at this point in the history
This replaces the label instead of the for-of itself as we already
integrate the label in the replacement nodes.
Fixes babel#3858
  • Loading branch information
danez authored and chrisprice committed Oct 18, 2016
1 parent e4eca7c commit 0097463
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/babel-plugin-transform-es2015-for-of/src/index.js
Expand Up @@ -93,7 +93,11 @@ export default function ({ messages, template, types: t }) {
visitor: {
ForOfStatement(path, state) {
if (path.get("right").isArrayExpression()) {
return path.replaceWithMultiple(_ForOfStatementArray.call(this, path, state));
if (path.parentPath.isLabeledStatement()) {
return path.parentPath.replaceWithMultiple(_ForOfStatementArray(path));
} else {
return path.replaceWithMultiple(_ForOfStatementArray(path));
}
}

let callback = spec;
Expand Down
@@ -0,0 +1,5 @@
if ( true ) {
loop: for (let ch of []) {
}
}

@@ -0,0 +1,7 @@
if (true) {
var _arr = [];

loop: for (var _i = 0; _i < _arr.length; _i++) {
let ch = _arr[_i];
}
}
@@ -0,0 +1,4 @@
if ( true )
loop: for (let ch of []) {
}

@@ -0,0 +1,7 @@
if (true) {
var _arr = [];

loop: for (var _i = 0; _i < _arr.length; _i++) {
let ch = _arr[_i];
}
}
@@ -0,0 +1,3 @@
{
"plugins": ["transform-es2015-for-of"]
}

0 comments on commit 0097463

Please sign in to comment.