Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix break/continue when switch is nested inside loop #11802

Merged
merged 2 commits into from Jul 7, 2020
Merged

Conversation

existentialism
Copy link
Member

@existentialism existentialism commented Jul 7, 2020

Q                       A
Fixed Issues? Fixes #11800, fixes #11690
Patch: Bug Fix? Y
Tests Added + Pass? Y
License MIT

@existentialism existentialism added the PR: Bug Fix 🐛 A type of pull request used for our changelog categories label Jul 7, 2020
@codesandbox-ci
Copy link

codesandbox-ci bot commented Jul 7, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d531677:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Brilliant! Preserve the break/continue completion by avoiding switch statements.

packages/babel-plugin-transform-block-scoping/src/index.js Outdated Show resolved Hide resolved
default:
if (typeof _ret === "object") return _ret.v;
}
if (_ret === "continue") continue;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not related to this PR: the string literal here is not minimizer-friendly. We should revise

function loopNodeTo(node) {
if (t.isBreakStatement(node)) {
return "break";
} else if (t.isContinueStatement(node)) {
return "continue";
}
}

later, e.g. change it to "b"/"c".

@babel-bot
Copy link
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/25579/

Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love when a bugfix is mostly deleted lines

@JLHwung JLHwung merged commit 58cfaf2 into main Jul 7, 2020
@JLHwung JLHwung deleted the issue11800 branch July 7, 2020 22:38
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 7, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue PR: Bug Fix 🐛 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: switch statements containing closures are broken Incorrect switch break logic
4 participants