Skip to content

Commit

Permalink
Transform labeled for-of inside braceless if statement (#12611)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jan 12, 2021
1 parent eda4130 commit 58d2f41
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/babel-plugin-transform-for-of/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if (true)
actions: for (let x of y) {
continue actions
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
if (true)
actions: for (let x of y) {
continue actions
}
Original file line number Diff line number Diff line change
@@ -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();
}
}

0 comments on commit 58d2f41

Please sign in to comment.