Skip to main content
The Deno 2 Release Candidate is here
Learn more
Module

x/source_map/mod.js>SourceMapConsumer

Port of mozilla / source-map to deno.
Latest
class SourceMapConsumer
import { SourceMapConsumer } from "https://deno.land/x/source_map@0.8.0-beta.1/mod.js";

Constructors

new
SourceMapConsumer(aSourceMap, aSourceMapURL)

Methods

Returns all generated line and column information for the original source, line, and column provided. If no column is provided, returns all mappings corresponding to a either the line we are searching for or the next closest line that has any mappings. Otherwise, returns all mappings corresponding to the given line and either the column we are searching for or the next closest column that has any offsets.

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: Optional. the column number in the original source. The column number is 0-based.

and an array of objects is returned, each 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.
eachMapping(
aCallback,
aContext,
aOrder,
)

Iterate over each mapping between an original source/line/column and a generated line/column in this source map.

Static Methods

fromSourceMap(aSourceMap, aSourceMapURL)
with(
rawSourceMap,
sourceMapUrl,
f,
)

Construct a new SourceMapConsumer from rawSourceMap and sourceMapUrl (see the SourceMapConsumer constructor for details. Then, invoke the async function f(SourceMapConsumer) -> T with the newly constructed consumer, wait for f to complete, call destroy on the consumer, and return f's return value.

You must not use the consumer after f completes!

By using with, you do not have to remember to manually call destroy on the consumer, since it will be called automatically once f completes.

const xSquared = await SourceMapConsumer.with(
  myRawSourceMap,
  null,
  async function (consumer) {
    // Use `consumer` inside here and don't worry about remembering
    // to call `destroy`.

    const x = await whatever(consumer);
    return x * x;
  }
);

// You may not use that `consumer` anymore out here; it has
// been destroyed. But you can use `xSquared`.
console.log(xSquared);