rollup / plugins

🍣 The one-stop shop for official Rollup plugins
MIT License
3.65k stars 591 forks source link

[plugin-commonjs] Untransformed `exports` in conditional branch #1771

Open jaskp opened 2 months ago

jaskp commented 2 months ago

Expected Behavior

All reachable CJS exports (i.e. exports.foo = bar) are transformed.

Actual Behavior

A reachable CJS export remains in the true branch:

/* dist/index.mjs */
if (globalThis.crypto || false) {
  // 👇
  exports.getRandomValue = () =>
    globalThis.crypto.getRandomValues(new Uint8Array(1))[0];
} else {
  lib.getRandomValue = () => {
    throw Error();
  };
}

Additional Information

This happens when appending || false to the condition in the if statement.

jaskp commented 1 month ago

Would it be possible to address this? @shellscape should I rather post this into the main Rollup repo?

shellscape commented 1 month ago

Thanks for the issue, but this will likely need community contribution to resolve. We're very short on maintainers at the moment.