()
| 83 | } |
| 84 | |
| 85 | toJSON(): SourceMap | null { |
| 86 | if (!this.hasMappings) { |
| 87 | return null; |
| 88 | } |
| 89 | |
| 90 | const sourcesIndex = new Map<string, number>(); |
| 91 | const sources: string[] = []; |
| 92 | const sourcesContent: (string | null)[] = []; |
| 93 | |
| 94 | Array.from(this.sourcesContent.keys()).forEach((url: string, i: number) => { |
| 95 | sourcesIndex.set(url, i); |
| 96 | sources.push(url); |
| 97 | sourcesContent.push(this.sourcesContent.get(url) || null); |
| 98 | }); |
| 99 | |
| 100 | let mappings: string = ''; |
| 101 | let lastCol0: number = 0; |
| 102 | let lastSourceIndex: number = 0; |
| 103 | let lastSourceLine0: number = 0; |
| 104 | let lastSourceCol0: number = 0; |
| 105 | |
| 106 | this.lines.forEach((segments) => { |
| 107 | lastCol0 = 0; |
| 108 | |
| 109 | mappings += segments |
| 110 | .map((segment) => { |
| 111 | // zero-based starting column of the line in the generated code |
| 112 | let segAsStr = toBase64VLQ(segment.col0 - lastCol0); |
| 113 | lastCol0 = segment.col0; |
| 114 | |
| 115 | if (segment.sourceUrl != null) { |
| 116 | // zero-based index into the “sources” list |
| 117 | segAsStr += toBase64VLQ(sourcesIndex.get(segment.sourceUrl)! - lastSourceIndex); |
| 118 | lastSourceIndex = sourcesIndex.get(segment.sourceUrl)!; |
| 119 | // the zero-based starting line in the original source |
| 120 | segAsStr += toBase64VLQ(segment.sourceLine0! - lastSourceLine0); |
| 121 | lastSourceLine0 = segment.sourceLine0!; |
| 122 | // the zero-based starting column in the original source |
| 123 | segAsStr += toBase64VLQ(segment.sourceCol0! - lastSourceCol0); |
| 124 | lastSourceCol0 = segment.sourceCol0!; |
| 125 | } |
| 126 | |
| 127 | return segAsStr; |
| 128 | }) |
| 129 | .join(','); |
| 130 | mappings += ';'; |
| 131 | }); |
| 132 | |
| 133 | mappings = mappings.slice(0, -1); |
| 134 | |
| 135 | return { |
| 136 | 'file': this.file || '', |
| 137 | 'version': VERSION, |
| 138 | 'sourceRoot': '', |
| 139 | 'sources': sources, |
| 140 | 'sourcesContent': sourcesContent, |
| 141 | 'mappings': mappings, |
| 142 | }; |
no test coverage detected