How to use the source-map.SourceMapConsumer.GENERATED_ORDER function in source-map

To help you get started, we’ve selected a few source-map examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github webpack / webpack-sources / lib / applySourceMap.js View on Github external
var middleSourceContents = {};

	var m2rMappingsByLine = {};

	var rightSourceContentsSet = {};
	var rightSourceContentsLines = {};

	// Store all mappings by generated line
	sourceMapConsumer.eachMapping(
		function(mapping) {
			(m2rMappingsByLine[mapping.generatedLine] =
				m2rMappingsByLine[mapping.generatedLine] || []).push(mapping);
		},
		null,
		SourceMapConsumer.GENERATED_ORDER
	);

	// Store all source contents
	sourceNode.walkSourceContents(function(source, content) {
		middleSourceContents["$" + source] = content;
	});

	var middleSource = middleSourceContents["$" + sourceFile];
	var middleSourceLines = middleSource ? middleSource.split("\n") : undefined;

	// Walk all left to middle mappings
	sourceNode.walk(function(chunk, middleMapping) {
		var source;

		// Find a mapping from middle to right
		if(
github microsoft / rushstack / apps / api-extractor / src / collector / SourceMapper.ts View on Github external
const sourceMapConsumer: SourceMapConsumer = new SourceMapConsumer(rawSourceMap);
          const mappingItems: MappingItem[] = [];

          // Extract the list of mapping items
          sourceMapConsumer.eachMapping(
            (mappingItem: MappingItem) => {
              mappingItems.push({
                ...mappingItem,
                // The "source-map" package inexplicably uses 1-based line numbers but 0-based column numbers.
                // Fix that up proactively so we don't have to deal with it later.
                generatedColumn: mappingItem.generatedColumn + 1,
                originalColumn: mappingItem.originalColumn + 1
              });
            },
            this,
            SourceMapConsumer.GENERATED_ORDER
          );

          sourceMap = { sourceMapConsumer, mappingItems};
        } else {
          // No source map for this filename
          sourceMap = null; // eslint-disable-line no-restricted-syntax
        }

        this._sourceMapByFilePath.set(normalizedPath, sourceMap);
        if (options.sourceFilePath !== normalizedPath) {
          // Add both keys to the map
          this._sourceMapByFilePath.set(options.sourceFilePath, sourceMap);
        }
      }
    }
github theintern / intern / src / lib / node / ErrorFormatter.ts View on Github external
if (originalPosition.line != null) {
      return originalPosition;
    }

    const entries: MappingItem[] = [];

    // find all map entries that apply to the given line in the generated
    // output
    map.eachMapping(
      entry => {
        if (entry.generatedLine === line) {
          entries.push(entry);
        }
      },
      null,
      SourceMapConsumer.GENERATED_ORDER
    );

    if (entries.length === 0) {
      // no valid mappings exist -- return the line and column arguments
      return { line: line, column: column };
    }

    let position = entries[0];

    // Chrome/Node.js column is at the start of the term that generated the
    // exception IE column is at the beginning of the expression/line with
    // the exceptional term
    //
    // Safari column number is just after the exceptional term
    //   - need to go back one element in the mapping
    //
github firefox-devtools / debugger / packages / devtools-source-map / src / source-map.js View on Github external
// one to it to get the exclusive end position.
            column: mapping.lastGeneratedColumn + 1
          }
        });
      } else if (
        typeof mapping.source === "string" &&
        currentGroup.length > 0
      ) {
        // If there is a URL, but it is for a _different_ file, we create a
        // new group of mappings so that we can tell
        currentGroup = [];
        originalGroups.push(currentGroup);
      }
    },
    null,
    SourceMapConsumer.GENERATED_ORDER
  );

  const generatedMappingsForOriginal = [];
  if (mergeUnmappedRegions) {
    // If we don't care about excluding unmapped regions, then we just need to
    // create a range that is the fully encompasses each group, ignoring the
    // empty space between each individual range.
    for (const group of originalGroups) {
      if (group.length > 0) {
        generatedMappingsForOriginal.push({
          start: group[0].start,
          end: group[group.length - 1].end
        });
      }
    }
  } else {
github microsoft / vscode-nls-dev / src / lib.ts View on Github external
if (contents.length > 0) {
			this.lines.push({ content: contents.substring(index, contents.length), ending: '', mappings: null });
		}
		if (rawSourceMap) {
			let sourceMapConsumer = new SourceMapConsumer(rawSourceMap);
			sourceMapConsumer.eachMapping((mapping) => {
				// Note that the generatedLine index is one based;
				let line = this.lines[mapping.generatedLine - 1];
				if (line) {
					if (!line.mappings) {
						line.mappings = [];
					}
					line.mappings.push(mapping);
				}
			}, null, SourceMapConsumer.GENERATED_ORDER);
		}
	}
github firefox-devtools / vscode-firefox-debug / src / adapter / firefox / sourceMaps / info.ts View on Github external
public eachMapping(callback: (mapping: MappingItem) => void): void {
		if (this.sourceMapConsumer) {
			this.sourceMapConsumer.eachMapping(mappingItem => {
				const lastGeneratedColumn = (mappingItem.lastGeneratedColumn !== undefined) ? (mappingItem.lastGeneratedColumn || mappingItem.generatedColumn) : undefined;
				callback({
					...mappingItem,
					originalColumn: mappingItem.originalColumn,
					generatedColumn: mappingItem.generatedColumn,
					lastGeneratedColumn
				});
			}, undefined, SourceMapConsumer.GENERATED_ORDER);
		}
	}