Transform labeled for-of inside braceless if statement (#12611)

This commit is contained in:
Nicolò Ribaudo 2021-01-12 19:19:15 +01:00 committed by GitHub
parent eda4130d5e
commit 58d2f41930
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 41 additions and 1 deletions

View File

@ -227,7 +227,9 @@ export default declare((api, options) => {
container[0] = t.labeledStatement(parent.label, container[0]);
path.parentPath.replaceWithMultiple(nodes);
path.remove();
// The parent has been replaced, prevent Babel from traversing a detatched path
path.skip();
} else {
path.replaceWithMultiple(nodes);
}

View File

@ -0,0 +1,4 @@
if (true)
actions: for (let x of y) {
continue actions
}

View File

@ -0,0 +1,15 @@
if (true) {
var _iterator = babelHelpers.createForOfIteratorHelper(y),
_step;
try {
actions: for (_iterator.s(); !(_step = _iterator.n()).done;) {
let x = _step.value;
continue actions;
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}

View File

@ -0,0 +1,4 @@
if (true)
actions: for (let x of y) {
continue actions
}

View File

@ -0,0 +1,15 @@
if (true) {
var _iterator = babelHelpers.createForOfIteratorHelper(y),
_step;
try {
actions: for (_iterator.s(); !(_step = _iterator.n()).done;) {
let x = _step.value;
continue actions;
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
}