Skip to content

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

Closed

Description

@jaskp

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.

Activity

  1. changed the title [-]plugin-commonjs misses export in conditional statement affected by plugin-replace[/-] [+]plugin-commonjs broken by `|| false`[/+] on Sep 23, 2024
  2. changed the title [-]plugin-commonjs broken by `|| false`[/-] [+][plugin-commonjs] Untransformed `exports` in conditional branch[/+] on Oct 23, 2024
  3. jaskp commented on Oct 23, 2024

    @jaskp
    Author

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

  4. shellscape commented on Oct 23, 2024

    @shellscape
    Collaborator

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

  5. stale commented on Apr 27, 2025

    @stale

    Hey folks. This issue hasn't received any traction for 60 days, so we're going to close this for housekeeping. If this is still an ongoing issue, please do consider contributing a Pull Request to resolve it. Further discussion is always welcome even with the issue closed. If anything actionable is posted in the comments, we'll consider reopening it. ⓘ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions