Skip to content

zig: bun.sourcemap -> bun.SourceMap - #23477

Merged
nektro merged 3 commits into
mainfrom
nektro-patch-15495
Oct 27, 2025
Merged

nektro merged 3 commits into
mainfrom
nektro-patch-15495

Conversation

@nektro

@nektro nektro commented Oct 11, 2025

Copy link
Copy Markdown
Contributor

addresses a TODO

@robobun

robobun commented Oct 11, 2025 •

Copy link
Copy Markdown
Collaborator
Updated 11:13 AM PT - Oct 14th, 2025

❌ @nektro, your commit 48352de has 2 failures in Build #29160 (All Failures):


🧪   To try this PR locally:

bunx bun-pr 23477

That installs a local version of the PR into your bun-23477 executable, so you can run:

bun-23477 --bun

@nektro
nektro marked this pull request as ready for review October 14, 2025 19:59
@coderabbitai

This comment was marked as duplicate.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
src/cli/test_command.zig (1)

955-980: Optional: guard against empty mapping map to prevent work when no coverage

Early return is already present after appending; consider returning immediately if map.count() == 0 to skip alloc/sort work.

-        var map = coverage.ByteRangeMapping.map orelse return;
+        var map = coverage.ByteRangeMapping.map orelse return;
+        if (map.count() == 0) return;
📜 Review details

Configuration used: CodeRabbit UI

Review profile: ASSERTIVE

Plan: Pro

Disabled knowledge base sources:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between bd88717 and 48352de.

📒 Files selected for processing (22)
  • src/StandaloneModuleGraph.zig (1 hunks)
  • src/bake/DevServer.zig (1 hunks)
  • src/bake/DevServer/IncrementalGraph.zig (1 hunks)
  • src/bake/DevServer/PackedMap.zig (1 hunks)
  • src/bake/DevServer/SourceMapStore.zig (1 hunks)
  • src/bun.js/SavedSourceMap.zig (1 hunks)
  • src/bun.js/VirtualMachine.zig (1 hunks)
  • src/bun.js/bindings/generated_classes_list.zig (1 hunks)
  • src/bun.js/virtual_machine_exports.zig (1 hunks)
  • src/bun.zig (1 hunks)
  • src/bundler/Chunk.zig (10 hunks)
  • src/bundler/LinkerContext.zig (9 hunks)
  • src/bundler/LinkerGraph.zig (1 hunks)
  • src/bundler/bundle_v2.zig (7 hunks)
  • src/bundler/linker_context/computeChunks.zig (6 hunks)
  • src/bundler/linker_context/postProcessCSSChunk.zig (1 hunks)
  • src/bundler/linker_context/postProcessJSChunk.zig (1 hunks)
  • src/bundler/linker_context/writeOutputFilesToDisk.zig (0 hunks)
  • src/cli/test_command.zig (7 hunks)
  • src/js_printer.zig (1 hunks)
  • src/sourcemap/CodeCoverage.zig (1 hunks)
  • src/sourcemap/JSSourceMap.zig (5 hunks)
💤 Files with no reviewable changes (1)
  • src/bundler/linker_context/writeOutputFilesToDisk.zig
🧰 Additional context used
📓 Path-based instructions (6)
**/*.zig

📄 CodeRabbit inference engine (.cursor/rules/javascriptcore-class.mdc)

**/*.zig: Declare the extern C symbol in Zig and export a Zig-friendly alias for use
Wrap the Bun____toJS extern in a Zig method that takes a JSGlobalObject and returns JSC.JSValue

Files:

  • src/bundler/LinkerContext.zig
  • src/bake/DevServer/IncrementalGraph.zig
  • src/bundler/linker_context/computeChunks.zig
  • src/bundler/bundle_v2.zig
  • src/bake/DevServer.zig
  • src/bun.js/SavedSourceMap.zig
  • src/bake/DevServer/SourceMapStore.zig
  • src/bun.js/bindings/generated_classes_list.zig
  • src/bundler/LinkerGraph.zig
  • src/js_printer.zig
  • src/bun.js/virtual_machine_exports.zig
  • src/bundler/Chunk.zig
  • src/bundler/linker_context/postProcessJSChunk.zig
  • src/bake/DevServer/PackedMap.zig
  • src/sourcemap/CodeCoverage.zig
  • src/bundler/linker_context/postProcessCSSChunk.zig
  • src/bun.zig
  • src/bun.js/VirtualMachine.zig
  • src/cli/test_command.zig
  • src/StandaloneModuleGraph.zig
  • src/sourcemap/JSSourceMap.zig
src/**/*.zig

📄 CodeRabbit inference engine (CLAUDE.md)

In Zig code, manage memory carefully and use defer for cleanup of allocations/resources

src/**/*.zig: Use the # prefix to declare private fields in Zig structs (e.g., struct { #foo: u32 })
Prefer decl literals when initializing values in Zig (e.g., const decl: Decl = .{ .binding = 0, .value = 0 })
Place @import directives at the bottom of Zig files
Use @import("bun") instead of @import("root").bun

When adding debug logs in Zig, create a scoped logger and log via Bun APIs: const log = bun.Output.scoped(.${SCOPE}, .hidden); then log("...", .{})

Files:

  • src/bundler/LinkerContext.zig
  • src/bake/DevServer/IncrementalGraph.zig
  • src/bundler/linker_context/computeChunks.zig
  • src/bundler/bundle_v2.zig
  • src/bake/DevServer.zig
  • src/bun.js/SavedSourceMap.zig
  • src/bake/DevServer/SourceMapStore.zig
  • src/bun.js/bindings/generated_classes_list.zig
  • src/bundler/LinkerGraph.zig
  • src/js_printer.zig
  • src/bun.js/virtual_machine_exports.zig
  • src/bundler/Chunk.zig
  • src/bundler/linker_context/postProcessJSChunk.zig
  • src/bake/DevServer/PackedMap.zig
  • src/sourcemap/CodeCoverage.zig
  • src/bundler/linker_context/postProcessCSSChunk.zig
  • src/bun.zig
  • src/bun.js/VirtualMachine.zig
  • src/cli/test_command.zig
  • src/StandaloneModuleGraph.zig
  • src/sourcemap/JSSourceMap.zig
src/bun.js/**/*.zig

📄 CodeRabbit inference engine (.cursor/rules/zig-javascriptcore-classes.mdc)

src/bun.js/**/*.zig: In Zig binding structs, expose generated bindings via pub const js = JSC.Codegen.JS and re-export toJS/fromJS/fromJSDirect
Constructors and prototype methods should return bun.JSError!JSC.JSValue to integrate Zig error handling with JS exceptions
Use parameter name globalObject (not ctx) and accept (*JSC.JSGlobalObject, *JSC.CallFrame) in binding methods/constructors
Implement getters as get(this, globalObject) returning JSC.JSValue and matching the .classes.ts interface
Provide deinit() for resource cleanup and finalize() that calls deinit(); use bun.destroy(this) or appropriate destroy pattern
Access JS call data via CallFrame (argument(i), argumentCount(), thisValue()) and throw errors with globalObject.throw(...)
For properties marked cache: true, use the generated Zig accessors (NameSetCached/GetCached) to work with GC-owned values
In finalize() for objects holding JS references, release them using .deref() before destroy

Files:

  • src/bun.js/SavedSourceMap.zig
  • src/bun.js/bindings/generated_classes_list.zig
  • src/bun.js/virtual_machine_exports.zig
  • src/bun.js/VirtualMachine.zig
src/bun.js/bindings/generated_classes_list.zig

📄 CodeRabbit inference engine (.cursor/rules/zig-javascriptcore-classes.mdc)

Update src/bun.js/bindings/generated_classes_list.zig to include new classes

Files:

  • src/bun.js/bindings/generated_classes_list.zig
src/**/js_*.zig

📄 CodeRabbit inference engine (.cursor/rules/registering-bun-modules.mdc)

src/**/js_*.zig: Implement JavaScript bindings in a Zig file named with a js_ prefix (e.g., js_smtp.zig, js_your_feature.zig)
Handle reference counting correctly with ref()/deref() in JS-facing Zig code
Always implement proper cleanup in deinit() and finalize() for JS-exposed types

Files:

  • src/js_printer.zig
src/{**/js_*.zig,bun.js/api/**/*.zig}

📄 CodeRabbit inference engine (.cursor/rules/registering-bun-modules.mdc)

Use bun.JSError!JSValue for proper error propagation in JS-exposed Zig functions

Files:

  • src/js_printer.zig
🧠 Learnings (15)
📓 Common learnings
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/dev/sourcemap.test.ts : sourcemap.test.ts should verify source map correctness in dev
Learnt from: CR
PR: oven-sh/bun#0
File: src/CLAUDE.md:0-0
Timestamp: 2025-10-07T03:19:53.031Z
Learning: Applies to src/**/*.zig : Use import("bun") instead of import("root").bun
📚 Learning: 2025-10-07T03:19:53.031Z
Learnt from: CR
PR: oven-sh/bun#0
File: src/CLAUDE.md:0-0
Timestamp: 2025-10-07T03:19:53.031Z
Learning: Applies to src/**/*.zig : Use import("bun") instead of import("root").bun

Applied to files:

  • src/bake/DevServer/IncrementalGraph.zig
  • src/bundler/bundle_v2.zig
  • src/bake/DevServer.zig
  • src/bun.js/SavedSourceMap.zig
  • src/bun.js/virtual_machine_exports.zig
  • src/bake/DevServer/PackedMap.zig
  • src/bun.zig
  • src/bun.js/VirtualMachine.zig
  • src/StandaloneModuleGraph.zig
📚 Learning: 2025-10-04T09:51:30.294Z
Learnt from: CR
PR: oven-sh/bun#0
File: CLAUDE.md:0-0
Timestamp: 2025-10-04T09:51:30.294Z
Learning: Applies to src/js/bun/** : Organize Bun-specific built-in modules under src/js/bun/ (e.g., bun:ffi, bun:sqlite)

Applied to files:

  • src/bundler/linker_context/computeChunks.zig
  • src/sourcemap/CodeCoverage.zig
  • src/StandaloneModuleGraph.zig
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/**/*.zig : In Zig binding structs, expose generated bindings via pub const js = JSC.Codegen.JS<ClassName> and re-export toJS/fromJS/fromJSDirect

Applied to files:

  • src/bundler/bundle_v2.zig
  • src/bun.js/bindings/generated_classes_list.zig
  • src/bun.js/virtual_machine_exports.zig
  • src/bun.zig
  • src/bun.js/VirtualMachine.zig
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/**/*.zig : Constructors and prototype methods should return bun.JSError!JSC.JSValue to integrate Zig error handling with JS exceptions

Applied to files:

  • src/bundler/bundle_v2.zig
📚 Learning: 2025-08-30T00:11:57.076Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/registering-bun-modules.mdc:0-0
Timestamp: 2025-08-30T00:11:57.076Z
Learning: Applies to src/{**/js_*.zig,bun.js/api/**/*.zig} : Use bun.JSError!JSValue for proper error propagation in JS-exposed Zig functions

Applied to files:

  • src/bundler/bundle_v2.zig
  • src/sourcemap/JSSourceMap.zig
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/dev/sourcemap.test.ts : sourcemap.test.ts should verify source map correctness in dev

Applied to files:

  • src/bake/DevServer.zig
  • src/bun.js/SavedSourceMap.zig
  • src/bake/DevServer/SourceMapStore.zig
  • src/bake/DevServer/PackedMap.zig
📚 Learning: 2025-10-12T02:22:34.373Z
Learnt from: CR
PR: oven-sh/bun#0
File: test/CLAUDE.md:0-0
Timestamp: 2025-10-12T02:22:34.373Z
Learning: Applies to test/{test/**/*.test.{ts,js,jsx,tsx,mjs,cjs},test/js/node/test/{parallel,sequential}/*.js} : When spawning Bun in tests, use `bunExe()` and `bunEnv` from `harness`

Applied to files:

  • src/bake/DevServer.zig
  • src/cli/test_command.zig
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/bindings/generated_classes_list.zig : Update src/bun.js/bindings/generated_classes_list.zig to include new classes

Applied to files:

  • src/bun.js/bindings/generated_classes_list.zig
  • src/bun.js/virtual_machine_exports.zig
  • src/bun.zig
  • src/bun.js/VirtualMachine.zig
📚 Learning: 2025-08-30T00:13:36.815Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/zig-javascriptcore-classes.mdc:0-0
Timestamp: 2025-08-30T00:13:36.815Z
Learning: Applies to src/bun.js/**/*.zig : Use parameter name globalObject (not ctx) and accept (*JSC.JSGlobalObject, *JSC.CallFrame) in binding methods/constructors

Applied to files:

  • src/bun.js/virtual_machine_exports.zig
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/dev/bundle.test.ts : bundle.test.ts should contain DevServer-specific bundling tests

Applied to files:

  • src/bun.js/virtual_machine_exports.zig
📚 Learning: 2025-08-30T00:09:39.100Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/dev-server-tests.mdc:0-0
Timestamp: 2025-08-30T00:09:39.100Z
Learning: Applies to test/bake/{dev/*.test.ts,dev-and-prod.ts} : Import testing utilities (devTest, prodTest, devAndProductionTest, Dev, Client) from test/bake/bake-harness.ts

Applied to files:

  • src/bun.js/virtual_machine_exports.zig
📚 Learning: 2025-10-04T09:51:30.294Z
Learnt from: CR
PR: oven-sh/bun#0
File: CLAUDE.md:0-0
Timestamp: 2025-10-04T09:51:30.294Z
Learning: Applies to test/**/*.test.{ts,tsx} : Use Bun’s Jest-compatible runner (import { test, expect } from "bun:test") for tests

Applied to files:

  • src/cli/test_command.zig
📚 Learning: 2025-08-30T00:12:56.803Z
Learnt from: CR
PR: oven-sh/bun#0
File: .cursor/rules/writing-tests.mdc:0-0
Timestamp: 2025-08-30T00:12:56.803Z
Learning: Applies to test/**/*.{js,ts} : Write tests in JavaScript or TypeScript using Bun’s Jest-style APIs (test, describe, expect) and run with bun test

Applied to files:

  • src/cli/test_command.zig
📚 Learning: 2025-10-12T02:22:34.373Z
Learnt from: CR
PR: oven-sh/bun#0
File: test/CLAUDE.md:0-0
Timestamp: 2025-10-12T02:22:34.373Z
Learning: Applies to test/{test/**/*.test.{ts,js,jsx,tsx,mjs,cjs},test/js/node/test/{parallel,sequential}/*.js} : Import common utilities from `harness` (e.g., `bunExe`, `bunEnv`, `tempDirWithFiles`, platform helpers, GC helpers)

Applied to files:

  • src/cli/test_command.zig
🔇 Additional comments (22)
src/bake/DevServer/SourceMapStore.zig (1)

549-549: LGTM! Namespace update is correct.

The change from bun.sourcemap to bun.SourceMap aligns with the PR objective to standardize the SourceMap API naming. No logic changes.

src/bun.js/virtual_machine_exports.zig (1)

227-228: LGTM! Provider bindings updated correctly.

The BakeSourceProvider and DevServerSourceProvider now correctly reference bun.SourceMap instead of bun.sourcemap, consistent with the namespace migration.

src/bundler/linker_context/postProcessCSSChunk.zig (1)

11-11: LGTM! Type reference updated correctly.

The line_offset variable now uses bun.SourceMap.LineColumnOffset.Optional. The initialization logic remains unchanged.

src/StandaloneModuleGraph.zig (1)

1554-1554: LGTM! Import alias updated correctly.

The SourceMap import now references bun.SourceMap, aligning with the standardized naming convention.

src/bundler/LinkerGraph.zig (1)

461-461: LGTM! Public field type updated correctly.

The line_offset_table field now uses bun.SourceMap.LineOffsetTable.List. The .empty initializer is preserved.

src/bundler/linker_context/postProcessJSChunk.zig (1)

113-113: LGTM! Local variable type updated correctly.

The line_offset variable now references bun.SourceMap.LineColumnOffset.Optional. No changes to initialization logic.

src/sourcemap/CodeCoverage.zig (1)

729-729: LGTM! Import binding updated correctly.

The LineOffsetTable binding now references bun.SourceMap.LineOffsetTable, consistent with the namespace migration throughout the codebase.

src/bundler/bundle_v2.zig (3)

2872-2873: SourceMapPieces namespace migration looks correct

Initialization now uses SourceMap.SourceMapPieces with this.allocator(). Matches prior behavior; no issues spotted.

Also applies to: 2891-2892, 2904-2905


4319-4328: sourceMapChunk return type updated to SourceMap.Chunk

Signature and switch use align with the new API; r2.source_map must be SourceMap.Chunk-compatible. LGTM.

Please ensure js_printer.PrintResult.source_map is now SourceMap.Chunk.


4338-4341: CompileResultForSourceMap fields updated to SourceMap types

Types now use SourceMap.Chunk and SourceMap.LineColumnOffset. Looks correct.

src/sourcemap/JSSourceMap.zig (5)

5-5: Switch to bun.SourceMap.ParsedSourceMap

Pointer type updated; deinit still calls deref(). Ownership and lifetime remain consistent. LGTM.


139-146: Updated Mapping.parse call — verify new signature and options

The parse now passes sources_count and maxInt(i32) with options { allow_names = true, sort = true }. This seems right for Node-compatible mapping lookups.

Please confirm the parameter order matches bun.SourceMap.Mapping.parse and that sorting is desired here (affects binary search). Also ensure errors still map to SyntaxError as before.


159-162: Construct ParsedSourceMap with parsed mapping list

Using bun.new(bun.SourceMap.ParsedSourceMap, mapping_list) is consistent; names/sources arrays are retained on this instance and freed in deinit(). LGTM.


203-216: mappingNameToJS now accepts bun.SourceMap.Mapping

Type change aligns with new API. Fallback to this.names preserved. Looks good.


218-225: sourceNameToJS now accepts bun.SourceMap.Mapping

Bounds check against this.sources.len remains intact. No issues.

src/cli/test_command.zig (7)

963-963: Collect byte ranges using bun.SourceMap.coverage.ByteRangeMapping

Type migration looks correct; capacity prealloc uses map.count(). LGTM.


973-977: Update sort comparator to SourceMap coverage type

Comparator and element type updated consistently. LGTM.


986-989: printCodeCoverage signature updated

Parameter now takes []bun.SourceMap.coverage.ByteRangeMapping. Matches callers. LGTM.


1056-1060: Average coverage Fraction type migrated

Initialization uses bun.SourceMap.coverage.Fraction. Looks fine.

Confirm Fraction still includes the .failing field, as it’s later set on opts.fractions.


1187-1192: Fallback ‘failed’ Fraction type migrated

Using bun.SourceMap.coverage.Fraction for zero-file case. LGTM.


2006-2008: Introduce local aliases for coverage and CodeCoverageReport

Good cleanup; reduces verbosity across the module.


1695-1771: Exit-code logic includes low coverage; ensure Fraction.failing semantics unchanged

The exit condition uses coverage_options.fractions.failing. Verify the new Fraction sets this consistently when thresholds are not met.

Comment thread src/bundler/bundle_v2.zig Resolved
Comment thread src/bundler/bundle_v2.zig Resolved
@nektro
nektro requested a review from cirospaciari October 14, 2025 22:49
@nektro
nektro merged commit 1e849b9 into main Oct 27, 2025
@nektro
nektro deleted the nektro-patch-15495 branch October 27, 2025 19:26
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.

3 participants