fix(bundler): propagate star import through barrel namespace re-exports#28173
Conversation
When a barrel file re-exports a namespace import (`import * as X from
'./mod'; export { X }`), the barrel optimization BFS was propagating
to the target module with `is_star = false`. This caused the target's
own re-exports to be incorrectly deferred, dropping function definitions
from the bundled output.
The fix threads `alias_is_star` through `BarrelExportResolution` so the
BFS correctly treats namespace re-exports as star imports, ensuring all
exports from the target module are included.
Closes #28170
Closes #28137
https://claude.ai/code/session_0188mQLPgSvNV2rVAqDh42mt
|
Updated 8:42 PM PT - Mar 16th, 2026
❌ @robobun, your commit 5208312 has 1 failures in
🧪 To try this PR locally: bunx bun-pr 28173That installs a local version of the PR into your bun-28173 --bun |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (1)
WalkthroughAdded Changes
🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📝 Coding Plan
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@test/regression/issue/28170.test.ts`:
- Around line 91-93: The test currently asserts installExit === 0 but doesn't
surface captured logs on failure; update the failure path around the
installProc/installExit check (and the similar block at lines 112-119) to log
the captured process output before asserting: await the stored streams
(installProc.stderr.text() and installProc.stdout.text()) and print them (e.g.,
console.error) if installExit is non-zero so CI failures show the stderr/stdout;
do the same for the corresponding process variables in the later block (the
build/install process variables used in lines 112-119) before calling
expect(...).toBe(0).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: d767914e-a1e9-47cd-8e3c-207e8220c5cc
📒 Files selected for processing (2)
src/bundler/barrel_imports.zigtest/regression/issue/28170.test.ts
|
Found 3 issues this PR may fix:
🤖 Generated with Claude Code |
There was a problem hiding this comment.
LGTM — small, well-targeted fix threading alias_is_star through BarrelExportResolution with a good regression test.
Extended reasoning...
Overview
This PR fixes a bug where the barrel optimization BFS incorrectly hardcoded is_star = false when propagating through re-exported namespace imports (import * as X from "./mod"; export { X }). The fix adds alias_is_star: bool to the BarrelExportResolution struct, populates it from the existing import_entry.alias_is_star field in resolveBarrelExport, and uses it in the BFS propagation step instead of the hardcoded false. This is a 3-line production code change. A comprehensive regression test is included that sets up a workspace with barrel files using namespace re-exports and verifies the bundled output.
Security risks
None. This is a bundler optimization fix that corrects which exports are loaded during barrel optimization BFS. No auth, crypto, permissions, or user-facing input handling is involved.
Level of scrutiny
Low scrutiny is appropriate. The change is mechanical — it threads an existing boolean field through an intermediate struct so the BFS correctly identifies star imports. The field alias_is_star already exists on NamedImport (defined in src/ast.zig:589) and is already used elsewhere in the codebase (e.g., ImportScanner.zig, LinkerContext.zig). No CODEOWNERS are affected.
Other factors
- The regression test comprehensively covers the fix scenario with a multi-package workspace setup that exercises the exact barrel re-export pattern that was broken.
- The only bug found by automated review is a minor nit about asserting stderr before exit code in the test, which is a diagnostic improvement, not a correctness issue.
- The PR closes two reported issues (#28170 and #28137).
There was a problem hiding this comment.
LGTM — small, well-scoped fix threading an existing boolean through barrel BFS propagation, with a solid regression test.
Extended reasoning...
Overview
This PR touches two files: src/bundler/barrel_imports.zig (the core fix) and test/regression/issue/28170.test.ts (a new regression test). The Zig change adds an alias_is_star: bool field to the internal BarrelExportResolution struct, populates it from the already-existing import_entry.alias_is_star field in resolveBarrelExport, and uses it at the single BFS propagation point where the value was previously hardcoded to false. This is a 3-line struct addition and a 1-line behavioral fix.
Security risks
None. This is an internal bundler optimization path — no user input handling, no auth, no network, no file system access beyond what the bundler already does.
Level of scrutiny
The change is small and mechanical: it threads an existing boolean through one intermediate struct. The alias_is_star field is already well-established in the codebase (src/ast.zig:589, ImportScanner.zig, LinkerContext.zig, and already used in barrel_imports.zig lines 283 and 351 for initial BFS seeding). The fix is a natural extension of the existing pattern. The regression test creates a realistic monorepo workspace setup and verifies the bundled output executes correctly.
Other factors
- Previous review nits (from coderabbitai and my prior run) about surfacing install/build errors in test assertions have been addressed (commit
5208312). - All inline comments are resolved.
- The PR fixes real user-reported issues (#28170, #28137) with clear root cause analysis.
- No CODEOWNERS concerns for these paths.
- The test follows established patterns in the test suite.
…ts (oven-sh#28173) ## Summary - Fixes barrel optimization dropping exports when a barrel re-exports namespace imports (`import * as X from './mod'; export { X }`) with `sideEffects: false` - The BFS propagation now correctly threads `alias_is_star` through `BarrelExportResolution`, treating namespace re-exports as star imports in the target module ## Root Cause When the barrel optimization BFS encountered a re-exported namespace import like: ```ts // utils/index.ts (sideEffects: false) import * as typed from './arrays/typed/index.js'; export { typed }; ``` It propagated to `./arrays/typed/index.js` with `is_star = false` and an empty alias. The target barrel's own re-exports (e.g., `export { toDataView } from './misc.js'`) were then incorrectly deferred because the BFS tried to find an export named `""` instead of loading all exports. ## Fix Added `alias_is_star` to `BarrelExportResolution` and used it during BFS propagation. When the underlying import is `import * as ns`, the propagation now uses `is_star = true`, ensuring the target module's exports are all loaded. ## Verification ``` USE_SYSTEM_BUN=1 bun test test/regression/issue/28170.test.ts â�� FAIL (toDataView is not defined) bun bd test test/regression/issue/28170.test.ts â�� PASS ``` Closes oven-sh#28170 Closes oven-sh#28137 --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Summary
import * as X from './mod'; export { X }) withsideEffects: falsealias_is_starthroughBarrelExportResolution, treating namespace re-exports as star imports in the target moduleRoot Cause
When the barrel optimization BFS encountered a re-exported namespace import like:
It propagated to
./arrays/typed/index.jswithis_star = falseand an empty alias. The target barrel's own re-exports (e.g.,export { toDataView } from './misc.js') were then incorrectly deferred because the BFS tried to find an export named""instead of loading all exports.Fix
Added
alias_is_startoBarrelExportResolutionand used it during BFS propagation. When the underlying import isimport * as ns, the propagation now usesis_star = true, ensuring the target module's exports are all loaded.Verification
Closes #28170
Closes #28137