.. | ||
lib | ||
LICENSE | ||
package.json | ||
README.md |
webpack-sources
Contains multiple classes which represent a Source
. A
Source
can be asked for source code, size, source map and
hash.
Source
Base class for all sources.
Public methods
All methods should be considered as expensive as they may need to do computations.
source
.prototype.source() -> String | ArrayBuffer Source
Returns the represented source code as string.
size
.prototype.size() -> Number Source
Returns the size in chars of the represented source code.
map
.prototype.map(options: Object) -> Object | null Source
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
(defaulttrue
): If set to false the implementation may omit mappings for columns.module: Boolean
(defaulttrue
): If set to false the implementation may omit inner mappings for modules.
sourceAndMap
.prototype.sourceAndMap(options: Object) -> {
Sourcesource: String,
map: Object
}
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
.prototype.updateHash(hash: Hash) -> void Source
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)
node
(optional)
.prototype.node(options: Object) -> SourceNode Source
This is an optional method. It may be null
if not
implemented.
Returns a SourceNode
(see source-map library) for the
represented source code.
See map()
for options
.
listNode
(optional)
.prototype.listNode(options: Object) -> SourceNode Source
This is an optional method. It may be null
if not
implemented.
Returns a SourceListMap
(see source-list-map library)
for the represented source code.
See map()
for options
.
RawSource
Represents source code without SourceMap.
new RawSource(sourceCode: String)
OriginalSource
Represents source code, which is a copy of the original file.
new OriginalSource(
: String,
sourceCode: String
name )
sourceCode
: The source code.name
: The filename of the original source code.
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.
new SourceMapSource(
: String,
sourceCode: String,
name: Object | String,
sourceMap?: String,
originalSource?: Object | String,
innerSourceMap?: boolean
removeOriginalSource )
sourceCode
: The source code.name
: The filename of the original source code.sourceMap
: The SourceMap for the source code.originalSource
: The source code of the original file. Can be omitted if thesourceMap
already contains the original source code.innerSourceMap
: The SourceMap for theoriginalSource
/name
.removeOriginalSource
: Removes the source code forname
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
.
LineToLineMappedSource
Represents source code, which is mapped line by line to the original file.
new LineToLineMappedSource(
: String,
sourceCode: String,
name: String
originalSource )
sourceCode
: The source code.name
: The filename of the original source code.originalSource
: The original source code.
CachedSource
Decorates a Source
and caches returned results of
map
, source
, size
and
sourceAndMap
in memory. Every other operation is delegated
to the wrapped Source
.
new CachedSource(source: Source)
PrefixSource
Prefix every line of the decorated Source
with a
provided string.
new PrefixSource(
: String,
prefix: Source
source )
ConcatSource
Concatenate multiple Source
s or strings to a single
source.
new ConcatSource(
...items?: Source | String
)
Public methods
add
.prototype.add(item: Source | String) ConcatSource
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.
Public methods
replace
.prototype.replace(
ReplaceSource: Number,
start: Number,
end: String
replacement )
Replaces chars from start
(0-indexed, inclusive) to
end
(0-indexed, inclusive) with
replacement
.
Locations represents locations in the original source and are not influenced by other replacements or insertions.
insert
.prototype.insert(
ReplaceSource: Number,
pos: String
insertion )
Inserts the insertion
before char pos
(0-indexed).
Location represents location in the original source and is not influenced by other replacements or insertions.
original
Get decorated Source
.