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

BuildBundlerMinifier: Variables of for..of loop are minified incorrectly, resulting in erroneous syntax #591

Open
msvprogs opened this issue Sep 11, 2022 · 0 comments

Comments

@msvprogs
Copy link

Installed product versions

  • Visual Studio: 2022 Community
  • Library: 3.2.449

Description

Minification of for..of loop replaces the loop variable and iterable object variable with the same names, which is syntactically incorrect and throws Uncaught ReferenceError: can't access lexical declaration 'n' before initialization.

Steps to recreate

Consider the following code block:

function forEachTest() {
    const arr = [1, 2, 3];
    arr.push(4);

    for (const num of arr) {
        console.log(num);
    }
}

With following bundleconfig.json settings:

  {
    "outputFileName": "wwwroot/js/site.min.js",
    "inputFiles": [
      "wwwroot/js/site.bundle.js"
    ],
    "minify": {
      "enabled": true,
      "renameLocals": true
    },
    "sourceMap": false
  }

Current behavior

The code block is minified incorrectly - the names of loop variable and iterable variable are the same:

function forEachTest(){const n=[1,2,3];n.push(4);for(const n of n)console.log(n)}

Expected behavior

For example, this way:

function forEachTest(){const n=[1,2,3];n.push(4);for(const a of n)console.log(a)}
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

1 participant