1 |
3a515b92
|
cagy
|
# webpack-sources
|
2 |
|
|
|
3 |
|
|
Contains multiple classes which represent a `Source`. A `Source` can be asked for source code, size, source map and hash.
|
4 |
|
|
|
5 |
|
|
## `Source`
|
6 |
|
|
|
7 |
|
|
Base class for all sources.
|
8 |
|
|
|
9 |
|
|
### Public methods
|
10 |
|
|
|
11 |
|
|
All methods should be considered as expensive as they may need to do computations.
|
12 |
|
|
|
13 |
|
|
#### `source`
|
14 |
|
|
|
15 |
|
|
``` js
|
16 |
|
|
Source.prototype.source() -> String | ArrayBuffer
|
17 |
|
|
```
|
18 |
|
|
|
19 |
|
|
Returns the represented source code as string.
|
20 |
|
|
|
21 |
|
|
#### `size`
|
22 |
|
|
|
23 |
|
|
``` js
|
24 |
|
|
Source.prototype.size() -> Number
|
25 |
|
|
```
|
26 |
|
|
|
27 |
|
|
Returns the size in chars of the represented source code.
|
28 |
|
|
|
29 |
|
|
#### `map`
|
30 |
|
|
|
31 |
|
|
``` js
|
32 |
|
|
Source.prototype.map(options: Object) -> Object | null
|
33 |
|
|
```
|
34 |
|
|
|
35 |
|
|
Returns the SourceMap of the represented source code as JSON. May return `null` if no SourceMap is available.
|
36 |
|
|
|
37 |
|
|
The `options` object can contain the following keys:
|
38 |
|
|
|
39 |
|
|
* `columns: Boolean` (default `true`): If set to false the implementation may omit mappings for columns.
|
40 |
|
|
* `module: Boolean` (default `true`): If set to false the implementation may omit inner mappings for modules.
|
41 |
|
|
|
42 |
|
|
#### `sourceAndMap`
|
43 |
|
|
|
44 |
|
|
``` js
|
45 |
|
|
Source.prototype.sourceAndMap(options: Object) -> {
|
46 |
|
|
source: String,
|
47 |
|
|
map: Object
|
48 |
|
|
}
|
49 |
|
|
```
|
50 |
|
|
|
51 |
|
|
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.
|
52 |
|
|
|
53 |
|
|
See `map()` for `options`.
|
54 |
|
|
|
55 |
|
|
#### `updateHash`
|
56 |
|
|
|
57 |
|
|
``` js
|
58 |
|
|
Source.prototype.updateHash(hash: Hash) -> void
|
59 |
|
|
```
|
60 |
|
|
|
61 |
|
|
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)
|
62 |
|
|
|
63 |
|
|
#### `node` (optional)
|
64 |
|
|
|
65 |
|
|
``` js
|
66 |
|
|
Source.prototype.node(options: Object) -> SourceNode
|
67 |
|
|
```
|
68 |
|
|
|
69 |
|
|
This is an optional method. It may be `null` if not implemented.
|
70 |
|
|
|
71 |
|
|
Returns a `SourceNode` (see source-map library) for the represented source code.
|
72 |
|
|
|
73 |
|
|
See `map()` for `options`.
|
74 |
|
|
|
75 |
|
|
#### `listNode` (optional)
|
76 |
|
|
|
77 |
|
|
``` js
|
78 |
|
|
Source.prototype.listNode(options: Object) -> SourceNode
|
79 |
|
|
```
|
80 |
|
|
|
81 |
|
|
This is an optional method. It may be `null` if not implemented.
|
82 |
|
|
|
83 |
|
|
Returns a `SourceListMap` (see source-list-map library) for the represented source code.
|
84 |
|
|
|
85 |
|
|
See `map()` for `options`.
|
86 |
|
|
|
87 |
|
|
## `RawSource`
|
88 |
|
|
|
89 |
|
|
Represents source code without SourceMap.
|
90 |
|
|
|
91 |
|
|
``` js
|
92 |
|
|
new RawSource(sourceCode: String)
|
93 |
|
|
```
|
94 |
|
|
|
95 |
|
|
## `OriginalSource`
|
96 |
|
|
|
97 |
|
|
Represents source code, which is a copy of the original file.
|
98 |
|
|
|
99 |
|
|
``` js
|
100 |
|
|
new OriginalSource(
|
101 |
|
|
sourceCode: String,
|
102 |
|
|
name: String
|
103 |
|
|
)
|
104 |
|
|
```
|
105 |
|
|
|
106 |
|
|
* `sourceCode`: The source code.
|
107 |
|
|
* `name`: The filename of the original source code.
|
108 |
|
|
|
109 |
|
|
OriginalSource tries to create column mappings if requested, by splitting the source code at typical statement borders (`;`, `{`, `}`).
|
110 |
|
|
|
111 |
|
|
## `SourceMapSource`
|
112 |
|
|
|
113 |
|
|
Represents source code with SourceMap, optionally having an additional SourceMap for the original source.
|
114 |
|
|
|
115 |
|
|
``` js
|
116 |
|
|
new SourceMapSource(
|
117 |
|
|
sourceCode: String,
|
118 |
|
|
name: String,
|
119 |
|
|
sourceMap: Object | String,
|
120 |
|
|
originalSource?: String,
|
121 |
|
|
innerSourceMap?: Object | String,
|
122 |
|
|
removeOriginalSource?: boolean
|
123 |
|
|
)
|
124 |
|
|
```
|
125 |
|
|
|
126 |
|
|
* `sourceCode`: The source code.
|
127 |
|
|
* `name`: The filename of the original source code.
|
128 |
|
|
* `sourceMap`: The SourceMap for the source code.
|
129 |
|
|
* `originalSource`: The source code of the original file. Can be omitted if the `sourceMap` already contains the original source code.
|
130 |
|
|
* `innerSourceMap`: The SourceMap for the `originalSource`/`name`.
|
131 |
|
|
* `removeOriginalSource`: Removes the source code for `name` from the final map, keeping only the deeper mappings for that file.
|
132 |
|
|
|
133 |
|
|
The `SourceMapSource` supports "identity" mappings for the `innerSourceMap`.
|
134 |
|
|
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`.
|
135 |
|
|
|
136 |
|
|
## `LineToLineMappedSource`
|
137 |
|
|
|
138 |
|
|
Represents source code, which is mapped line by line to the original file.
|
139 |
|
|
|
140 |
|
|
``` js
|
141 |
|
|
new LineToLineMappedSource(
|
142 |
|
|
sourceCode: String,
|
143 |
|
|
name: String,
|
144 |
|
|
originalSource: String
|
145 |
|
|
)
|
146 |
|
|
```
|
147 |
|
|
|
148 |
|
|
* `sourceCode`: The source code.
|
149 |
|
|
* `name`: The filename of the original source code.
|
150 |
|
|
* `originalSource`: The original source code.
|
151 |
|
|
|
152 |
|
|
## `CachedSource`
|
153 |
|
|
|
154 |
|
|
Decorates a `Source` and caches returned results of `map`, `source`, `size` and `sourceAndMap` in memory. Every other operation is delegated to the wrapped `Source`.
|
155 |
|
|
|
156 |
|
|
``` js
|
157 |
|
|
new CachedSource(source: Source)
|
158 |
|
|
```
|
159 |
|
|
|
160 |
|
|
## `PrefixSource`
|
161 |
|
|
|
162 |
|
|
Prefix every line of the decorated `Source` with a provided string.
|
163 |
|
|
|
164 |
|
|
``` js
|
165 |
|
|
new PrefixSource(
|
166 |
|
|
prefix: String,
|
167 |
|
|
source: Source
|
168 |
|
|
)
|
169 |
|
|
```
|
170 |
|
|
|
171 |
|
|
## `ConcatSource`
|
172 |
|
|
|
173 |
|
|
Concatenate multiple `Source`s or strings to a single source.
|
174 |
|
|
|
175 |
|
|
``` js
|
176 |
|
|
new ConcatSource(
|
177 |
|
|
...items?: Source | String
|
178 |
|
|
)
|
179 |
|
|
```
|
180 |
|
|
|
181 |
|
|
### Public methods
|
182 |
|
|
|
183 |
|
|
#### `add`
|
184 |
|
|
|
185 |
|
|
``` js
|
186 |
|
|
ConcatSource.prototype.add(item: Source | String)
|
187 |
|
|
```
|
188 |
|
|
|
189 |
|
|
Adds an item to the source.
|
190 |
|
|
|
191 |
|
|
## `ReplaceSource`
|
192 |
|
|
|
193 |
|
|
Decorates a `Source` with replacements and insertions of source code.
|
194 |
|
|
|
195 |
|
|
The `ReplaceSource` supports "identity" mappings for child source.
|
196 |
|
|
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.
|
197 |
|
|
|
198 |
|
|
### Public methods
|
199 |
|
|
|
200 |
|
|
#### `replace`
|
201 |
|
|
|
202 |
|
|
``` js
|
203 |
|
|
ReplaceSource.prototype.replace(
|
204 |
|
|
start: Number,
|
205 |
|
|
end: Number,
|
206 |
|
|
replacement: String
|
207 |
|
|
)
|
208 |
|
|
```
|
209 |
|
|
|
210 |
|
|
Replaces chars from `start` (0-indexed, inclusive) to `end` (0-indexed, inclusive) with `replacement`.
|
211 |
|
|
|
212 |
|
|
Locations represents locations in the original source and are not influenced by other replacements or insertions.
|
213 |
|
|
|
214 |
|
|
#### `insert`
|
215 |
|
|
|
216 |
|
|
``` js
|
217 |
|
|
ReplaceSource.prototype.insert(
|
218 |
|
|
pos: Number,
|
219 |
|
|
insertion: String
|
220 |
|
|
)
|
221 |
|
|
```
|
222 |
|
|
|
223 |
|
|
Inserts the `insertion` before char `pos` (0-indexed).
|
224 |
|
|
|
225 |
|
|
Location represents location in the original source and is not influenced by other replacements or insertions.
|
226 |
|
|
|
227 |
|
|
#### `original`
|
228 |
|
|
|
229 |
|
|
Get decorated `Source`.
|