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

`Object.keys()` @nosideeffects semantics is not applied consistently

Open KimlikDAO-bot opened this issue 8 months ago • 1 comments

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.

KimlikDAO-bot avatar Feb 09 '25 23:02 KimlikDAO-bot