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:
committed by
Henry Zhu
parent
9c2794dc85
commit
d9dd32860a
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
}
|
||||
}
|
||||
3
packages/babel-plugin-transform-es2015-for-of/test/fixtures/regression/options.json
vendored
Normal file
3
packages/babel-plugin-transform-es2015-for-of/test/fixtures/regression/options.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"plugins": ["transform-es2015-for-of"]
|
||||
}
|
||||
Reference in New Issue
Block a user