fix(ngcc): handle mappings outside the content when flattening source-maps (#35718)
Previously when rendering flattened source-maps, it was assumed that no mapping would come from a line that is outside the lines of the actual source content. It turns out this is not a valid assumption. Now the code that renders flattened source-maps will handle such mappings, with the additional benefit that the rendered source-map will only contain mapping lines up to the last mapping, rather than a mapping line for every content line. Fixes #35709 PR Close #35718
This commit is contained in:

committed by
Matias Niemelä

parent
72c4fda613
commit
73cf7d5cb4
@ -49,11 +49,9 @@ export class SourceFile {
|
||||
const sources: SourceFile[] = [];
|
||||
const names: string[] = [];
|
||||
|
||||
// Ensure a mapping line array for each line in the generated source.
|
||||
const mappings: SourceMapMappings = this.lineLengths.map(() => []);
|
||||
const mappings: SourceMapMappings = [];
|
||||
|
||||
for (const mapping of this.flattenedMappings) {
|
||||
const mappingLine = mappings[mapping.generatedSegment.line];
|
||||
const sourceIndex = findIndexOrAdd(sources, mapping.originalSource);
|
||||
const mappingArray: SourceMapSegment = [
|
||||
mapping.generatedSegment.column,
|
||||
@ -65,7 +63,14 @@ export class SourceFile {
|
||||
const nameIndex = findIndexOrAdd(names, mapping.name);
|
||||
mappingArray.push(nameIndex);
|
||||
}
|
||||
mappingLine.push(mappingArray);
|
||||
|
||||
// Ensure a mapping line array for this mapping.
|
||||
const line = mapping.generatedSegment.line;
|
||||
while (line >= mappings.length) {
|
||||
mappings.push([]);
|
||||
}
|
||||
// Add this mapping to the line
|
||||
mappings[line].push(mappingArray);
|
||||
}
|
||||
|
||||
const sourcePathDir = dirname(this.sourcePath);
|
||||
|
Reference in New Issue
Block a user