How to use the source-map.SourceMapConsumer.LEAST_UPPER_BOUND 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 SitePen / remap-istanbul / lib / getMapping.js View on Github external
return null;
	}
	/* istanbul ignore if: edge case too hard to test for */
	if (start.line === null || start.column === null) {
		return null;
	}
	/* istanbul ignore if: edge case too hard to test for */
	if (end.line === null || end.column === null) {
		return null;
	}

	if (start.line === end.line && start.column === end.column) {
		end = sourceMap.originalPositionFor({
			line: location.end.line,
			column: location.end.column,
			bias: SourceMapConsumer.LEAST_UPPER_BOUND,
		});
		end.column -= 1;
	}

	return {
		source: start.source,
		loc: {
			start: {
				line: start.line,
				column: start.column,
			},
			end: {
				line: end.line,
				column: end.column,
			},
			skip: location.skip,
github firefox-devtools / debugger / packages / devtools-source-map / src / source-map.js View on Github external
// generated location in the file when there were multiple generated
  // locations. The current comparison fn in 0.7 does not appear to take
  // generated location into account properly.
  let match;
  for (const pos of positions) {
    if (!match || pos.line < match.line || pos.column < match.column) {
      match = pos;
    }
  }

  if (!match) {
    match = map.generatedPositionFor({
      source: originalSource.url,
      line: location.line,
      column: location.column == null ? 0 : location.column,
      bias: SourceMapConsumer.LEAST_UPPER_BOUND
    });
  }

  return {
    sourceId: generatedSourceId,
    line: match.line,
    column: match.column
  };
}
github linkedin / css-blocks / packages / @css-blocks / core / src / SourceLocation.ts View on Github external
function pickBestSourceRange(configuration: Configuration, filename: string, source: string, consumer: ReturnType , start: SourcePosition, end: SourcePosition): MappedSourceRange | SourceRange {
  let generated = { filename, start, end, source };
  // Fun fact! The positions returned by the source map consumer use a 1-based
  // index for lines, and a 0-based index for columns.
  let startOrigin: NullableMappedPosition = consumer.originalPositionFor({ line: start.line, column: start.column - 1, bias: SourceMapConsumer.LEAST_UPPER_BOUND});
  let endOrigin: NullableMappedPosition = consumer.originalPositionFor({ line: end.line, column: end.column - 1, bias: SourceMapConsumer.LEAST_UPPER_BOUND});
  // If the start and end locations of the origins are in different files,
  // we try different biases to see if we can get something that agrees.
  if (startOrigin.source && startOrigin.source !== endOrigin.source) {
    let startOrigin2: NullableMappedPosition = consumer.originalPositionFor({ line: start.line, column: start.column - 1, bias: SourceMapConsumer.GREATEST_LOWER_BOUND });
    let endOrigin2: NullableMappedPosition = consumer.originalPositionFor({ line: end.line, column: end.column - 1, bias: SourceMapConsumer.GREATEST_LOWER_BOUND });
    if (startOrigin2.source && startOrigin2.source === endOrigin.source) {
      startOrigin = startOrigin2;
    } else if (endOrigin2.source && startOrigin.source === endOrigin2.source) {
      endOrigin = endOrigin2;
    } else if (startOrigin2.source && endOrigin2.source && startOrigin2.source === endOrigin2.source) {
      startOrigin = startOrigin2;
      endOrigin = endOrigin2;
    } else if (startOrigin.line !== null && startOrigin.column !== null) {
      // pick the starting file's location and add a character.
      endOrigin = { ...startOrigin, ...{ column: startOrigin.column + 1 } };
github linkedin / css-blocks / packages / @css-blocks / core / src / SourceLocation.ts View on Github external
function pickBestSourceRange(configuration: Configuration, filename: string, source: string, consumer: ReturnType , start: SourcePosition, end: SourcePosition): MappedSourceRange | SourceRange {
  let generated = { filename, start, end, source };
  // Fun fact! The positions returned by the source map consumer use a 1-based
  // index for lines, and a 0-based index for columns.
  let startOrigin: NullableMappedPosition = consumer.originalPositionFor({ line: start.line, column: start.column - 1, bias: SourceMapConsumer.LEAST_UPPER_BOUND});
  let endOrigin: NullableMappedPosition = consumer.originalPositionFor({ line: end.line, column: end.column - 1, bias: SourceMapConsumer.LEAST_UPPER_BOUND});
  // If the start and end locations of the origins are in different files,
  // we try different biases to see if we can get something that agrees.
  if (startOrigin.source && startOrigin.source !== endOrigin.source) {
    let startOrigin2: NullableMappedPosition = consumer.originalPositionFor({ line: start.line, column: start.column - 1, bias: SourceMapConsumer.GREATEST_LOWER_BOUND });
    let endOrigin2: NullableMappedPosition = consumer.originalPositionFor({ line: end.line, column: end.column - 1, bias: SourceMapConsumer.GREATEST_LOWER_BOUND });
    if (startOrigin2.source && startOrigin2.source === endOrigin.source) {
      startOrigin = startOrigin2;
    } else if (endOrigin2.source && startOrigin.source === endOrigin2.source) {
      endOrigin = endOrigin2;
    } else if (startOrigin2.source && endOrigin2.source && startOrigin2.source === endOrigin2.source) {
      startOrigin = startOrigin2;
      endOrigin = endOrigin2;
    } else if (startOrigin.line !== null && startOrigin.column !== null) {
      // pick the starting file's location and add a character.
      endOrigin = { ...startOrigin, ...{ column: startOrigin.column + 1 } };
    } else if (endOrigin.line !== null && endOrigin.column !== null && endOrigin.column > 0) {
github firefox-devtools / devtools-core / packages / devtools-map-bindings / src / scopes.js View on Github external
function getOriginalPositionName(
  map: SourceMapConsumer,
  generatedPosition: SourceMapPosition,
): (string|null) {
  const originalPosition = map.originalPositionFor(generatedPosition);
  if (!originalPosition || !originalPosition.name) {
    return null;
  }
  // Verify if it's the exact position.
  const originalPositionTest = map.originalPositionFor({
    line: generatedPosition.line,
    column: generatedPosition.column,
    bias: SourceMapConsumer.LEAST_UPPER_BOUND
  });
  if (
    !originalPositionTest ||
    originalPositionTest.column !== originalPosition.column ||
    originalPositionTest.line !== originalPosition.line
  ) {
    return null;
  }
  return originalPosition.name;
}
github microsoft / vscode-js-debug / src / adapter / breakpointPredictor.ts View on Github external
for (const metadata of set) {
      if (!metadata.compiledPath) {
        return;
      }

      const map = await sourceUtils.loadSourceMap(metadata);
      if (!map) {
        continue;
      }

      for (const b of params.breakpoints || []) {
        const entry = map.generatedPositionFor({
          source: metadata.sourceUrl,
          line: b.line,
          column: b.column || 1,
          bias: SourceMapConsumer.LEAST_UPPER_BOUND,
        });
        if (entry.line === null) {
          continue;
        }

        const { lineNumber, columnNumber } = uiToRawOffset(
          { lineNumber: entry.line || 1, columnNumber: entry.column ? entry.column + 1 : 1 },
          kNodeScriptOffset,
        );
        const predicted: PredictedLocation = {
          source: {
            absolutePath,
            lineNumber: b.line,
            columnNumber: b.column || 1,
          },
          compiled: {