3 Contains multiple classes which represent a `Source`. A `Source` can be asked for source code, size, source map and hash.
7 Base class for all sources.
11 All methods should be considered as expensive as they may need to do computations.
16 Source.prototype.source() -> String | Buffer
19 Returns the represented source code as string or Buffer (for binary Sources).
24 Source.prototype.buffer() -> Buffer
27 Returns the represented source code as Buffer. Strings are converted to utf-8.
32 Source.prototype.size() -> Number
35 Returns the size in bytes of the represented source code.
40 Source.prototype.map(options?: Object) -> Object | null
43 Returns the SourceMap of the represented source code as JSON. May return `null` if no SourceMap is available.
45 The `options` object can contain the following keys:
47 - `columns: Boolean` (default `true`): If set to false the implementation may omit mappings for columns.
52 Source.prototype.sourceAndMap(options?: Object) -> {
53 source: String | Buffer,
58 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.
60 See `map()` for `options`.
65 Source.prototype.updateHash(hash: Hash) -> void
68 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)
72 Represents source code without SourceMap.
75 new RawSource(sourceCode: String | Buffer)
80 Represents source code, which is a copy of the original file.
84 sourceCode: String | Buffer,
89 - `sourceCode`: The source code.
90 - `name`: The filename of the original source code.
92 OriginalSource tries to create column mappings if requested, by splitting the source code at typical statement borders (`;`, `{`, `}`).
96 Represents source code with SourceMap, optionally having an additional SourceMap for the original source.
100 sourceCode: String | Buffer,
102 sourceMap: Object | String | Buffer,
103 originalSource?: String | Buffer,
104 innerSourceMap?: Object | String | Buffer,
105 removeOriginalSource?: boolean
109 - `sourceCode`: The source code.
110 - `name`: The filename of the original source code.
111 - `sourceMap`: The SourceMap for the source code.
112 - `originalSource`: The source code of the original file. Can be omitted if the `sourceMap` already contains the original source code.
113 - `innerSourceMap`: The SourceMap for the `originalSource`/`name`.
114 - `removeOriginalSource`: Removes the source code for `name` from the final map, keeping only the deeper mappings for that file.
116 The `SourceMapSource` supports "identity" mappings for the `innerSourceMap`.
117 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`.
121 Decorates a `Source` and caches returned results of `map`, `source`, `buffer`, `size` and `sourceAndMap` in memory. `updateHash` is not cached.
122 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.
125 new CachedSource(source: Source)
126 new CachedSource(source: Source | () => Source, cachedData?: CachedData)
129 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.
133 #### `getCachedData()`
135 Returns the cached data for passing to the constructor. All cached entries are converted to Buffers and strings are avoided.
139 Returns the original `Source` object.
141 #### `originalLazy()`
143 Returns the original `Source` object or a function returning these.
147 Prefix every line of the decorated `Source` with a provided string.
152 source: Source | String | Buffer
158 Concatenate multiple `Source`s or strings to a single source.
162 ...items?: Source | String
171 ConcatSource.prototype.add(item: Source | String)
174 Adds an item to the source.
178 Decorates a `Source` with replacements and insertions of source code.
180 The `ReplaceSource` supports "identity" mappings for child source.
181 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.
188 ReplaceSource.prototype.replace(
195 Replaces chars from `start` (0-indexed, inclusive) to `end` (0-indexed, inclusive) with `replacement`.
197 Locations represents locations in the original source and are not influenced by other replacements or insertions.
202 ReplaceSource.prototype.insert(
208 Inserts the `insertion` before char `pos` (0-indexed).
210 Location represents location in the original source and is not influenced by other replacements or insertions.
214 Get decorated `Source`.
218 Converts a Source-like object into a real Source object.
225 CompatSource.from(sourceLike: any | Source)
228 If `sourceLike` is a real Source it returns it unmodified. Otherwise it returns it wrapped in a CompatSource.