Source Maps

TODO

@parcel/source-maps: API

SourceMap source-map/src/SourceMap.js:7

interface SourceMap {
  static generateEmptyMap(sourceName: string, sourceContent: string, lineOffset: number): SourceMap,
Generates an empty map from the provided fileName and sourceContent
Params:
  • sourceName: path of the source file
  • sourceContent: content of the source file
  • lineOffset: an offset that gets added to the sourceLine index of each mapping
  addEmptyMap(sourceName: string, sourceContent: string, lineOffset: number): SourceMap,
Generates an empty map from the provided fileName and sourceContent
Params:
  • sourceName: path of the source file
  • sourceContent: content of the source file
  • lineOffset: an offset that gets added to the sourceLine index of each mapping
  addRawMappings(map: VLQMap, lineOffset: number, columnOffset: number): SourceMap,
Appends raw VLQ mappings to the sourcemaps
  addBufferMappings(buffer: Buffer, lineOffset: number, columnOffset: number): SourceMap,
Appends a flatbuffer to this sourcemap Note: The flatbuffer buffer should be generated by this library
Params:
  • buffer: the sourcemap buffer that should get appended to this sourcemap
  • lineOffset: an offset that gets added to the sourceLine index of each mapping
  • columnOffset: an offset that gets added to the sourceColumn index of each mapping
  addIndexedMapping(mapping: IndexedMapping<string>, lineOffset?: number, columnOffset?: number): void,
Appends a Mapping object to this sourcemap Note: line numbers start at 1 due to mozilla's source-map library
Params:
  • mapping: the mapping that should be appended to this sourcemap
  • lineOffset: an offset that gets added to the sourceLine index of each mapping
  • columnOffset: an offset that gets added to the sourceColumn index of each mapping
  addIndexedMappings(mappings: Array<IndexedMapping<string>>, lineOffset?: number, columnOffset?: number): SourceMap,
Appends an array of Mapping objects to this sourcemap This is useful when improving performance if a library provides the non-serialised mappings
Note: This is only faster if they generate the serialised map lazily Note: line numbers start at 1 due to mozilla's source-map library
Params:
  • mappings: an array of mapping objects
  • lineOffset: an offset that gets added to the sourceLine index of each mapping
  • columnOffset: an offset that gets added to the sourceColumn index of each mapping
  addName(name: string): number,
Appends a name to the sourcemap
Params:
  • name: the name that should be appended to the names array
  addNames(names: Array<string>): Array<number>,
Appends an array of names to the sourcemap's names array
Params:
  • names: an array of names to add to the sourcemap
  addSource(source: string): number,
Appends a source to the sourcemap's sources array
Params:
  • source: a filepath that should be appended to the sources array
  addSources(sources: Array<string>): Array<number>,
Appends an array of sources to the sourcemap's sources array
Params:
  • sources: an array of filepaths which should sbe appended to the sources array
  getSourceIndex(source: string): number,
Get the index in the sources array for a certain source file filepath
Params:
  • source: the filepath of the source file
  getSource(index: number): string,
Get the source file filepath for a certain index of the sources array
Params:
  • index: the index of the source in the sources array
  setSourceContent(sourceName: string, sourceContent: string): void,
Set the sourceContent for a certain file this is optional and is only recommended for files that we cannot read in at the end when we serialise the sourcemap
Params:
  • sourceName: the path of the sourceFile
  • sourceContent: the content of the sourceFile
  getSourceContent(sourceName: string): string,
Get the content of a source file if it is inlined as part of the source-map
Params:
  • sourceName: filename
  getNameIndex(name: string): number,
Get the index in the names array for a certain name
Params:
  • name: the name you want to find the index of
  getName(index: number): string,
Get the name for a certain index of the names array
Params:
  • index: the index of the name in the names array
  indexedMappingToStringMapping(mapping: ?IndexedMapping<number>): ?IndexedMapping<string>,
Convert a Mapping object that uses indexes for name and source to the actual value of name and source
Note: This is only used internally, should not be used externally and will probably eventually get handled directly in C++ for improved performance
Params:
  • index: the Mapping that should get converted to a string-based Mapping
  extends(buffer: Buffer): SourceMap,
Remaps original positions from this map to the ones in the provided map
This works by finding the closest generated mapping in the provided map to original mappings of this map and remapping those to be the original mapping of the provided map.
Params:
  getMap(): ParsedMap,
Returns an object with mappings, sources and names This should only be used for tests, debugging and visualising sourcemaps
Note: This is a fairly slow operation
  findClosestMapping(line: number, column: number): ?IndexedMapping<string>,
Searches through the sourcemap and returns a mapping that is close to the provided generated line and column
Params:
  • line: the line in the generated code (starts at 1)
  • column: the column in the generated code (starts at 0)
  toBuffer(): Buffer,
Returns a flatbuffer that represents this sourcemap, used for caching
  toVLQ(): VLQMap,
Returns a serialised map using VLQ Mappings
  delete(): void,
A function that has to be called at the end of the SourceMap's lifecycle to ensure all memory and native bindings get de-allocated
  stringify(options: SourceMapStringifyOptions): Promise<string | VLQMap>,
Returns a serialised map
Params:
  • options: options used for formatting the serialised map
}
Referenced by:
BaseAsset, BundleResult, GenerateOutput, MutableAsset, Optimizer, Packager, TransformerResult

MappingPosition source-map/src/types.js:2

type MappingPosition = {|
  line: number,
  column: number,
|}
Referenced by:
IndexedMapping

IndexedMapping source-map/src/types.js:7

type IndexedMapping<T> = {
  generated: MappingPosition,
  original?: MappingPosition,
  source?: T,
  name?: T,
}
Referenced by:
ParsedMap, SourceMap

ParsedMap source-map/src/types.js:15

type ParsedMap = {|
  sources: Array<string>,
  names: Array<string>,
  mappings: Array<IndexedMapping<number>>,
  sourcesContent: Array<string | null>,
|}
Referenced by:
SourceMap

VLQMap source-map/src/types.js:22

type VLQMap = {
  +sources: $ReadOnlyArray<string>,
  +sourcesContent?: $ReadOnlyArray<string | null>,
  +names: $ReadOnlyArray<string>,
  +mappings: string,
  +version?: number,
  +file?: string,
  +sourceRoot?: string,
}
Referenced by:
SourceMap

SourceMapStringifyOptions source-map/src/types.js:33

type SourceMapStringifyOptions = {
  file?: string,
  sourceRoot?: string,
  rootDir?: string,
  inlineSources?: boolean,
  fs?: {
    readFile(path: string, encoding: string): Promise<string>,
    ...
  },
  format?: 'inline' | 'string' | 'object',
}
Referenced by:
SourceMap