aboutsummaryrefslogtreecommitdiff
path: root/src/sourcemap
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-23 22:22:55 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-08-23 22:22:55 -0700
commitad326b77342dd3d8585a30b7da803d32f9c11fe2 (patch)
treefda755bf32e4361eebbf4228994204ae031cae80 /src/sourcemap
parentaa08c35c062d0db004b9aaedcd8d427eda8aa7c7 (diff)
downloadbun-ad326b77342dd3d8585a30b7da803d32f9c11fe2.tar.gz
bun-ad326b77342dd3d8585a30b7da803d32f9c11fe2.tar.zst
bun-ad326b77342dd3d8585a30b7da803d32f9c11fe2.zip
[Inspector] Fix bug with sourcemaps including internal metadata bytes
Diffstat (limited to 'src/sourcemap')
-rw-r--r--src/sourcemap/sourcemap.zig22
1 files changed, 20 insertions, 2 deletions
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;