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

[bug] immediately invoked function and variable-name collision #354

Closed
freund17 opened this issue May 30, 2019 · 9 comments · Fixed by #363
Closed

[bug] immediately invoked function and variable-name collision #354

freund17 opened this issue May 30, 2019 · 9 comments · Fixed by #363
Labels

Comments

@freund17
Copy link

Bug report

My second attempt on reproducing this bug... (first attempt: #352).
I think I got it this time around...
No idea what to title this issue though...

Version (complete output of terser -V or specific git commit)
terser 4.0.0

Complete CLI command or minify() options used
terser --compress

terser input

(function(callback) {
  callback();
})(function() {
  window.used = function() {
    var A = window.foo,
      B = window.bar,
      C = window.foobar;

    return (function(A, c) {
      if (-1 === c) return A;
      return $(A, c);
    })(B, C);
  }.call(this);
});

terser output

window.used = (function() {
  window.foo;
  var B = window.bar,
    C = window.foobar;
  return (function(A, c) {
    return $(A, c);
  })(B, C);
})();

(Prettified)

Notice the missing if.

Expected result

window.used = (function() {
  window.foo;
  var B = window.bar,
    C = window.foobar;
  return -1 === C ? B : $(B, C);
})();

(Prettified)

@freund17
Copy link
Author

With the outer function dropped - works:

terser input

(function() {
  window.used = (function() {
    var A = window.foo,
      B = window.bar,
      C = window.foobar;

    return (function(A, c) {
      if (-1 === c) return A;
      return $(A, c);
    })(B, C);
  })();
})();

terser output

window.used = (function() {
  window.foo;
  var B = window.bar,
    C = window.foobar;
  return -1 === C ? B : $(B, C);
})();

(Prettified)

@freund17
Copy link
Author

With the unused variable, A, renamed to X - works:

terser input

(function(callback) {
  callback();
})(function() {
  window.used = (function() {
    var X = window.foo,
      B = window.bar,
      C = window.foobar;

    return (function(A, c) {
      if (-1 === c) return A;
      return $(A, c);
    })(B, C);
  })();
});

terser output

window.used = (function() {
  window.foo;
  var A,
    c,
    B = window.bar,
    C = window.foobar;
  return (A = B), -1 === (c = C) ? A : $(A, c);
})();

(Prettified)

@fabiosantoscode
Copy link
Collaborator

Oh my, this looks like a tough and serious one. Thanks for the repro :)

@roblan
Copy link

roblan commented Jun 3, 2019

@fabiosantoscode looks a little like #294 and #308

and there is already MR for that: #320

@L2jLiga
Copy link
Contributor

L2jLiga commented Jun 5, 2019

@roblan, #320 did not fix issue. I've just checked it, output same to master for given input

@fabiosantoscode
Copy link
Collaborator

Damn, I got my hopes up :(

@L2jLiga
Copy link
Contributor

L2jLiga commented Jun 5, 2019

Hey, dont give it up!

@roblan
Copy link

roblan commented Jun 6, 2019

Sorry :(

@L2jLiga
Copy link
Contributor

L2jLiga commented Jun 6, 2019

PR created

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.

4 participants