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

es/minifier: Labelled loops in combination with continue can lead to name clash #9871

Closed
Ocean-OS opened this issue Jan 12, 2025 · 3 comments

Comments

@Ocean-OS
Copy link

Describe the bug

Using any code that uses a loop with a label, and a continue label statement may end up with name clashes:

outer: for (let i = 0; i < 100; i++) {
    for (let k = 0; k < 100; k++) {
        if (k === 10 && i === 10) continue outer;
    }
}

is compiled to

i:for(var i=0;i<100;i++){for(var r=0;r<100;r++){if(r===10&&i===10)continue i}}

which leads to a name conflict between the label i and the variable i.

Input code

outer: for (let i = 0; i < 100; i++) {
    for (let k = 0; k < 100; k++) {
        if (k === 10 && i === 10) continue outer;
    }
}

Config

{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": {
        "toplevel": false,
        "keep_classnames": false,
        "keep_fnames": false,
        "keep_private_props": false,
        "ie8": false,
        "safari10": false
      }
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": true,
  "isModule": true
}

Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.10.7&code=H4sIAAAAAAAAA8svLUktslJIyy9S0MhJLVHIVLBVMLAGUjYKhgYghra2pkI1L5cCEMAVZUMUZcMUZSMpAoHMNAUNoBpbW6C0gpoayFAwW1MhOT%2BvJDOvNFUhH2SvNURLLS9XLQAlydKLiAAAAA%3D%3D&config=H4sIAAAAAAAAA32QQQ6CMBBF95yCzNqFLjTGO3gGM6kDKba06RQiIdzdFqiCEjdt5%2F83M%2BnvszyHigVc8j48Q2HRMbl3HRTuao%2FPoAAJjSyctB52ya04WgUqplEaJgc8upL82MXHGQdlDFPCZ03LWhbdcqEw2jpiXoMRxbpUtEDjHmMVtaS%2B4WA9iOxNKGSuUdPPuEQUf13rZIuewm3sFiTpvKEyFujkYb%2BKJoSTpXOMCbS5N4sPge8sTZGd4AOlgLxrxh0g%2BZoao5YNL76116fHAQAA

SWC Info output

No response

Expected behavior

I would've expected the code to work, and there wouldn't be any name conflicts between the label and any variables.

Actual behavior

The label, which has been renamed to i in the compilation, now clashes with the variable i.

Version

1.10.7

Additional context

No response

@Ocean-OS Ocean-OS added the C-bug label Jan 12, 2025
@Ocean-OS Ocean-OS changed the title Labelled for loops in combination with continue can lead to name clash Labelled loops in combination with continue can lead to name clash Jan 12, 2025
@kdy1 kdy1 added this to the Planned milestone Jan 13, 2025
@Austaras
Copy link
Member

It should be fine for label to share same name with variable.

@Ocean-OS
Copy link
Author

It should be fine for label to share same name with variable.

When I try to run the code, it doesn't work.

@Austaras
Copy link
Member

It should be fine for label to share same name with variable.

When I try to run the code, it doesn't work.

What's your js runtime? I've tried in Firefox and node.js. They both work fine.

@kdy1 kdy1 removed this from the Planned milestone Jan 14, 2025
@swc-bot swc-bot added the Stale label Feb 15, 2025
@kdy1 kdy1 changed the title Labelled loops in combination with continue can lead to name clash es/minifier: Labelled loops in combination with continue can lead to name clash Feb 17, 2025
@kdy1 kdy1 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

4 participants