MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / Mappings

Class Mappings

benchmark/data.js:213–270  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

211 };
212}
213class Mappings {
214 constructor(hires) {
215 this.hires = hires;
216 this.generatedCodeLine = 0;
217 this.generatedCodeColumn = 0;
218 this.raw = [];
219 this.rawSegments = this.raw[this.generatedCodeLine] = [];
220 this.pending = null;
221 }
222 addEdit(sourceIndex, content, loc, nameIndex) {
223 if (content.length) {
224 const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
225 if (nameIndex >= 0) {
226 segment.push(nameIndex);
227 }
228 this.rawSegments.push(segment);
229 } else if (this.pending) {
230 this.rawSegments.push(this.pending);
231 }
232 this.advance(content);
233 this.pending = null;
234 }
235 addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
236 let originalCharIndex = chunk.start;
237 let first = true;
238 while (originalCharIndex < chunk.end) {
239 if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
240 this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
241 }
242 if (original[originalCharIndex] === '\n') {
243 loc.line += 1;
244 loc.column = 0;
245 this.generatedCodeLine += 1;
246 this.raw[this.generatedCodeLine] = this.rawSegments = [];
247 this.generatedCodeColumn = 0;
248 first = true;
249 } else {
250 loc.column += 1;
251 this.generatedCodeColumn += 1;
252 first = false;
253 }
254 originalCharIndex += 1;
255 }
256 this.pending = null;
257 }
258 advance(str) {
259 if (!str) return;
260 const lines = str.split('\n');
261 if (lines.length > 1) {
262 for (let i = 0; i < lines.length - 1; i++) {
263 this.generatedCodeLine++;
264 this.raw[this.generatedCodeLine] = this.rawSegments = [];
265 }
266 this.generatedCodeColumn = 0;
267 }
268 this.generatedCodeColumn += lines[lines.length - 1].length;
269 }
270}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected