Parses the compact mappings string from a source-map V3 object into a per-line
array of segments, sorted by generatedCol (esbuild always emits them in order).
Extracts and decodes the inline source map that esbuild appends to a bundle as
//# sourceMappingURL=data:application/json;base64,….
Returns null when no inline map is present or parsing fails.
Returns true when url points to a test bundle (/tests.js or /filtered-tests.js) served by the local HTTP server.
| null
Returns the original source position for a generated (line, col) pair.
Both coordinates are 1-based (the format Chrome uses in Error.stack).
Returns null when the position cannot be mapped.
Parses a source-map V3 JSON string into a SourceMapDecoder ready for position lookup.
Parses the trailing URL:LINE:COL suffix of a stack frame. The greedy (.+) group
captures URLs that contain colons (e.g. http://host:PORT/path); the regex anchors
mean the last two :digits sequences are always the line/col.
Reads one VLQ-encoded integer from text starting at position.
Returns [decodedValue, positionAfterLastConsumedChar].
| null
Attempts to resolve a single stack-frame line to its original source location.
Handles Chrome named (at FUNC (URL:L:C)), Chrome anonymous (at [async] URL:L:C),
and Firefox/WebKit (FUNC@URL:L:C) formats.
Resolves every frame in stack that references a test bundle to its original source.
Resolves the absolute path of the source at sourceIndex in the map's sources array,
applying the same sourceRoot + outDir rules as position lookups. Returns null when
the index is out of range or the entry is empty. Used by the coverage collector to key
accumulated line coverage by absolute source path.
One decoded mapping entry. All coordinates are 0-based.
-
generatedCol: number
0-based column in the generated (bundle) file.
-
sourceCol: number
0-based column in the original source file.
-
sourceIndex: number
Index into the source map's
sourcesarray. -
sourceLine: number
0-based line in the original source file.
Parsed representation of a source-map V3 JSON, ready for position lookup.
-
outDir: string
Absolute directory of the bundle file, used to resolve relative source paths.
-
segmentsByLine: Segment[][]
Decoded segments indexed by 0-based generated line number.
-
sourceRoot: string
Source-root prefix from the map JSON (usually
""for esbuild output). -
sources: string[]
Raw source paths from the map (may be relative to
outDir). -
sourcesContent: (string | null)[]
Original source texts verbatim from the map JSON; one entry per
sourceselement.
Usage
import * as mod from "lib/utils/source-map.ts";