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

use collapse_vars causes compiled code logic changes #3562

Closed
runyuweng opened this issue Nov 1, 2019 · 2 comments · Fixed by #3563
Closed

use collapse_vars causes compiled code logic changes #3562

runyuweng opened this issue Nov 1, 2019 · 2 comments · Fixed by #3563
Labels

Comments

@runyuweng
Copy link

runyuweng commented Nov 1, 2019

Bug report or feature request?
use collapse_vars causes compiled code logic changes

Uglify version (uglifyjs -V)
3.6.5

JavaScript input

var api = {
  getDataV1: function() {},
  getDataV2: function() {},
}
var fn;
var data;
if (typeId === 1) {
  fn = api.getDataV1;
  data = {id: 1};
} else {
  fn = api.getDataV2;
  data = {id: 2};
}
fn(data);

The uglifyjs CLI command executed or minify() options used.

  {
    mangle: true,
    compress: {}
  }

JavaScript output or error produced.

var fn,
  data,
  api = { getDataV1: function() {}, getDataV2: function() {} };
fn(
  (data =
    1 === typeId
      ? ((fn = api.getDataV1), { id: 1 })
      : ((fn = api.getDataV2), { id: 2 }))
);

JavaScript output when set collapse_vars fasle.

var fn,
  data,
  api = { getDataV1: function() {}, getDataV2: function() {} };
(data =
  1 === typeId
    ? ((fn = api.getDataV1), { id: 1 })
    : ((fn = api.getDataV2), { id: 2 })),
  fn(data);

demo url
https://github.com/runyuweng/uglify-js-compile-case

@alexlamsl alexlamsl added the bug label Nov 1, 2019
@alexlamsl
Copy link
Collaborator

Thanks for the detailed report - will investigate.

alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Nov 1, 2019
alexlamsl added a commit that referenced this issue Nov 1, 2019
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Nov 1, 2019
alexlamsl added a commit that referenced this issue Nov 1, 2019
@alexlamsl
Copy link
Collaborator

Fix released in uglify-js@3.6.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants