Skip to main content
The Deno 2 Release Candidate is here
Learn more
Latest
class BasicSourceMapConsumer
import { BasicSourceMapConsumer } from "https://deno.land/x/source_map@0.8.0-beta.1/lib/source-map-consumer.js";

A BasicSourceMapConsumer instance represents a parsed source map which we can query for information about the original file positions by giving it a file position in the generated source.

The first parameter is the raw source map (either as a JSON string, or already parsed to an object). According to the spec, source maps have the following attributes:

  • version: Which version of the source map spec this map is following.
  • sources: An array of URLs to the original source files.
  • names: An array of identifiers which can be referenced by individual mappings.
  • sourceRoot: Optional. The URL root from which all sources are relative.
  • sourcesContent: Optional. An array of contents of the original source files.
  • mappings: A string of base64 VLQs which contain the actual mappings.
  • file: Optional. The generated file this source map is associated with.

Here is an example source map, taken from the source map spec0:

{
  version : 3,
  file: "out.js",
  sourceRoot : "",
  sources: ["foo.js", "bar.js"],
  names: ["src", "maps", "are", "fun"],
  mappings: "AA,AB;;ABCDE;"
}

The second parameter, if given, is a string whose value is the URL at which the source map was found. This URL is used to compute the sources array.

Constructors

new
BasicSourceMapConsumer(aSourceMap, aSourceMapURL)

Properties

readonly
sources

Methods

Utility function to find the index of a source. Returns -1 if not found.

Parse the mappings in a string in to a data structure which we can easily query (the ordered arrays in the this.__generatedMappings and this.__originalMappings properties).

Compute the last column for each generated mapping. The last column is inclusive.

eachMapping(
aCallback,
aContext,
aOrder,
)

Returns the generated line and column information for the original source, line, and column positions provided. The only argument is an object with the following properties:

  • source: The filename of the original source.
  • line: The line number in the original source. The line number is 1-based.
  • column: The column number in the original source. The column number is 0-based.
  • bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the closest element that is smaller than or greater than the one we are searching for, respectively, if the exact element cannot be found. Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.

and an object is returned with the following properties:

  • line: The line number in the generated source, or null. The line number is 1-based.
  • column: The column number in the generated source, or null. The column number is 0-based.

Return true if we have the source content for every source in the source map, false otherwise.

Returns the original source, line, and column information for the generated source's line and column positions provided. The only argument is an object with the following properties:

  • line: The line number in the generated source. The line number is 1-based.
  • column: The column number in the generated source. The column number is 0-based.
  • bias: Either 'SourceMapConsumer.GREATEST_LOWER_BOUND' or 'SourceMapConsumer.LEAST_UPPER_BOUND'. Specifies whether to return the closest element that is smaller than or greater than the one we are searching for, respectively, if the exact element cannot be found. Defaults to 'SourceMapConsumer.GREATEST_LOWER_BOUND'.

and an object is returned with the following properties:

  • source: The original source file, or null.
  • line: The line number in the original source, or null. The line number is 1-based.
  • column: The column number in the original source, or null. The column number is 0-based.
  • name: The original identifier, or null.
sourceContentFor(aSource, nullOnMissing)

Returns the original source content. The only argument is the url of the original source file. Returns null if no original source content is available.

Static Methods

fromSourceMap(aSourceMap, aSourceMapURL)

Create a BasicSourceMapConsumer from a SourceMapGenerator.