1 | # 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
|
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 | code: 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()` separatly.
|
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 | )
|
123 | ```
|
124 |
|
125 | * `sourceCode`: The source code.
|
126 | * `name`: The filename of the original source code.
|
127 | * `sourceMap`: The SourceMap for the source code.
|
128 | * `originalSource`: The source code of the original file. Can be omitted if the `sourceMap` already contains the original source code.
|
129 | * `innerSourceMap`: The SourceMap for the `originalSource`/`name`.
|
130 |
|
131 | ## `LineToLineMappedSource`
|
132 |
|
133 | Represents source code, which is mapped line by line to the orginal file.
|
134 |
|
135 | ``` js
|
136 | new LineToLineMappedSource(
|
137 | sourceCode: String,
|
138 | name: String,
|
139 | originalSource: String
|
140 | )
|
141 | ```
|
142 |
|
143 | * `sourceCode`: The source code.
|
144 | * `name`: The filename of the original source code.
|
145 | * `originalSource`: The original source code.
|
146 |
|
147 | ## `CachedSource`
|
148 |
|
149 | Decorates a `Source` and caches returned results of `map`, `source`, `size` and `sourceAndMap` in memory. Every other operation is delegated to the wrapped `Source`.
|
150 |
|
151 | ``` js
|
152 | new CachedSource(source: Source)
|
153 | ```
|
154 |
|
155 | ## `PrefixSource`
|
156 |
|
157 | Prefix every line of the decorated `Source` with a provided string.
|
158 |
|
159 | ``` js
|
160 | new PrefixSource(
|
161 | prefix: String,
|
162 | source: Source
|
163 | )
|
164 | ```
|
165 |
|
166 | ## `ConcatSource`
|
167 |
|
168 | Concatenate mulitple `Source`s or strings to a single source.
|
169 |
|
170 | ``` js
|
171 | new ConcatSource(
|
172 | ...items?: Source | String
|
173 | )
|
174 | ```
|
175 |
|
176 | ### Public methods
|
177 |
|
178 | #### `add`
|
179 |
|
180 | ``` js
|
181 | ConcatSource.prototype.add(item: Source | String)
|
182 | ```
|
183 |
|
184 | Adds an item to the source.
|
185 |
|
186 | ## `ReplaceSource`
|
187 |
|
188 | Decorates a `Source` with replacements and insertions of source code.
|
189 |
|
190 | ### Public methods
|
191 |
|
192 | #### `replace`
|
193 |
|
194 | ``` js
|
195 | ReplaceSource.prototype.replace(
|
196 | start: Number,
|
197 | end: Number,
|
198 | replacement: String
|
199 | )
|
200 | ```
|
201 |
|
202 | Replaces chars from `start` (0-indexed, inclusive) to `end` (0-indexed, inclusive) with `replacement`.
|
203 |
|
204 | Locations represents locations in the original source and are not influenced by other replacements or insertions.
|
205 |
|
206 | #### `insert`
|
207 |
|
208 | ``` js
|
209 | ReplaceSource.prototype.insert(
|
210 | pos: Number,
|
211 | insertion: String
|
212 | )
|
213 | ```
|
214 |
|
215 | Inserts the `insertion` before char `pos` (0-indexed).
|
216 |
|
217 | Location represents location in the original source and is not influenced by other replacements or insertions.
|
218 |
|
219 |
|