aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/bun.js/javascript.zig8
-rw-r--r--src/sourcemap/sourcemap.zig22
2 files changed, 25 insertions, 5 deletions
diff --git a/src/bun.js/javascript.zig b/src/bun.js/javascript.zig
index 492b9fbee..062bd52a2 100644
--- a/src/bun.js/javascript.zig
+++ b/src/bun.js/javascript.zig
@@ -113,6 +113,8 @@ const ParsedSourceMap = SourceMap.Mapping.ParsedSourceMap;
const MappingList = SourceMap.Mapping.List;
pub const SavedSourceMap = struct {
+ pub const vlq_offset = 24;
+
// For bun.js, we store the number of mappings and how many bytes the final list is at the beginning of the array
// The first 8 bytes are the length of the array
// The second 8 bytes are the number of mappings
@@ -120,7 +122,7 @@ pub const SavedSourceMap = struct {
data: [*]u8,
pub fn vlq(this: SavedMappings) []u8 {
- return this.data[24..this.len()];
+ return this.data[vlq_offset..this.len()];
}
pub inline fn len(this: SavedMappings) usize {
@@ -134,7 +136,7 @@ pub const SavedSourceMap = struct {
pub fn toMapping(this: SavedMappings, allocator: Allocator, path: string) anyerror!ParsedSourceMap {
const result = SourceMap.Mapping.parse(
allocator,
- this.data[24..this.len()],
+ this.data[vlq_offset..this.len()],
@as(usize, @bitCast(this.data[8..16].*)),
1,
@as(usize, @bitCast(this.data[16..24].*)),
@@ -527,7 +529,7 @@ pub const VirtualMachine = struct {
pub fn onChunk(this: *SourceMapHandlerGetter, chunk: SourceMap.Chunk, source: logger.Source) anyerror!void {
var temp_json_buffer = bun.MutableString.initEmpty(bun.default_allocator);
defer temp_json_buffer.deinit();
- temp_json_buffer = try chunk.printSourceMapContents(source, temp_json_buffer, true, true);
+ temp_json_buffer = try chunk.printSourceMapContentsAtOffset(source, temp_json_buffer, true, SavedSourceMap.vlq_offset, true);
const source_map_url_prefix_start = "//# sourceMappingURL=data:application/json;base64,";
// TODO: do we need to %-encode the path?
const source_url_len = source.path.text.len;
diff --git a/src/sourcemap/sourcemap.zig b/src/sourcemap/sourcemap.zig
index 0bcb4021d..411e8523d 100644
--- a/src/sourcemap/sourcemap.zig
+++ b/src/sourcemap/sourcemap.zig
@@ -1122,6 +1122,24 @@ pub const Chunk = struct {
include_sources_contents: bool,
comptime ascii_only: bool,
) !MutableString {
+ return printSourceMapContentsAtOffset(
+ chunk,
+ source,
+ mutable,
+ include_sources_contents,
+ 0,
+ ascii_only,
+ );
+ }
+
+ pub fn printSourceMapContentsAtOffset(
+ chunk: Chunk,
+ source: Logger.Source,
+ mutable: MutableString,
+ include_sources_contents: bool,
+ offset: usize,
+ comptime ascii_only: bool,
+ ) !MutableString {
var output = mutable;
// attempt to pre-allocate
@@ -1137,7 +1155,7 @@ pub const Chunk = struct {
}
output.growIfNeeded(
- filename.len + 2 + (source.contents.len * @as(usize, @intFromBool(include_sources_contents))) + chunk.buffer.list.items.len + 32 + 39 + 29 + 22 + 20,
+ filename.len + 2 + (source.contents.len * @as(usize, @intFromBool(include_sources_contents))) + (chunk.buffer.list.items.len - offset) + 32 + 39 + 29 + 22 + 20,
) catch unreachable;
try output.append("{\n \"version\":3,\n \"sources\": [");
@@ -1149,7 +1167,7 @@ pub const Chunk = struct {
}
try output.append("],\n \"mappings\": ");
- output = try JSPrinter.quoteForJSON(chunk.buffer.list.items, output, ascii_only);
+ output = try JSPrinter.quoteForJSON(chunk.buffer.list.items[offset..], output, ascii_only);
try output.append(", \"names\": []\n}");
return output;