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

An IndexedSourceMapConsumer instance represents a parsed source map which we can query for information. It differs from BasicSourceMapConsumer in that it takes "indexed" source maps (i.e. ones with a "sections" field) as input.

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

  • version: Which version of the source map spec this map is following.
  • file: Optional. The generated file this source map is associated with.
  • sections: A list of section definitions.

Each value under the "sections" field has two fields:

  • offset: The offset into the original specified at which this section begins to apply, defined as an object with a "line" and "column" field.
  • map: A source map definition. This source map could also be indexed, but doesn't have to be.

Instead of the "map" field, it's also possible to have a "url" field specifying a URL to retrieve a source map from, but that's currently unsupported.

Here's an example source map, taken from the source map spec0, but modified to omit a section which uses the "url" field.

{ version : 3, file: "app.js", sections: [{ offset: {line:100, column:10}, map: { version : 3, file: "section.js", sources: ["foo.js", "bar.js"], names: ["src", "maps", "are", "fun"], mappings: "AAAA,E;;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
IndexedSourceMapConsumer(aSourceMap, aSourceMapURL)

Properties

readonly
sources

The list of original sources.

Methods

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.

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.

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.