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

Unnecesary variable definitions not being removed #27

Closed
fedemp opened this issue Oct 28, 2012 · 2 comments · Fixed by #1829 or #1862
Closed

Unnecesary variable definitions not being removed #27

fedemp opened this issue Oct 28, 2012 · 2 comments · Fixed by #1829 or #1862

Comments

@fedemp
Copy link

fedemp commented Oct 28, 2012

I got this output from CoffeeScript due to the way it "compiles" anonymous functions.

(function(jQuery) {
  var $;
  $ = jQuery;
  $('body').addClass('foo');
})(jQuery);

$ is here just an alias for the received argument.

When minified (using this new version and the old one) I got:

(function(o){var a;a=o,a("body").addClass("foo")})(jQuery)

Should not uglify ignore the new defined variable and just use the same name from the argument? As in..

 (function(o){o("body").addClass("foo")})(jQuery)
@kzc
Copy link
Contributor

kzc commented Apr 10, 2017

If this:

  var $;
  $ = jQuery;

were to be transformed by reduce_vars or cascade into:

  var $ = jQuery;

then collapse_vars would produce:

!function(jQuery) {
    jQuery("body").addClass("foo");
}(jQuery);

@alexlamsl
Copy link
Collaborator

My current plan of attack:

alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Apr 17, 2017
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Apr 18, 2017
alexlamsl added a commit that referenced this issue Apr 18, 2017
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Apr 23, 2017
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue May 1, 2017
- collapse `a++` & `a=x;` similar to `var a=x;`

fixes mishoo#27
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue May 1, 2017
- collapse `a++` & `a=x;` similar to `var a=x;`

fixes mishoo#27
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue May 2, 2017
- extend expression types
  - `a++`
  - `a=x;`
- extend scan range
  - `for(init;;);`
  - `switch(expr){case expr:}`
  - `a = x; a = a || y;`
- terminate upon `debugger;`

fixes mishoo#27
fixes mishoo#1858
alexlamsl added a commit that referenced this issue May 6, 2017
- extend expression types
  - `a++`
  - `a=x;`
- extend scan range
  - `for(init;;);`
  - `switch(expr){case expr:}`
  - `a = x; a = a || y;`
- terminate upon `debugger;`

closes #1821
fixes #27
fixes #315
fixes #1858
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants