Fix replacing for-of if inside label (#4736)

This replaces the label instead of the for-of itself as we already
integrate the label in the replacement nodes.
Fixes #3858
This commit is contained in:
Daniel Tschinder
2016-10-17 23:27:13 +02:00
committed by Henry Zhu
parent 9c2794dc85
commit d9dd32860a
6 changed files with 31 additions and 1 deletions

View File

@@ -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;

View File

@@ -0,0 +1,5 @@
if ( true ) {
loop: for (let ch of []) {
}
}

View File

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

View File

@@ -0,0 +1,4 @@
if ( true )
loop: for (let ch of []) {
}

View File

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

View File

@@ -0,0 +1,3 @@
{
"plugins": ["transform-es2015-for-of"]
}