Description
The following test case is compiled incorrectly when language_out is ECMASCRIPT_2015 or later. (This is the smallest I could make it and still reproduce the issue. I found it in the middle of much more complicated code.)
function test(a, b) {
"use strict";
console.log(b);
if ('123' == b) {
const Y = a.c;
if ('abc' == Y)
a.Z = a.d;
if ('abc' != Y)
return Y;
}
return b;
}
The result of running
java -jar closure-compiler-v20190819.jar --language_out=ECMASCRIPT_2015 test.js
is as follows:
'use strict';function test2(b,a){console.log(a);if("123"==a){const a=b.c;"abc"==a&&(b.Z=b.d)}return a};
You might be able to see that the output is missing the “if('abc' != Y) return Y” branch. When calling the method with arguments ({c:'xyz'},'123'), the correct result is 'xyz', but the compiled method returns '123'.
(The output also moves “use strict” outside the function, even if you add another non-strict function to the input file. This is wrong, since it’ll turn the other functions into strict ones. But that’s probably a different issue.)
Using ECMASCRIPT5 for the output language generates correct code.