Returns the represented source code as an array of Buffers. This avoids the
intermediate Buffer.concat allocation performed by buffer() when the source
is composed of multiple children (for example ConcatSource). Consumers that
can accept an array of buffers (e.g. writing via fs.createWriteStream or
writev) should prefer this method for better performance.
The default implementation returns [this.buffer()].
size
Source.prototype.size() -> Number
Returns the size in bytes of the represented source code.
Returns the SourceMap of the represented source code as JSON. May return null if no SourceMap is available.
The options object can contain the following keys:
columns: Boolean (default true): If set to false the implementation may omit mappings for columns.
scopes: Boolean (default false): If set to true the map carries the scopes field of the Scopes proposal, naming for each source the bindings it declares and the expression each one reads in the generated code. Sources declare those bindings themselves — see OriginalSource — and a map whose sources declare none omits the field.
Returns both, source code (like Source.prototype.source() and SourceMap (like Source.prototype.map()). This method could have better performance than calling source() and map() separately.
See map() for options.
updateHash
Source.prototype.updateHash(hash: Hash) -> void
Updates the provided Hash object with the content of the represented source code. (Hash is an object with an update method, which is called with string values)
RawSource
Represents source code without SourceMap.
new RawSource(sourceCode: String | Buffer)
OriginalSource
Represents source code, which is a copy of the original file.
scopeBindings: What each name this source declares reads in the generated code, keyed by the name the source uses. Only consulted when a map is asked for with scopes: true, and carried through wrapping sources such as ReplaceSource and ConcatSource.
OriginalSource tries to create column mappings if requested, by splitting the source code at typical statement borders (;, {, }).
SourceMapSource
Represents source code with SourceMap, optionally having an additional SourceMap for the original source.
originalSource: The source code of the original file. Can be omitted if the sourceMap already contains the original source code.
innerSourceMap: The SourceMap for the originalSource/name.
removeOriginalSource: Removes the source code for name from the final map, keeping only the deeper mappings for that file.
The SourceMapSource supports "identity" mappings for the innerSourceMap.
When original source matches generated source for a mapping it's assumed to be mapped char by char allowing to keep finer mappings from sourceMap.
CachedSource
Decorates a Source and caches returned results of map, source, buffer, size and sourceAndMap in memory. updateHash is not cached.
It tries to reused cached results from other methods to avoid calculations, i. e. when source is already cached, calling size will get the size from the cached source, calling sourceAndMap will only call map on the wrapped Source.
Instead of passing a Source object directly one can pass an function that returns a Source object. The function is only called when needed and once.
Public methods
getCachedData()
Returns the cached data for passing to the constructor. All cached entries are converted to Buffers and strings are avoided.
original()
Returns the original Source object.
originalLazy()
Returns the original Source object or a function returning these.
PrefixSource
Prefix every line of the decorated Source with a provided string.
new PrefixSource( prefix: String, source: Source | String | Buffer)
ConcatSource
Concatenate multiple Sources or strings to a single source.
new ConcatSource( ...items?: Source | String)
Public methods
add
ConcatSource.prototype.add(item: Source | String)
Adds an item to the source.
ReplaceSource
Decorates a Source with replacements and insertions of source code.
The ReplaceSource supports "identity" mappings for child source.
When original source matches generated source for a mapping it's assumed to be mapped char by char allowing to split mappings at replacements/insertions.
Returns where a generated position came from: the closest mapping at or before column on line, or null when nothing maps there. Lines count from one and columns from zero, on both sides. source is joined with the map's sourceRoot. It decodes the whole map, so it suits a one-off lookup such as an error location.