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

simplify pulls VariableDeclaration into loop, then mangle fails to mangle same variable after loop #999

Open
jleven opened this issue Nov 29, 2020 · 1 comment

Comments

@jleven
Copy link

jleven commented Nov 29, 2020

Describe the bug

Minification produces output where a variable is only minified sometimes within a function. Thanks for your help!

To Reproduce

Minimal code to reproduce the bug

function foo() {
  let varName = [];
  while (false) {}
  varName;
}

Actual Output

"use strict";
function foo(){
  for(var a=[];false;);
  varName
}

Expected Output

I'm not sure if it's expected to pull the varName variable into the loop in this circumstance, so the expected output is one of the following:

"use strict";
function foo(){
  for(var a=[];false;);
  a
}

or

"use strict";
function foo(){
  var a=[];
  for(;false;);
  a
}

Configuration

Turning off all minify plugins except for mangle and simplify (bug requires both).

npx babel ./src --out-dir ./lib

babel-minify version: 0.5.1

babel core : 7.11.6

babel-minify-config:

  {
      "mangle": true,
      "simplify": true,
      "evaluate": false,
      "replace": false,
      "booleans": false,
      "builtIns": false,
      "consecutiveAdds": false,
      "deadcode": false,
      "flipComparisons": false,
      "guards": false,
      "infinity": false,
      "memberExpressions": false,
      "mergeVars": false,
      "numericLiterals": false,
      "propertyLiterals": false,
      "regexpConstructors": false,
      "removeConsole": false,
      "removeDebugger": false,
      "removeUndefined": false,
      "simplifyComparisons": false,
      "typeConstructors": false,
      "undefinedToVoid": false
  }

babelrc:

module.exports = {
  presets: [
    '@babel/preset-env',
    ['minify', {
      "mangle": true,
      "simplify": true,
      "evaluate": false,
      "replace": false,
      "booleans": false,
      "builtIns": false,
      "consecutiveAdds": false,
      "deadcode": false,
      "flipComparisons": false,
      "guards": false,
      "infinity": false,
      "memberExpressions": false,
      "mergeVars": false,
      "numericLiterals": false,
      "propertyLiterals": false,
      "regexpConstructors": false,
      "removeConsole": false,
      "removeDebugger": false,
      "removeUndefined": false,
      "simplifyComparisons": false,
      "typeConstructors": false,
      "undefinedToVoid": false
    }]
  ],
  plugins: [
  ],
}

Possible solution

Not sure. But it appears the logic in this region may need to be improved, when it decides if a variable is referenced outside the loop.

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