1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | "use strict";
|
7 |
|
8 | const { register } = require("./serialization");
|
9 |
|
10 | const Position = (require("acorn")).Position;
|
11 | const SourceLocation = require("acorn").SourceLocation;
|
12 | const ValidationError = require("schema-utils/dist/ValidationError").default;
|
13 | const {
|
14 | CachedSource,
|
15 | ConcatSource,
|
16 | OriginalSource,
|
17 | PrefixSource,
|
18 | RawSource,
|
19 | ReplaceSource,
|
20 | SourceMapSource
|
21 | } = require("webpack-sources");
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | const CURRENT_MODULE = "webpack/lib/util/registerExternalSerializer";
|
32 |
|
33 | register(
|
34 | CachedSource,
|
35 | CURRENT_MODULE,
|
36 | "webpack-sources/CachedSource",
|
37 | new (class CachedSourceSerializer {
|
38 | |
39 |
|
40 |
|
41 |
|
42 |
|
43 | serialize(source, { write, writeLazy }) {
|
44 | if (writeLazy) {
|
45 | writeLazy(source.originalLazy());
|
46 | } else {
|
47 | write(source.original());
|
48 | }
|
49 | write(source.getCachedData());
|
50 | }
|
51 |
|
52 | |
53 |
|
54 |
|
55 |
|
56 | deserialize({ read }) {
|
57 | const source = read();
|
58 | const cachedData = read();
|
59 | return new CachedSource(source, cachedData);
|
60 | }
|
61 | })()
|
62 | );
|
63 |
|
64 | register(
|
65 | RawSource,
|
66 | CURRENT_MODULE,
|
67 | "webpack-sources/RawSource",
|
68 | new (class RawSourceSerializer {
|
69 | |
70 |
|
71 |
|
72 |
|
73 |
|
74 | serialize(source, { write }) {
|
75 | write(source.buffer());
|
76 | write(!source.isBuffer());
|
77 | }
|
78 |
|
79 | |
80 |
|
81 |
|
82 |
|
83 | deserialize({ read }) {
|
84 | const source = read();
|
85 | const convertToString = read();
|
86 | return new RawSource(source, convertToString);
|
87 | }
|
88 | })()
|
89 | );
|
90 |
|
91 | register(
|
92 | ConcatSource,
|
93 | CURRENT_MODULE,
|
94 | "webpack-sources/ConcatSource",
|
95 | new (class ConcatSourceSerializer {
|
96 | |
97 |
|
98 |
|
99 |
|
100 |
|
101 | serialize(source, { write }) {
|
102 | write(source.getChildren());
|
103 | }
|
104 |
|
105 | |
106 |
|
107 |
|
108 |
|
109 | deserialize({ read }) {
|
110 | const source = new ConcatSource();
|
111 | source.addAllSkipOptimizing(read());
|
112 | return source;
|
113 | }
|
114 | })()
|
115 | );
|
116 |
|
117 | register(
|
118 | PrefixSource,
|
119 | CURRENT_MODULE,
|
120 | "webpack-sources/PrefixSource",
|
121 | new (class PrefixSourceSerializer {
|
122 | |
123 |
|
124 |
|
125 |
|
126 |
|
127 | serialize(source, { write }) {
|
128 | write(source.getPrefix());
|
129 | write(source.original());
|
130 | }
|
131 |
|
132 | |
133 |
|
134 |
|
135 |
|
136 | deserialize({ read }) {
|
137 | return new PrefixSource(read(), read());
|
138 | }
|
139 | })()
|
140 | );
|
141 |
|
142 | register(
|
143 | ReplaceSource,
|
144 | CURRENT_MODULE,
|
145 | "webpack-sources/ReplaceSource",
|
146 | new (class ReplaceSourceSerializer {
|
147 | |
148 |
|
149 |
|
150 |
|
151 |
|
152 | serialize(source, { write }) {
|
153 | write(source.original());
|
154 | write(source.getName());
|
155 | const replacements = source.getReplacements();
|
156 | write(replacements.length);
|
157 | for (const repl of replacements) {
|
158 | write(repl.start);
|
159 | write(repl.end);
|
160 | }
|
161 | for (const repl of replacements) {
|
162 | write(repl.content);
|
163 | write(repl.name);
|
164 | }
|
165 | }
|
166 |
|
167 | |
168 |
|
169 |
|
170 |
|
171 | deserialize({ read }) {
|
172 | const source = new ReplaceSource(read(), read());
|
173 | const len = read();
|
174 | const startEndBuffer = [];
|
175 | for (let i = 0; i < len; i++) {
|
176 | startEndBuffer.push(read(), read());
|
177 | }
|
178 | let j = 0;
|
179 | for (let i = 0; i < len; i++) {
|
180 | source.replace(
|
181 | startEndBuffer[j++],
|
182 | startEndBuffer[j++],
|
183 | read(),
|
184 | read()
|
185 | );
|
186 | }
|
187 | return source;
|
188 | }
|
189 | })()
|
190 | );
|
191 |
|
192 | register(
|
193 | OriginalSource,
|
194 | CURRENT_MODULE,
|
195 | "webpack-sources/OriginalSource",
|
196 | new (class OriginalSourceSerializer {
|
197 | |
198 |
|
199 |
|
200 |
|
201 |
|
202 | serialize(source, { write }) {
|
203 | write(source.buffer());
|
204 | write(source.getName());
|
205 | }
|
206 |
|
207 | |
208 |
|
209 |
|
210 |
|
211 | deserialize({ read }) {
|
212 | const buffer = read();
|
213 | const name = read();
|
214 | return new OriginalSource(buffer, name);
|
215 | }
|
216 | })()
|
217 | );
|
218 |
|
219 | register(
|
220 | SourceLocation,
|
221 | CURRENT_MODULE,
|
222 | "acorn/SourceLocation",
|
223 | new (class SourceLocationSerializer {
|
224 | |
225 |
|
226 |
|
227 |
|
228 |
|
229 | serialize(loc, { write }) {
|
230 | write(loc.start.line);
|
231 | write(loc.start.column);
|
232 | write(loc.end.line);
|
233 | write(loc.end.column);
|
234 | }
|
235 |
|
236 | |
237 |
|
238 |
|
239 |
|
240 | deserialize({ read }) {
|
241 | return {
|
242 | start: {
|
243 | line: read(),
|
244 | column: read()
|
245 | },
|
246 | end: {
|
247 | line: read(),
|
248 | column: read()
|
249 | }
|
250 | };
|
251 | }
|
252 | })()
|
253 | );
|
254 |
|
255 | register(
|
256 | Position,
|
257 | CURRENT_MODULE,
|
258 | "acorn/Position",
|
259 | new (class PositionSerializer {
|
260 | |
261 |
|
262 |
|
263 |
|
264 |
|
265 | serialize(pos, { write }) {
|
266 | write(pos.line);
|
267 | write(pos.column);
|
268 | }
|
269 |
|
270 | |
271 |
|
272 |
|
273 |
|
274 | deserialize({ read }) {
|
275 | return {
|
276 | line: read(),
|
277 | column: read()
|
278 | };
|
279 | }
|
280 | })()
|
281 | );
|
282 |
|
283 | register(
|
284 | SourceMapSource,
|
285 | CURRENT_MODULE,
|
286 | "webpack-sources/SourceMapSource",
|
287 | new (class SourceMapSourceSerializer {
|
288 | |
289 |
|
290 |
|
291 |
|
292 |
|
293 | serialize(source, { write }) {
|
294 | write(source.getArgsAsBuffers());
|
295 | }
|
296 |
|
297 | |
298 |
|
299 |
|
300 |
|
301 | deserialize({ read }) {
|
302 |
|
303 | return new SourceMapSource(...read());
|
304 | }
|
305 | })()
|
306 | );
|
307 |
|
308 | register(
|
309 | ValidationError,
|
310 | CURRENT_MODULE,
|
311 | "schema-utils/ValidationError",
|
312 | new (class ValidationErrorSerializer {
|
313 |
|
314 | |
315 |
|
316 |
|
317 |
|
318 |
|
319 | serialize(error, { write }) {
|
320 | write(error.errors);
|
321 | write(error.schema);
|
322 | write({
|
323 | name: error.headerName,
|
324 | baseDataPath: error.baseDataPath,
|
325 | postFormatter: error.postFormatter
|
326 | });
|
327 | }
|
328 |
|
329 | |
330 |
|
331 |
|
332 |
|
333 | deserialize({ read }) {
|
334 | return new ValidationError(read(), read(), read());
|
335 | }
|
336 | })()
|
337 | );
|