Repository navigation
Conversation
…ep this undefined When a call to an imported binding is printed as a property access on the namespace object (dev server / HMR chunks and CJS-format output), the namespace object leaked in as the call receiver. Browsers reject that receiver for natives like queueMicrotask with TypeError: Illegal invocation. The existing wrap check compared the call target against EIdentifier, but a rewritten import is always an EImportIdentifier, so it never matched. Match EImportIdentifier instead, and clear call_target after printing the target so a later occurrence of the same binding (e.g. as an argument) is not mistaken for the call target. Fixes #34733
|
Warning Review limit reached
Next review available in: 3 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
Comment |
|
Updated 6:48 PM PT - Jul 19th, 2026
❌ @robobun, your commit 55a495a has 1 failures in
🧪 To try this PR locally: bunx bun-pr 34734That installs a local version of the PR into your bun-34734 --bun |
There was a problem hiding this comment.
Beyond the inline nit, I checked that the new call_target = None clear is safe for nested calls (outer(inner()) — the inner ECall re-sets it before printing its own target), and grep confirms lines 4275/4314 are the only readers of call_target, so nothing downstream depended on it staying set through the args.
Extended reasoning...
The two changed match arms were provably dead before this PR: they sit inside the ExprData::EImportIdentifier case yet matched call_target against EIdentifier, which the ECall arm sets to e.target.data — the very EImportIdentifier being printed. Switching the pattern to EImportIdentifier makes the existing (0, ns.fn) wrap actually fire, and clearing call_target after the target prints stops fn(fn) from spuriously wrapping the argument. Deferring only because the printer is core output-shaping code and the tagged-template sibling flagged inline is a judgement call on scope.
…t snapshots A template tag receives this the same way a call target does, so a rewritten import used as a tag gets the same (0, ns.fn) wrap. Update the react-compiler snapshot and ReactSSR sourcemap columns and file size for the new call output.
There was a problem hiding this comment.
LGTM — the follow-up commit covers tagged template tags as well, so the receiver fix now applies to both call shapes.
What was reviewed:
- The
EIdentifier→EImportIdentifiermatch swap in both wrap-check sites; confirmed the old match was dead (call targets that reach this arm are alwaysEImportIdentifier), so no behavior is lost. - Clearing
call_targetafter printing the target/tag — traced thatcall_targethas no other readers, so the clear only prevents spurious wrapping of the same ref appearing later as an argument or in a following statement. - Snapshot / filesize / source-map column drift in
bundler_npmandreact-compilersnapshots are the expected downstream effect of new(0, ...)wrappers around namespace-rewritten React calls.
Extended reasoning...
Overview
Fixes #34733: when an imported binding is rewritten to a namespace property access (dev server / internal_bake_dev, or CJS output with external imports), calling it as fn() was emitted as ns.fn(), which passes ns as this and breaks receiver-checking natives like queueMicrotask. The printer already had a wrap check for this, but it matched ExprData::EIdentifier while the call target at print time is always ExprData::EImportIdentifier, so it never fired. The PR:
- Swaps the match to
EImportIdentifierin both wrap-check sites (src/js_printer/lib.rs:4282,:4320). - Clears
self.call_targetafter printing the call target (:3520) and the template tag (:4180) so a later occurrence of the same ref (as an argument, or in a subsequent expression) isn't spuriously wrapped. - Sets
call_targetfor tagged templates (:4172) — this addresses my earlier review note about the siblingETemplatearm having the same receiver hazard. - Adds an
itBundledoutput-shape test and a behavioral dev-server test; updates the react-compiler snapshot and thebundler_npmfilesize/source-map columns to account for the extra(0, ...)wrappers.
Security risks
None. This is a code-generation correctness fix with no security-sensitive surface (no auth, crypto, filesystem, or network paths touched).
Level of scrutiny
Medium. The printer is on the hot path for all bundled/transpiled output, so a wrong change here would affect every bundle. That said, the diff is ~10 lines of Rust with a very narrow effect: it only changes output when an EImportIdentifier with a namespace_alias is the direct target of a call/tagged-template and was_originally_identifier() is set. I grep'd for all readers of call_target — only the two wrap checks read it, so clearing it after use cannot regress anything else. The old EIdentifier match was provably dead (the arm is only reached for EImportIdentifier nodes, and an EIdentifier call target can't share a ref with one), so nothing is lost by removing it. The output now matches esbuild's semantics for the ECall case, which is the reference per REVIEW.md.
Other factors
- My prior inline comment about tagged templates was addressed in 5ae556c with a test assertion (
(0, import_util.tag)\template``). - The
was_originally_identifier()guard is preserved unchanged, sons.fn()(where the user wrote a member access) is not wrapped. - The new bundler test asserts both positive (calls/tags wrap) and negative (non-call uses stay as plain property access; arguments aren't wrapped) cases, and the dev-server test is behavioral (checks the actual receiver at runtime).
- Snapshot and
expectExactFilesizedrift inbundler_npm.test.ts(+20 bytes, two column offsets +16) is consistent with a handful ofimport_react.foo(...)→(0, import_react.foo)(...)wraps in the minified React bundle.
|
CI status: all bundler, transpiler, and dev server suites are green. The only hard failure is test/js/node/test/parallel/test-net-connect-memleak.js on the Alpine lanes, which fails on main as well (pre-existing, being handled separately); the other red entries passed on retry. The diff is ready for review. |
|
Closing as part of a cleanup of stale pull requests. This PR has had no new commits since 2026-07-20, it conflicts with main, and its last CI run failed. This is not a judgment on the fix itself. The linked issue (#34733) stays open. If the problem still reproduces on a current build, reopen this PR after a rebase or open a new one against main. |
What does this PR do?
Fixes #34733.
With the dev server / HMR (and any output where an imported binding is rewritten to a property access on a namespace object, e.g.
--format cjswith external imports), a call like:was printed as:
That changes the call receiver from
undefinedto the namespace object. For natives with a Web IDL receiver check, browsers throwTypeError: Illegal invocation(WebKit:TypeError: Can only call Window.queueMicrotask on instances of Window).Cause
The printer already had logic to wrap such calls as
(0, ns.fn)(...), but the check compared the recorded call target againstEIdentifier. A rewritten import is always anEImportIdentifierat print time, so the check never matched and the wrap never fired (the pre-port Zig printer had the same comparison, which is why stable releases are affected too).Fix
EImportIdentifier(by ref) in the wrap check, so calls print as(0, ns.fn)(...)andthisstaysundefined, matching esbuild.call_targetafter printing the call target, so a later occurrence of the same binding (e.g. as an argument) is not mistaken for the call target and spuriously wrapped.Dev server chunk after the fix:
Non-call uses keep the plain property access (
const alias = import_util.microtask;), and CJS-format output now matches esbuild ((0, import_ext.fn)(1)for calls,other(import_ext.fn)for arguments).Tests
test/bundler/bundler_edgecase.test.ts:edgecase/BakeDevImportedFunctionCallReceiverasserts theinternal_bake_devchunk wraps calls and leaves non-call uses unwrapped.test/bake/dev/esm.test.ts: behavioral dev-server test asserting an imported function call does not receive the module namespace asthis.Both fail on bun without the fix (the dev test returns
false, i.e. the receiver was the module object) and pass with it. Also ranbundler_edgecase,bundler_loader,bundler_cjs2esm,esbuild/default,esbuild/importstar,esbuild/packagejson, and the fulltest/bake/dev/esm.test.tslocally: all green.no test proof · iteration 1 · Platform-specific test(s) that do not run on this machine. Deferring to CI, which covers all platforms: test/bundler/bundler_edgecase.test.ts test/bundler/bundler_npm.test.ts