Skip to content

Convert module.exports = { foo: 'bar'} to ESM in bun build - #3103

Merged
Jarred-Sumner merged 2 commits into
mainfrom
jarred/cjs
May 29, 2023
Merged

Jarred-Sumner merged 2 commits into
mainfrom
jarred/cjs

Conversation

@Jarred-Sumner

Copy link
Copy Markdown
Collaborator

No description provided.

@github-actions

github-actions Bot commented May 28, 2023 •

Copy link
Copy Markdown
Contributor

❌ @Jarred-Sumner 27 files with test failures on linux-x64:

  • test/bundler/api.test.ts
  • test/bundler/bundler_browser.test.ts
  • test/bundler/bundler_edgecase.test.ts
  • test/bundler/bundler_jsx.test.ts
  • test/bundler/bundler_naming.test.ts
  • test/bundler/bundler_plugin.test.ts
  • test/bundler/esbuild/dce.test.ts
  • test/bundler/esbuild/default.test.ts
  • test/bundler/esbuild/extra.test.ts
  • test/bundler/esbuild/importstar.test.ts
  • test/bundler/esbuild/loader.test.ts
  • test/bundler/esbuild/packagejson.test.ts
  • test/bundler/esbuild/splitting.test.ts
  • test/bundler/esbuild/ts.test.ts
  • test/bundler/esbuild/tsconfig.test.ts
  • test/cli/hot/hot.test.ts
  • test/cli/run/env.test.ts
  • test/cli/run/preload-test.test.js
  • test/cli/run/run-cjs.test.ts
  • test/js/bun/plugin/plugins.test.ts
  • test/js/bun/resolve/png/test-png-import.test.js
  • test/js/bun/test/preload-test.test.js
  • test/js/bun/test/snapshot-tests/snapshots/more-snapshots/different-directory.test.ts
  • test/js/bun/test/snapshot-tests/snapshots/more.test.ts
  • test/js/bun/websocket/websocket-server.test.ts
  • test/js/node/child_process/child_process-node.test.js
  • test/transpiler/transpiler.test.js

View test output

#91044b0b68386b0472bdf50ab80df7d2f4b8586e

@github-actions

github-actions Bot commented May 28, 2023 •

Copy link
Copy Markdown
Contributor

❌ @Jarred-Sumner 27 files with test failures on linux-x64-baseline:

  • test/bundler/api.test.ts
  • test/bundler/bundler_browser.test.ts
  • test/bundler/bundler_edgecase.test.ts
  • test/bundler/bundler_jsx.test.ts
  • test/bundler/bundler_naming.test.ts
  • test/bundler/bundler_plugin.test.ts
  • test/bundler/esbuild/dce.test.ts
  • test/bundler/esbuild/default.test.ts
  • test/bundler/esbuild/extra.test.ts
  • test/bundler/esbuild/importstar.test.ts
  • test/bundler/esbuild/loader.test.ts
  • test/bundler/esbuild/packagejson.test.ts
  • test/bundler/esbuild/splitting.test.ts
  • test/bundler/esbuild/ts.test.ts
  • test/bundler/esbuild/tsconfig.test.ts
  • test/cli/hot/hot.test.ts
  • test/cli/run/env.test.ts
  • test/cli/run/preload-test.test.js
  • test/cli/run/run-cjs.test.ts
  • test/js/bun/plugin/plugins.test.ts
  • test/js/bun/resolve/png/test-png-import.test.js
  • test/js/bun/test/preload-test.test.js
  • test/js/bun/test/snapshot-tests/snapshots/more-snapshots/different-directory.test.ts
  • test/js/bun/test/snapshot-tests/snapshots/more.test.ts
  • test/js/bun/websocket/websocket-server.test.ts
  • test/js/node/child_process/child_process-node.test.js
  • test/transpiler/transpiler.test.js

View test output

#91044b0b68386b0472bdf50ab80df7d2f4b8586e

@github-actions

github-actions Bot commented May 28, 2023 •

Copy link
Copy Markdown
Contributor

❌ @Jarred-Sumner 32 files with test failures on bun-darwin-x64-baseline:

  • test/bundler/api.test.ts
  • test/bundler/bundler_browser.test.ts
  • test/bundler/bundler_edgecase.test.ts
  • test/bundler/bundler_jsx.test.ts
  • test/bundler/bundler_naming.test.ts
  • test/bundler/bundler_plugin.test.ts
  • test/bundler/esbuild/dce.test.ts
  • test/bundler/esbuild/default.test.ts
  • test/bundler/esbuild/extra.test.ts
  • test/bundler/esbuild/importstar.test.ts
  • test/bundler/esbuild/loader.test.ts
  • test/bundler/esbuild/packagejson.test.ts
  • test/bundler/esbuild/splitting.test.ts
  • test/bundler/esbuild/ts.test.ts
  • test/bundler/esbuild/tsconfig.test.ts
  • test/cli/hot/hot.test.ts
  • test/cli/run/env.test.ts
  • test/cli/run/preload-test.test.js
  • test/cli/run/run-cjs.test.ts
  • test/js/bun/plugin/plugins.test.ts
  • test/js/bun/resolve/png/test-png-import.test.js
  • test/js/bun/spawn/spawn-streaming-stdin.test.ts
  • test/js/bun/spawn/spawn.test.ts
  • test/js/bun/sqlite/sqlite.test.js
  • test/js/bun/test/preload-test.test.js
  • test/js/bun/test/snapshot-tests/snapshots/more-snapshots/different-directory.test.ts
  • test/js/bun/test/snapshot-tests/snapshots/more.test.ts
  • test/js/bun/util/sleepSync.test.ts
  • test/js/node/child_process/child_process-node.test.js
  • test/js/web/timers/setInterval.test.js
  • test/js/web/timers/setTimeout.test.js
  • test/transpiler/transpiler.test.js

View test output

#91044b0b68386b0472bdf50ab80df7d2f4b8586e

@Jarred-Sumner
Jarred-Sumner merged commit 2b04ef4 into main May 29, 2023
@Jarred-Sumner
Jarred-Sumner deleted the jarred/cjs branch May 29, 2023 04:02
crishoj added a commit to crishoj/bun that referenced this pull request Jul 29, 2026
PR oven-sh#3103 (May 2023) added this conversion together with a Zig loop-else
bug that permanently disabled it: the trivial-property validation
loop's only exit is `return null` — no `break` — so the `else` branch,
intended as the empty-object de-opt, ran after every completed loop and
the rewrite code was unreachable from day one. The Rust port mirrored
the shipped behavior and deleted the dead rewrite code.

Reconstruct the rewrite from the pre-rewrite Zig (maybe.zig at
23427db^), with two deliberate changes:
- set esm_export_keyword like the live `exports.<name> = ...`
  conversion in visit_stmt.rs does (the never-run Zig omitted it), and
- emit only one export clause per key, so a duplicate key in the object
  literal ({ foo: 1, foo: 2 }) reassigns the ref (last-wins) instead of
  producing a duplicate `export { $foo as foo }`.

The empty-object case keeps de-opting, now via an explicit
props.is_empty() check. cjs2esm/UnwrappedModuleRequireAssigned's
__toESM assertion is updated: the fixture's `module.exports =
{ react: "react" }` now unwraps fully, so no interop helper remains.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant