source-map
- Version 0.7.4
- Published
- 226 kB
- No dependencies
- BSD-3-Clause license
Install
npm i source-map
yarn add source-map
pnpm add source-map
Overview
Generates and consumes source maps
Index
Variables
Classes
Interfaces
Type Aliases
Variables
variable BasicSourceMapConsumer
const BasicSourceMapConsumer: BasicSourceMapConsumerConstructor;
variable IndexedSourceMapConsumer
const IndexedSourceMapConsumer: IndexedSourceMapConsumerConstructor;
variable SourceMapConsumer
const SourceMapConsumer: SourceMapConsumerConstructor;
Classes
class SourceMapGenerator
class SourceMapGenerator {}
constructor
constructor(startOfSourceMap?: StartOfSourceMap);
method addMapping
addMapping: (mapping: Mapping) => void;
Add a single mapping from original source line and column to the generated source's line and column for this source map being created. The mapping object should have the following properties:
- generated: An object with the generated line and column positions. - original: An object with the original line and column positions. - source: The original source file (relative to the sourceRoot). - name: An optional original token name for this mapping.
method applySourceMap
applySourceMap: ( sourceMapConsumer: SourceMapConsumer, sourceFile?: string, sourceMapPath?: string) => void;
Applies the mappings of a sub-source-map for a specific source file to the source map being generated. Each mapping to the supplied source file is rewritten using the supplied source map. Note: The resolution for the resulting mappings is the minimium of this map and the supplied map.
Parameter sourceMapConsumer
The source map to be applied.
Parameter sourceFile
Optional. The filename of the source file. If omitted, SourceMapConsumer's file property will be used.
Parameter sourceMapPath
Optional. The dirname of the path to the source map to be applied. If relative, it is relative to the SourceMapConsumer. This parameter is needed when the two source maps aren't in the same directory, and the source map to be applied contains relative source paths. If so, those relative source paths need to be rewritten relative to the SourceMapGenerator.
method fromSourceMap
static fromSourceMap: ( sourceMapConsumer: SourceMapConsumer) => SourceMapGenerator;
Creates a new SourceMapGenerator based on a SourceMapConsumer
Parameter sourceMapConsumer
The SourceMap.
method setSourceContent
setSourceContent: (sourceFile: string, sourceContent: string) => void;
Set the source content for a source file.
method toJSON
toJSON: () => RawSourceMap;
method toString
toString: () => string;
class SourceNode
class SourceNode {}
constructor
constructor();
constructor
constructor( line: number, column: number, source: string, chunks?: string | SourceNode | (string | SourceNode)[], name?: string);
property children
children: SourceNode[];
property column
column: number;
property line
line: number;
property name
name: string;
property source
source: string;
property sourceContents
sourceContents: any;
method add
add: (chunk: Array<string | SourceNode> | SourceNode | string) => SourceNode;
method fromStringWithSourceMap
static fromStringWithSourceMap: ( code: string, sourceMapConsumer: SourceMapConsumer, relativePath?: string) => SourceNode;
method join
join: (sep: string) => SourceNode;
method prepend
prepend: (chunk: Array<string | SourceNode> | SourceNode | string) => SourceNode;
method replaceRight
replaceRight: (pattern: string, replacement: string) => SourceNode;
method setSourceContent
setSourceContent: (sourceFile: string, sourceContent: string) => void;
method toString
toString: () => string;
method toStringWithSourceMap
toStringWithSourceMap: ( startOfSourceMap?: StartOfSourceMap) => CodeWithSourceMap;
method walk
walk: (fn: (chunk: string, mapping: MappedPosition) => void) => void;
method walkSourceContents
walkSourceContents: (fn: (file: string, content: string) => void) => void;
Interfaces
interface BasicSourceMapConsumer
interface BasicSourceMapConsumer extends SourceMapConsumer {}
property file
file: string;
property sourceRoot
sourceRoot: string;
property sources
sources: string[];
property sourcesContent
sourcesContent: string[];
interface BasicSourceMapConsumerConstructor
interface BasicSourceMapConsumerConstructor {}
property prototype
prototype: BasicSourceMapConsumer;
method fromSourceMap
fromSourceMap: ( sourceMap: SourceMapGenerator) => Promise<BasicSourceMapConsumer>;
Create a BasicSourceMapConsumer from a SourceMapGenerator.
Parameter sourceMap
The source map that will be consumed.
construct signature
new (rawSourceMap: RawSourceMap | string): Promise<BasicSourceMapConsumer>;
interface CodeWithSourceMap
interface CodeWithSourceMap {}
interface IndexedSourceMapConsumer
interface IndexedSourceMapConsumer extends SourceMapConsumer {}
property sources
sources: string[];
interface IndexedSourceMapConsumerConstructor
interface IndexedSourceMapConsumerConstructor {}
property prototype
prototype: IndexedSourceMapConsumer;
construct signature
new (rawSourceMap: RawIndexMap | string): Promise<IndexedSourceMapConsumer>;
interface MappedPosition
interface MappedPosition {}
interface Mapping
interface Mapping {}
interface MappingItem
interface MappingItem {}
property generatedColumn
generatedColumn: number;
property generatedLine
generatedLine: number;
property name
name: string;
property originalColumn
originalColumn: number;
property originalLine
originalLine: number;
property source
source: string;
interface NullableMappedPosition
interface NullableMappedPosition {}
interface NullablePosition
interface NullablePosition {}
property column
column: number | null;
property lastColumn
lastColumn: number | null;
property line
line: number | null;
interface RawIndexMap
interface RawIndexMap extends StartOfSourceMap {}
interface RawSection
interface RawSection {}
interface RawSourceMap
interface RawSourceMap {}
property file
file: string;
property mappings
mappings: string;
property names
names: string[];
property sourceRoot
sourceRoot?: string;
property sources
sources: string[];
property sourcesContent
sourcesContent?: string[];
property version
version: number;
interface SourceMapConsumer
interface SourceMapConsumer {}
method allGeneratedPositionsFor
allGeneratedPositionsFor: ( originalPosition: MappedPosition) => NullablePosition[];
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. - column: Optional. the column number in the original source.
and an array of objects is returned, each with the following properties:
- line: The line number in the generated source, or null. - column: The column number in the generated source, or null.
method computeColumnSpans
computeColumnSpans: () => void;
Compute the last column for each generated mapping. The last column is inclusive.
method destroy
destroy: () => void;
Free this source map consumer's associated wasm data that is manually-managed. Alternatively, you can use SourceMapConsumer.with to avoid needing to remember to call destroy.
method eachMapping
eachMapping: ( callback: (mapping: MappingItem) => void, context?: any, order?: number) => void;
Iterate over each mapping between an original source/line/column and a generated line/column in this source map.
Parameter callback
The function that is called with each mapping.
Parameter context
Optional. If specified, this object will be the value of
this
every time thataCallback
is called.Parameter order
Either
SourceMapConsumer.GENERATED_ORDER
orSourceMapConsumer.ORIGINAL_ORDER
. Specifies whether you want to iterate over the mappings sorted by the generated file's line/column order or the original's source/line/column order, respectively. Defaults toSourceMapConsumer.GENERATED_ORDER
.
method generatedPositionFor
generatedPositionFor: ( originalPosition: MappedPosition & { bias?: number }) => NullablePosition;
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. - column: The column number in the original source. - 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. - column: The column number in the generated source, or null.
method hasContentsOfAllSources
hasContentsOfAllSources: () => boolean;
Return true if we have the source content for every source in the source map, false otherwise.
method originalPositionFor
originalPositionFor: ( generatedPosition: Position & { bias?: number }) => NullableMappedPosition;
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. - column: The column number in the generated source. - 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. - column: The column number in the original source, or null. - name: The original identifier, or null.
method sourceContentFor
sourceContentFor: ( source: string, returnNullOnMissing?: boolean) => string | null;
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.
interface SourceMapConsumerConstructor
interface SourceMapConsumerConstructor {}
property GENERATED_ORDER
GENERATED_ORDER: number;
property GREATEST_LOWER_BOUND
GREATEST_LOWER_BOUND: number;
property LEAST_UPPER_BOUND
LEAST_UPPER_BOUND: number;
property ORIGINAL_ORDER
ORIGINAL_ORDER: number;
property prototype
prototype: SourceMapConsumer;
method fromSourceMap
fromSourceMap: ( sourceMap: SourceMapGenerator, sourceMapUrl?: SourceMapUrl) => Promise<BasicSourceMapConsumer>;
Create a BasicSourceMapConsumer from a SourceMapGenerator.
Parameter sourceMap
The source map that will be consumed.
method with
with: <T>( rawSourceMap: RawSourceMap | RawIndexMap | string, sourceMapUrl: SourceMapUrl | null | undefined, callback: ( consumer: BasicSourceMapConsumer | IndexedSourceMapConsumer ) => Promise<T> | T) => Promise<T>;
Construct a new
SourceMapConsumer
fromrawSourceMap
andsourceMapUrl
(see theSourceMapConsumer
constructor for details. Then, invoke the `async function f(SourceMapConsumer) -> T` with the newly constructed consumer, wait forf
to complete, calldestroy
on the consumer, and returnf
's return value.You must not use the consumer after
f
completes!By using
with
, you do not have to remember to manually calldestroy
on the consumer, since it will be called automatically oncef
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);
construct signature
new ( rawSourceMap: RawSourceMap, sourceMapUrl?: SourceMapUrl): Promise<BasicSourceMapConsumer>;
construct signature
new ( rawSourceMap: RawIndexMap, sourceMapUrl?: SourceMapUrl): Promise<IndexedSourceMapConsumer>;
construct signature
new ( rawSourceMap: RawSourceMap | RawIndexMap | string, sourceMapUrl?: SourceMapUrl): Promise<BasicSourceMapConsumer | IndexedSourceMapConsumer>;
interface StartOfSourceMap
interface StartOfSourceMap {}
property file
file?: string;
property skipValidation
skipValidation?: boolean;
property sourceRoot
sourceRoot?: string;
Type Aliases
type SourceMapUrl
type SourceMapUrl = string;
Package Files (1)
Dependencies (0)
No dependencies.
Dev Dependencies (8)
Peer Dependencies (0)
No peer dependencies.
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/source-map
.
- Markdown[![jsDocs.io](https://img.shields.io/badge/jsDocs.io-reference-blue)](https://www.jsdocs.io/package/source-map)
- HTML<a href="https://www.jsdocs.io/package/source-map"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3339 ms. - Missing or incorrect documentation? Open an issue for this package.