closure-compiler icon indicating copy to clipboard operation
closure-compiler copied to clipboard

Variable inlining changes program behavior by ignoring var hoisting

Open hcnelson99 opened this issue 5 years ago • 10 comments

test.js:

var x = 1;
var z = function () {
    var y = x;
    var x = 0;
    return y;
}();
console.log(z);

Observed behavior:

$ node test.js
undefined
$ closure-compiler test.js
var x=1,z=function(){return 0}();console.log(z);
$ closure-compiler test.js | node
0

Desired behavior: closure-compiler should not change program behavior.

Version:

$ closure-compiler --version
Closure Compiler (http://github.com/google/closure-compiler)
Version: 1.0-SNAPSHOT
Built on: 2018-07-18 15:08

hcnelson99 avatar Jul 18 '18 15:07 hcnelson99