source: frontend/node_modules/webpack-sources/README.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 6.7 KB
Line 
1# webpack-sources
2
3Contains multiple classes which represent a `Source`. A `Source` can be asked for source code, size, source map and hash.
4
5## `Source`
6
7Base class for all sources.
8
9### Public methods
10
11All methods should be considered as expensive as they may need to do computations.
12
13#### `source`
14
15<!-- eslint-skip -->
16```typescript
17Source.prototype.source() -> String | Buffer
18```
19
20Returns the represented source code as string or Buffer (for binary Sources).
21
22#### `buffer`
23
24<!-- eslint-skip -->
25```typescript
26Source.prototype.buffer() -> Buffer
27```
28
29Returns the represented source code as Buffer. Strings are converted to utf-8.
30
31#### `buffers`
32
33<!-- eslint-skip -->
34```typescript
35Source.prototype.buffers() -> Buffer[]
36```
37
38Returns the represented source code as an array of Buffers. This avoids the
39intermediate `Buffer.concat` allocation performed by `buffer()` when the source
40is composed of multiple children (for example `ConcatSource`). Consumers that
41can accept an array of buffers (e.g. writing via `fs.createWriteStream` or
42`writev`) should prefer this method for better performance.
43
44The default implementation returns `[this.buffer()]`.
45
46#### `size`
47
48<!-- eslint-skip -->
49```typescript
50Source.prototype.size() -> Number
51```
52
53Returns the size in bytes of the represented source code.
54
55#### `map`
56
57<!-- eslint-skip -->
58```typescript
59Source.prototype.map(options?: Object) -> Object | null
60```
61
62Returns the SourceMap of the represented source code as JSON. May return `null` if no SourceMap is available.
63
64The `options` object can contain the following keys:
65
66- `columns: Boolean` (default `true`): If set to false the implementation may omit mappings for columns.
67
68#### `sourceAndMap`
69
70<!-- eslint-skip -->
71```typescript
72Source.prototype.sourceAndMap(options?: Object) -> {
73 source: String | Buffer,
74 map: Object | null
75}
76```
77
78Returns 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.
79
80See `map()` for `options`.
81
82#### `updateHash`
83
84<!-- eslint-skip -->
85```typescript
86Source.prototype.updateHash(hash: Hash) -> void
87```
88
89Updates 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)
90
91## `RawSource`
92
93Represents source code without SourceMap.
94
95<!-- eslint-skip -->
96```typescript
97new RawSource(sourceCode: String | Buffer)
98```
99
100## `OriginalSource`
101
102Represents source code, which is a copy of the original file.
103
104<!-- eslint-skip -->
105```typescript
106new OriginalSource(
107 sourceCode: String | Buffer,
108 name: String
109)
110```
111
112- `sourceCode`: The source code.
113- `name`: The filename of the original source code.
114
115OriginalSource tries to create column mappings if requested, by splitting the source code at typical statement borders (`;`, `{`, `}`).
116
117## `SourceMapSource`
118
119Represents source code with SourceMap, optionally having an additional SourceMap for the original source.
120
121<!-- eslint-skip -->
122```typescript
123new SourceMapSource(
124 sourceCode: String | Buffer,
125 name: String,
126 sourceMap: Object | String | Buffer,
127 originalSource?: String | Buffer,
128 innerSourceMap?: Object | String | Buffer,
129 removeOriginalSource?: boolean
130)
131```
132
133- `sourceCode`: The source code.
134- `name`: The filename of the original source code.
135- `sourceMap`: The SourceMap for the source code.
136- `originalSource`: The source code of the original file. Can be omitted if the `sourceMap` already contains the original source code.
137- `innerSourceMap`: The SourceMap for the `originalSource`/`name`.
138- `removeOriginalSource`: Removes the source code for `name` from the final map, keeping only the deeper mappings for that file.
139
140The `SourceMapSource` supports "identity" mappings for the `innerSourceMap`.
141When original source matches generated source for a mapping it's assumed to be mapped char by char allowing to keep finer mappings from `sourceMap`.
142
143## `CachedSource`
144
145Decorates a `Source` and caches returned results of `map`, `source`, `buffer`, `size` and `sourceAndMap` in memory. `updateHash` is not cached.
146It 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.
147
148<!-- eslint-skip -->
149```typescript
150new CachedSource(source: Source)
151new CachedSource(source: Source | () => Source, cachedData?: CachedData)
152```
153
154Instead 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.
155
156### Public methods
157
158#### `getCachedData()`
159
160Returns the cached data for passing to the constructor. All cached entries are converted to Buffers and strings are avoided.
161
162#### `original()`
163
164Returns the original `Source` object.
165
166#### `originalLazy()`
167
168Returns the original `Source` object or a function returning these.
169
170## `PrefixSource`
171
172Prefix every line of the decorated `Source` with a provided string.
173
174<!-- eslint-skip -->
175```typescript
176new PrefixSource(
177 prefix: String,
178 source: Source | String | Buffer
179)
180```
181
182## `ConcatSource`
183
184Concatenate multiple `Source`s or strings to a single source.
185
186<!-- eslint-skip -->
187```typescript
188new ConcatSource(
189 ...items?: Source | String
190)
191```
192
193### Public methods
194
195#### `add`
196
197<!-- eslint-skip -->
198```typescript
199ConcatSource.prototype.add(item: Source | String)
200```
201
202Adds an item to the source.
203
204## `ReplaceSource`
205
206Decorates a `Source` with replacements and insertions of source code.
207
208The `ReplaceSource` supports "identity" mappings for child source.
209When original source matches generated source for a mapping it's assumed to be mapped char by char allowing to split mappings at replacements/insertions.
210
211### Public methods
212
213#### `replace`
214
215<!-- eslint-skip -->
216```typescript
217ReplaceSource.prototype.replace(
218 start: Number,
219 end: Number,
220 replacement: String
221)
222```
223
224Replaces chars from `start` (0-indexed, inclusive) to `end` (0-indexed, inclusive) with `replacement`.
225
226Locations represents locations in the original source and are not influenced by other replacements or insertions.
227
228#### `insert`
229
230<!-- eslint-skip -->
231```typescript
232ReplaceSource.prototype.insert(
233 pos: Number,
234 insertion: String
235)
236```
237
238Inserts the `insertion` before char `pos` (0-indexed).
239
240Location represents location in the original source and is not influenced by other replacements or insertions.
241
242#### `original`
243
244Get decorated `Source`.
245
246## `CompatSource`
247
248Converts a Source-like object into a real Source object.
249
250### Public methods
251
252#### static `from`
253
254<!-- eslint-skip -->
255```typescript
256CompatSource.from(sourceLike: any | Source)
257```
258
259If `sourceLike` is a real Source it returns it unmodified. Otherwise it returns it wrapped in a CompatSource.
Note: See TracBrowser for help on using the repository browser.