You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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;
}
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.
The text was updated successfully, but these errors were encountered:
so it's the latePeepholeOptimizations that's breaking this.
Probably one of the optimizations sees two return a; statements in the function and doesn't realize that they may refer to different variables, so eliminates the seemingly unnecessary return a;.
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.)
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.
The text was updated successfully, but these errors were encountered: