MCPcopy
hub / github.com/mozilla/source-map / _serializeMappings

Method _serializeMappings

lib/source-map-generator.js:322–387  ·  view source on GitHub ↗

* Serialize the accumulated mappings in to the stream of base 64 VLQs * specified by the source map format.

()

Source from the content-addressed store, hash-verified

320 * specified by the source map format.
321 */
322 _serializeMappings() {
323 let previousGeneratedColumn = 0;
324 let previousGeneratedLine = 1;
325 let previousOriginalColumn = 0;
326 let previousOriginalLine = 0;
327 let previousName = 0;
328 let previousSource = 0;
329 let result = "";
330 let next;
331 let mapping;
332 let nameIdx;
333 let sourceIdx;
334
335 const mappings = this._mappings.toArray();
336 for (let i = 0, len = mappings.length; i < len; i++) {
337 mapping = mappings[i];
338 next = "";
339
340 if (mapping.generatedLine !== previousGeneratedLine) {
341 previousGeneratedColumn = 0;
342 while (mapping.generatedLine !== previousGeneratedLine) {
343 next += ";";
344 previousGeneratedLine++;
345 }
346 } else if (i > 0) {
347 if (
348 !util.compareByGeneratedPositionsInflated(mapping, mappings[i - 1])
349 ) {
350 continue;
351 }
352 next += ",";
353 }
354
355 next += base64VLQ.encode(
356 mapping.generatedColumn - previousGeneratedColumn
357 );
358 previousGeneratedColumn = mapping.generatedColumn;
359
360 if (mapping.source != null) {
361 sourceIdx = this._sources.indexOf(mapping.source);
362 next += base64VLQ.encode(sourceIdx - previousSource);
363 previousSource = sourceIdx;
364
365 // lines are stored 0-based in SourceMap spec version 3
366 next += base64VLQ.encode(
367 mapping.originalLine - 1 - previousOriginalLine
368 );
369 previousOriginalLine = mapping.originalLine - 1;
370
371 next += base64VLQ.encode(
372 mapping.originalColumn - previousOriginalColumn
373 );
374 previousOriginalColumn = mapping.originalColumn;
375
376 if (mapping.name != null) {
377 nameIdx = this._names.indexOf(mapping.name);
378 next += base64VLQ.encode(nameIdx - previousName);
379 previousName = nameIdx;

Callers 1

toJSONMethod · 0.95

Calls 2

indexOfMethod · 0.80
toArrayMethod · 0.45

Tested by

no test coverage detected