refactor(javascript): reuse validated source-map decoding
Pass typed map objects into the codec and reuse validated TraceMap instances for regular and indexed lookups. Remove whole-map serialization, duplicate leaf decoding, an array-copy wrapper, and the unused offset-validation mode in artifact declaration collection. Validation: source-map and browser consumer suites (126 tests), declaration tests, and artifact reconstruction boundaries pass. Section overlap checks and raw source declarations remain intact.
This commit is contained in:
1 parent
c42232f566
commit
f64790bfc3
6 files changed
+61
-78
No files matched your search
@@ -34,7 +34,6 @@ export const traceSourceMap = (
|
||||
position: WebSourcePosition,
|
||||
): WebSourceMapReport => {
|
||||
const inspected = inspectSourceMap(text);
|
||||
const map = new AnyMap(inspected.jsonText, url);
|
||||
const decodedLeaves = decodeValidatedSourceMapLeaves(inspected.leaves, url);
|
||||
for (const { leaf, rows } of decodedLeaves)
|
||||
for (const [line, row] of rows.entries())
|
||||
@@ -44,6 +43,27 @@ export const traceSourceMap = (
|
||||
"format",
|
||||
"Embedded source-map mappings overlap the following section boundary.",
|
||||
);
|
||||
let map: TraceMap;
|
||||
if (inspected.format === "regular") {
|
||||
const decoded = decodedLeaves[0];
|
||||
if (decoded === undefined)
|
||||
throw new SourceMapFormatFailure(
|
||||
"format",
|
||||
"Regular source map has no validated leaf.",
|
||||
);
|
||||
map = decoded.map;
|
||||
} else {
|
||||
map = new AnyMap(
|
||||
{
|
||||
version: 3,
|
||||
sections: decodedLeaves.map(({ leaf, map: sectionMap }) => ({
|
||||
offset: leaf.offset,
|
||||
map: sectionMap,
|
||||
})),
|
||||
},
|
||||
url,
|
||||
);
|
||||
}
|
||||
const rows =
|
||||
inspected.format === "regular"
|
||||
? (decodedLeaves[0]?.rows ?? [])
|
||||
|
||||
Reference in new issue
Block a user