closure-compiler
closure-compiler copied to clipboard
`Object.keys()` @nosideeffects semantics is not applied consistently
In certain cases, unused Object.keys() is not elided.
Consider
Object.keys({
"a": 1,
"b": 2,
});
google-closure-compiler --js a.js -O ADVANCED outputs [JSC_USELESS_CODE] however
const a = Object.keys({
"a": 1,
"b": 2,
});
google-closure-compiler --js a.js -O ADVANCED outputs Object.keys({a:1,b:2});
Namely assigning an Object.keys() to an unused variable leads to elimination of the variable but not the method call.
The externs definition seems correct but something else is interfering.