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

Variable created in catch(err) overrides external variable #1337

Closed
fregante opened this issue Oct 21, 2016 · 7 comments
Closed

Variable created in catch(err) overrides external variable #1337

fregante opened this issue Oct 21, 2016 · 7 comments

Comments

@fregante
Copy link

fregante commented Oct 21, 2016

(function() {
    var e = 'I’m gooooooooone!';
    return (function () {
        console.log(e)
        try {} catch (e) {}
    })()
}());

Results in:

I’m gooooooooone!

But it's minified to:

!function(){return function(){console.log(t);try{}catch(t){}}()}();

which results in:

Uncaught ReferenceError: t is not defined(…)

Tested on: https://github.com/Skalman/UglifyJS-online

@avdg
Copy link
Contributor

avdg commented Oct 21, 2016

Please update uglify to the latest version

@avdg
Copy link
Contributor

avdg commented Oct 21, 2016

Also, reproducible on master, so this is actually a valid bug report. Uh variable is defined, so no bug on master. It's just using the same mangle variable.

@fregante
Copy link
Author

fregante commented Oct 21, 2016

hmm I was actually about to close it because it doesn't seem to appear in 2.7.0 and 2.7.3

$ uglifyjs --version
uglify-js 2.6.4
$ uglifyjs a.js --compress unused
WARN: Dropping unused variable e [a.js:2,8]
!function(){return function(){console.log(e);try{}catch(e){}}()}();
$ uglifyjs --version
uglify-js 2.7.3
$ uglifyjs a.js --compress unused
!function(){var e="I’m gooooooooone!";return function(){console.log(e);try{}catch(e){}}()}();

Is there a regression?

@fregante
Copy link
Author

Cool, closing then :)

@kzc
Copy link
Contributor

kzc commented Oct 21, 2016

@bfred-it First I'd like to congratulate you for filing Issue 1337. You can claim your prize at the door.

Your test case is a --support-ie8 bug - a.k.a. screw_ie8=false.

--support-ie8 used to be the default for uglify-js@2.6.x and earlier.

The default for uglify-js@2.7.x is now --screw-ie8. See #409 (comment) and #1179.

$ uglifyjs -V
uglify-js 2.7.3
$ cat a.js
(function() {
    var e = 'I’m gooooooooone!';
    return (function () {
        console.log(e)
        try {} catch (e) {}
    })()
}());

--support-ie8

$ uglifyjs a.js --support-ie8 -cm
WARN: Dropping unused variable e [a.js:2,8]
!function(){return function(){console.log(n);try{}catch(n){}}()}();
$ uglifyjs a.js --support-ie8 -cm | node
WARN: Dropping unused variable e [a.js:2,8]
[stdin]:1
!function(){return function(){console.log(n);try{}catch(n){}}()}();
                                          ^

ReferenceError: n is not defined

--screw-ie8

$ uglifyjs a.js --screw-ie8 -cm
!function(){var o="I’m gooooooooone!";return function(){console.log(o);try{}catch(o){}}()}();
$ uglifyjs a.js --screw-ie8 -cm | node
I’m gooooooooone!
$ uglifyjs a.js -cm | node
I’m gooooooooone!

@fregante
Copy link
Author

Gotcha! Thanks for the explanation!

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

3 participants