Skip to content

use collapse_vars causes compiled code logic changes #3562

Closed
@runyuweng

Description

@runyuweng

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

Activity

alexlamsl

alexlamsl commented on Nov 1, 2019

@alexlamsl
Collaborator

Thanks for the detailed report - will investigate.

added a commit that references this issue on Nov 1, 2019
94b7ea9
added 3 commits that reference this issue on Nov 1, 2019
24bb288
96435e6
dcbf223
alexlamsl

alexlamsl commented on Nov 2, 2019

@alexlamsl
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alexlamsl@runyuweng

      Issue actions

        use collapse_vars causes compiled code logic changes · Issue #3562 · mishoo/UglifyJS