Terser: Minified code gets confused when declaring same variable name in try-block

Created on 17 Apr 2019  路  7Comments  路  Source: terser/terser

Bug

Version (complete output of terser -V)

terser 4.1.4

Complete CLI command or minify() options used

terser --compress --mangle

terser input

function test(foo, bar) {
    let model = false;
    if (model) {

    } else {
        model = true;
    }
    try {
        const bar = {};
    } catch (error) {
        bar.dispose();
    }
}

terser output or error

function test(t,c){let s=!1;s||(s=!0);try{const t={}}catch(c){t.dispose()}}

Expected result

Within the catch block, it should be c.dispose() and not t.dispose()! After all, the wrong parameter is being called dispose on.

bug

All 7 comments

I was able to reproduce this in 4.0.0.

One note, because it tripped me off initially:
It is expected to be c.dispose() because of function test(t,c), not because of catch(c).
The use of the variable name c in the catch is actually wrong.

Thank you very much for the report.

This still reproduces with Terser 4.1.4.

Probably with the latest version too. I'll see what I can do this week.

Thanks, I just recently replaced uglify-es with latest terser for VSCode and it would be great to get that fix in eventually 馃憤

Very subtle bug, as it revealed a slight problem in the AST design.

Oh great, thanks for fixing it.

Was this page helpful?
0 / 5 - 0 ratings