Repository navigation
zig: bun.sourcemap -> bun.SourceMap - #23477
Conversation
|
Updated 11:13 AM PT - Oct 14th, 2025
❌ @nektro, your commit 48352de has 2 failures in
🧪 To try this PR locally: bunx bun-pr 23477That installs a local version of the PR into your bun-23477 --bun |
This comment was marked as duplicate.
This comment was marked as duplicate.
There was a problem hiding this comment.
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 coverageEarly 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.
📒 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.zigsrc/bake/DevServer/IncrementalGraph.zigsrc/bundler/linker_context/computeChunks.zigsrc/bundler/bundle_v2.zigsrc/bake/DevServer.zigsrc/bun.js/SavedSourceMap.zigsrc/bake/DevServer/SourceMapStore.zigsrc/bun.js/bindings/generated_classes_list.zigsrc/bundler/LinkerGraph.zigsrc/js_printer.zigsrc/bun.js/virtual_machine_exports.zigsrc/bundler/Chunk.zigsrc/bundler/linker_context/postProcessJSChunk.zigsrc/bake/DevServer/PackedMap.zigsrc/sourcemap/CodeCoverage.zigsrc/bundler/linker_context/postProcessCSSChunk.zigsrc/bun.zigsrc/bun.js/VirtualMachine.zigsrc/cli/test_command.zigsrc/StandaloneModuleGraph.zigsrc/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").bunWhen adding debug logs in Zig, create a scoped logger and log via Bun APIs:
const log = bun.Output.scoped(.${SCOPE}, .hidden);thenlog("...", .{})
Files:
src/bundler/LinkerContext.zigsrc/bake/DevServer/IncrementalGraph.zigsrc/bundler/linker_context/computeChunks.zigsrc/bundler/bundle_v2.zigsrc/bake/DevServer.zigsrc/bun.js/SavedSourceMap.zigsrc/bake/DevServer/SourceMapStore.zigsrc/bun.js/bindings/generated_classes_list.zigsrc/bundler/LinkerGraph.zigsrc/js_printer.zigsrc/bun.js/virtual_machine_exports.zigsrc/bundler/Chunk.zigsrc/bundler/linker_context/postProcessJSChunk.zigsrc/bake/DevServer/PackedMap.zigsrc/sourcemap/CodeCoverage.zigsrc/bundler/linker_context/postProcessCSSChunk.zigsrc/bun.zigsrc/bun.js/VirtualMachine.zigsrc/cli/test_command.zigsrc/StandaloneModuleGraph.zigsrc/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.zigsrc/bun.js/bindings/generated_classes_list.zigsrc/bun.js/virtual_machine_exports.zigsrc/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.zigsrc/bundler/bundle_v2.zigsrc/bake/DevServer.zigsrc/bun.js/SavedSourceMap.zigsrc/bun.js/virtual_machine_exports.zigsrc/bake/DevServer/PackedMap.zigsrc/bun.zigsrc/bun.js/VirtualMachine.zigsrc/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.zigsrc/sourcemap/CodeCoverage.zigsrc/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.zigsrc/bun.js/bindings/generated_classes_list.zigsrc/bun.js/virtual_machine_exports.zigsrc/bun.zigsrc/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.zigsrc/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.zigsrc/bun.js/SavedSourceMap.zigsrc/bake/DevServer/SourceMapStore.zigsrc/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.zigsrc/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.zigsrc/bun.js/virtual_machine_exports.zigsrc/bun.zigsrc/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.sourcemaptobun.SourceMapaligns 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.SourceMapinstead ofbun.sourcemap, consistent with the namespace migration.src/bundler/linker_context/postProcessCSSChunk.zig (1)
11-11: LGTM! Type reference updated correctly.The
line_offsetvariable now usesbun.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_tablefield now usesbun.SourceMap.LineOffsetTable.List. The.emptyinitializer is preserved.src/bundler/linker_context/postProcessJSChunk.zig (1)
113-113: LGTM! Local variable type updated correctly.The
line_offsetvariable now referencesbun.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 correctInitialization 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.ChunkSignature 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 typesTypes now use SourceMap.Chunk and SourceMap.LineColumnOffset. Looks correct.
src/sourcemap/JSSourceMap.zig (5)
5-5: Switch to bun.SourceMap.ParsedSourceMapPointer type updated; deinit still calls deref(). Ownership and lifetime remain consistent. LGTM.
139-146: Updated Mapping.parse call — verify new signature and optionsThe 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 listUsing 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.MappingType change aligns with new API. Fallback to
this.namespreserved. Looks good.
218-225: sourceNameToJS now accepts bun.SourceMap.MappingBounds check against
this.sources.lenremains intact. No issues.src/cli/test_command.zig (7)
963-963: Collect byte ranges using bun.SourceMap.coverage.ByteRangeMappingType migration looks correct; capacity prealloc uses map.count(). LGTM.
973-977: Update sort comparator to SourceMap coverage typeComparator and element type updated consistently. LGTM.
986-989: printCodeCoverage signature updatedParameter now takes []bun.SourceMap.coverage.ByteRangeMapping. Matches callers. LGTM.
1056-1060: Average coverage Fraction type migratedInitialization uses bun.SourceMap.coverage.Fraction. Looks fine.
Confirm Fraction still includes the
.failingfield, as it’s later set onopts.fractions.
1187-1192: Fallback ‘failed’ Fraction type migratedUsing bun.SourceMap.coverage.Fraction for zero-file case. LGTM.
2006-2008: Introduce local aliases for coverage and CodeCoverageReportGood cleanup; reduces verbosity across the module.
1695-1771: Exit-code logic includes low coverage; ensure Fraction.failing semantics unchangedThe exit condition uses
coverage_options.fractions.failing. Verify the new Fraction sets this consistently when thresholds are not met.
addresses a TODO