( emitted: EmittedMap, precompiled: EmittedMap | undefined, source: string )
| 603 | } |
| 604 | |
| 605 | export const mapToSource = ( |
| 606 | emitted: EmittedMap, |
| 607 | precompiled: EmittedMap | undefined, |
| 608 | source: string |
| 609 | ): EmittedMap => { |
| 610 | if (!precompiled) return emitted |
| 611 | const lines = decode(precompiled.mappings) |
| 612 | const mappings: SourceMapMappings = decode(emitted.mappings).map(line => |
| 613 | line.flatMap((segment): SourceMapSegment[] => { |
| 614 | if (segment.length === 1) return [segment] |
| 615 | const [column, sourceIndex, sourceLine, sourceColumn] = segment |
| 616 | const original = segmentAt(lines[sourceLine], sourceColumn) |
| 617 | // what the precompiler wrote maps to no line of the source |
| 618 | if (!original) return [] |
| 619 | const traced: SourceMapSegment = [ |
| 620 | column, |
| 621 | sourceIndex, |
| 622 | original[2], |
| 623 | original[3] + sourceColumn - original[0] |
| 624 | ] |
| 625 | return [segment.length === 5 ? [...traced, segment[4]] : traced] |
| 626 | }) |
| 627 | ) |
| 628 | return { |
| 629 | ...emitted, |
| 630 | mappings: encode(mappings), |
| 631 | ...(emitted.sourcesContent && { sourcesContent: [source] }) |
| 632 | } |
| 633 | } |
| 634 | |
| 635 | // the last segment starting at or before the column, sorted by column |
| 636 | const segmentAt = ( |
no test coverage detected