Skip to content

multiple var assignment to same value with unused vars is compressed incorrectly #1539

@rincedd

Description

@rincedd

uglify-js@2.8.4 compresses the snippet

function foo() {
  'use strict';
  var myVar, myVar2;
  myVar = myVar2 = 42;
  return myVar;
}

console.log(foo());

to this:

uglifyjs --compress --mangle -- index.js 
WARN: Dropping unused variable myVar [index.js:3,5]
WARN: Dropping unused variable myVar2 [index.js:3,12]
function foo(){"use strict";return myVar2=42}console.log(foo());

Note that the variable declarations are dropped completely and myVar2 in the assignment seems to be wrongly considered to be a global variable. Due to strict mode, the minified version actually produces a ReferenceError now.

A similar case has also been reported in issue #1502, where myVar2 however was indeed a global variable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions