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

Minification generates invalid code containing break to out of scope label #4064

Closed
YarnSphere opened this issue Feb 5, 2025 · 2 comments
Closed

Comments

@YarnSphere
Copy link

Minimal reproduction:

l: {
  try {
    while (true) {}
    break l;
  } catch {}
}

esbuild 0.24.2 output:

try{e:for(;;);break e}catch{}

Link to reproduction: https://esbuild.github.io/try/#dAAwLjI0LjIALS1taW5pZnkAbDogewogIHRyeSB7CiAgICB3aGlsZSAodHJ1ZSkge30KICAgIGJyZWFrIGw7CiAgfSBjYXRjaCB7fQp9

Hit this when bundling JS code generated by the Kotlin compiler, which at some point contains the above pattern.

@YarnSphere
Copy link
Author

YarnSphere commented Feb 5, 2025

It seems like this was introduced in version 0.21.4.

Output of version 0.21.3:

e:try{for(;;);break e}catch{}

At a glance, this could be related to the changelog entry:

Fix for await transform when a label is present

This release fixes a bug where the for await transform, which wraps the loop in a try statement, previously failed to also move the loop's label into the try statement. This bug only affects code that uses both of these features in combination. Here's an example of some affected code:

@evanw
Copy link
Owner

evanw commented Feb 6, 2025

Thanks for the report. The full commit that introduced this problem was b004bbe. There's no associated issue in this repo because it resulted from another issue I found here: arogozine/LinqToTypeScript#29.

@evanw evanw closed this as completed in 11df6bf Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants