UglifyJS icon indicating copy to clipboard operation
UglifyJS copied to clipboard

[ES6] Bug in rename and destructuring

Open lmartorella opened this issue 2 years ago • 0 comments

Uglify version 3.17.4

JavaScript input

This code is already mangled from a previous pass, but it is actually the input in this test case.

source-file.js:

function f(e) {
    const {
        p3: {
            p4: o   // Note the destructuring of `e` to extract e.p3.p4 and put in `o`
        }
    } = e;
    switch (o) {  // o is used
        case "X":
            const o = this.z;  // `o` is overwritten in the local scope (legit in ES)
            break;
    }
}

The uglifyjs CLI command executed or minify() options used.

npx uglifyjs --compress --mangle -- source-file.js

JavaScript output or error produced.

function f(n){const{}=n["p3"];if("X"===b){const b=this.z}}

Note the empty destructuring, probably the intention was to produce b, that is used in the switch branch (then correctly optimized with an if).

Thanks, L

lmartorella avatar May 30 '23 14:05 lmartorella