MCPcopy Index your code
hub / github.com/angular/angular / toJSON

Method toJSON

packages/compiler/src/output/source_map.ts:85–143  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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 };

Callers 4

expectMapFunction · 0.45
nbSegmentsPerLineFunction · 0.45
source_map_spec.tsFile · 0.45

Calls 8

toBase64VLQFunction · 0.85
mapMethod · 0.80
keysMethod · 0.65
setMethod · 0.65
getMethod · 0.65
joinMethod · 0.65
forEachMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected