You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bun-ESM: an imported function aliased as main is auto-run on import #805
bugSomething is broken or behaves incorrectlypriority:p2Normal - queue itscope:repoConfined to this repositorystatus:readyFully specified and ready to be picked up
Found in review of #802 (CodeRabbit, thread r4701588611). The behaviour predates #802; it was kept there to keep that PR's scope.
What happens. When the root imports a function under the alias main (use A::{entry as main};) and declares no main itself, the flattened program has a top-level fn main. The Bun-ESM emitter treats any top-level main as the entry point and emits await main();, so importing the generated module runs A::entry as a side effect.
Expected. Only a main the root module itself declares is auto-run. An imported binding stays callable under its bound name and is not called on load. The root's own fn main keeps its auto-call.
Likely fix. The flattener records whether the root declares main (or marks bound-name copies), and the emitters (Bun-ESM, JS) emit the auto-call only in that case. Add a regression test for the aliased import and keep the existing root-main tests.
The concrete trigger (use A::{entry as main}; with no root main) plus the stated rule for which main should auto-run makes this easy to act on.
When the root module only imports a function aliased as main, the flattened program still ends up with a top-level fn main. The Bun-ESM emitter treats that as the entry point and emits await main();, so importing the generated module runs A::entry as a side effect. Only a main the root declares itself should be auto-called. An aliased import should stay callable as main but not run on load.
One thing to confirm: does the plain JS emitter show the same auto-call today, or is it Bun-ESM only? Your fix mentions both, and that decides how far the regression test needs to reach.
flowchart TD
A[📱 Root module] --> B{"Where does 'main' come from?"}
B -->|Root declares fn main| C[✅ Emit await main()]
B -->|"use A::{entry as main}"| D[🔄 Flattened top-level fn main]
D --> E[🔴 Emits await main() today]
D --> F[✅ Expected: callable, no auto-run]
#797 - fix: module flattening, Bun-ESM match lowering and loader follow-ups to #788 [merged]
📝 Issue Planner
Check the box below or use the @coderabbitai plan command to generate an implementation plan and prompts that you can use with your favorite coding assistant.
Create Plan
🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your .coderabbit.yaml:
issue_enrichment:
auto_enrich:
enabled: false
💬 Have feedback or questions? Drop into our discord!
🤖 WhatProblem only responds to issues and comments written by people.
This one came from coderabbitai[bot], so we skipped it. Automated issues from CI, linters and dependency bots are usually already actionable, and skipping them keeps your monthly allowance for the issues your team writes.
You'll see this note at most once a month per repository. If you would rather we did respond to automated issues, tell us below.
bugSomething is broken or behaves incorrectlypriority:p2Normal - queue itscope:repoConfined to this repositorystatus:readyFully specified and ready to be picked up
Activity
whatproblem-ai commentedon Nov 25, 2026
The concrete trigger (
use A::{entry as main};with no rootmain) plus the stated rule for whichmainshould auto-run makes this easy to act on.When the root module only imports a function aliased as
main, the flattened program still ends up with a top-levelfn main. The Bun-ESM emitter treats that as the entry point and emitsawait main();, so importing the generated module runsA::entryas a side effect. Only amainthe root declares itself should be auto-called. An aliased import should stay callable asmainbut not run on load.One thing to confirm: does the plain JS emitter show the same auto-call today, or is it Bun-ESM only? Your fix mentions both, and that decides how far the regression test needs to reach.
flowchart TD A[📱 Root module] --> B{"Where does 'main' come from?"} B -->|Root declares fn main| C[✅ Emit await main()] B -->|"use A::{entry as main}"| D[🔄 Flattened top-level fn main] D --> E[🔴 Emits await main() today] D --> F[✅ Expected: callable, no auto-run]🏆 Clarity Score: 92% - Clear and concise! 🎯
⌨️ Commands · 💬 Have feedback? Tell us · 🎯 New here? Add WhatProblem to your repo · 🔒 Privacy
coderabbitai commentedon Nov 25, 2026
🔗 Related PRs
#797 - fix: module flattening, Bun-ESM match lowering and loader follow-ups to
#788[merged]📝 Issue Planner
Check the box below or use the
@coderabbitai plancommand to generate an implementation plan and prompts that you can use with your favorite coding assistant.🧪 Issue enrichment is currently in open beta.
You can configure auto-planning by selecting labels in the issue_enrichment configuration.
To disable automatic issue enrichment, add the following to your
.coderabbit.yaml:💬 Have feedback or questions? Drop into our discord!
whatproblem-ai commentedon Nov 25, 2026
🤖 WhatProblem only responds to issues and comments written by people.
This one came from
coderabbitai[bot], so we skipped it. Automated issues from CI, linters and dependency bots are usually already actionable, and skipping them keeps your monthly allowance for the issues your team writes.You'll see this note at most once a month per repository. If you would rather we did respond to automated issues, tell us below.
⌨️ Commands · 💬 Have feedback? Tell us · 🔒 Privacy
Merge origin/main into claude/gifted-lamport-k0mc5l