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: catch var dropped as unused #1715

Closed
pvdz opened this issue Mar 28, 2017 · 2 comments · Fixed by #1716
Closed

Bug: catch var dropped as unused #1715

pvdz opened this issue Mar 28, 2017 · 2 comments · Fixed by #1716

Comments

@pvdz
Copy link
Contributor

pvdz commented Mar 28, 2017

  • Bug report or feature request?
    Bug. Found by fuzzer.

  • uglify-js version (uglifyjs -V)
    Git master, f71f490

I think this means #1708 isn't completely solved yet.

var a = 100, b = 10, c = 0;
function f() {
    try {
    } catch (b) {
        return;
        try {
        } catch (foo) {
            var b = 999;
        }
    } finally {
        --b
    }
}
f();
console.log(null, a, b, c);
$ bin/uglifyjs s.js -c && bin/uglifyjs s.js -c passes=3 && bin/uglifyjs s.js -c passes=3 -m 
WARN: Dropping unreachable code [s.js:6,8]
WARN: Declarations in unreachable code! [s.js:8,12]
function f(){try{}catch(b){return}finally{--b}}var a=100,b=10,c=0;f(),console.log(null,a,b,c);
WARN: Dropping unreachable code [s.js:6,8]
WARN: Declarations in unreachable code! [s.js:8,12]
function f(){try{}catch(b){return}finally{--b}}var a=100,b=10,c=0;f(),console.log(null,a,b,c);
WARN: Dropping unreachable code [s.js:6,8]
WARN: Declarations in unreachable code! [s.js:8,12]
function f(){try{}catch(b){return}finally{--b}}var a=100,b=10,c=0;f(),console.log(null,a,b,c);
$ cat s.js | node && node s.js && bin/uglifyjs s.js -c | node && bin/uglifyjs s.js -c passes=3 | node && bin/uglifyjs s.js -c passes=3 -m | node
null 100 10 0
null 100 10 0
WARN: Dropping unreachable code [s.js:6,8]
WARN: Declarations in unreachable code! [s.js:8,12]
null 100 9 0
WARN: Dropping unreachable code [s.js:6,8]
WARN: Declarations in unreachable code! [s.js:8,12]
null 100 9 0
WARN: Dropping unreachable code [s.js:6,8]
WARN: Declarations in unreachable code! [s.js:8,12]
null 100 9 0
@alexlamsl
Copy link
Collaborator

alexlamsl commented Mar 28, 2017

This one is due to drop_unused failing to extract declarations - fixing... 🤖

@alexlamsl
Copy link
Collaborator

Minimal test case:

options = {
    unused: true,
}
input: {
    var a = 1;
    function f() {
        a++;
        try {} catch (a) {
            var a;
        }
    }
    f();
    console.log(a);
}

@alexlamsl alexlamsl changed the title Bug: catch var in finally using wrong scope Bug: catch var dropped as unused Mar 28, 2017
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Mar 28, 2017
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Mar 28, 2017
alexlamsl added a commit to alexlamsl/UglifyJS that referenced this issue Mar 28, 2017
When fixing catch-related issue in mishoo#1715, it tries to optimise for duplicate definitions but did not take anonymous functions into account.

Remove such optimisation for now and we can cover this as a more general rule later.
alexlamsl added a commit that referenced this issue Mar 28, 2017
When fixing catch-related issue in #1715, it tries to optimise for duplicate definitions but did not take anonymous functions into account.

Remove such optimisation for now and we can cover this as a more general rule later.
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

Successfully merging a pull request may close this issue.

2 participants