@depup/webpack-sources 3.3.4-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/lib/CachedSource.js +419 -0
- package/lib/CompatSource.js +109 -0
- package/lib/ConcatSource.js +398 -0
- package/lib/OriginalSource.js +202 -0
- package/lib/PrefixSource.js +162 -0
- package/lib/RawSource.js +140 -0
- package/lib/ReplaceSource.js +557 -0
- package/lib/SizeOnlySource.js +71 -0
- package/lib/Source.js +89 -0
- package/lib/SourceMapSource.js +367 -0
- package/lib/helpers/createMappingsSerializer.js +225 -0
- package/lib/helpers/getFromStreamChunks.js +159 -0
- package/lib/helpers/getGeneratedSourceInfo.js +44 -0
- package/lib/helpers/getName.js +21 -0
- package/lib/helpers/getSource.js +24 -0
- package/lib/helpers/readMappings.js +120 -0
- package/lib/helpers/splitIntoLines.js +33 -0
- package/lib/helpers/splitIntoPotentialTokens.js +53 -0
- package/lib/helpers/streamAndGetSourceAndMap.js +123 -0
- package/lib/helpers/streamChunks.js +62 -0
- package/lib/helpers/streamChunksOfCombinedSourceMap.js +366 -0
- package/lib/helpers/streamChunksOfRawSource.js +54 -0
- package/lib/helpers/streamChunksOfSourceMap.js +499 -0
- package/lib/helpers/stringBufferUtils.js +117 -0
- package/lib/index.js +120 -0
- package/package.json +71 -0
- package/types.d.ts +461 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Tobias Koppers @sokra
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
const getGeneratedSourceInfo = require("./getGeneratedSourceInfo");
|
|
9
|
+
const getSource = require("./getSource");
|
|
10
|
+
const readMappings = require("./readMappings");
|
|
11
|
+
const splitIntoLines = require("./splitIntoLines");
|
|
12
|
+
|
|
13
|
+
/** @typedef {import("../Source").RawSourceMap} RawSourceMap */
|
|
14
|
+
/** @typedef {import("./getGeneratedSourceInfo").GeneratedSourceInfo} GeneratedSourceInfo */
|
|
15
|
+
/** @typedef {import("./streamChunks").OnChunk} OnChunk */
|
|
16
|
+
/** @typedef {import("./streamChunks").OnName} OnName */
|
|
17
|
+
/** @typedef {import("./streamChunks").OnSource} OnSource */
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* @param {string} source source
|
|
21
|
+
* @param {RawSourceMap} sourceMap source map
|
|
22
|
+
* @param {OnChunk} onChunk on chunk
|
|
23
|
+
* @param {OnSource} onSource on source
|
|
24
|
+
* @param {OnName} onName on name
|
|
25
|
+
* @returns {GeneratedSourceInfo} generated source info
|
|
26
|
+
*/
|
|
27
|
+
const streamChunksOfSourceMapFull = (
|
|
28
|
+
source,
|
|
29
|
+
sourceMap,
|
|
30
|
+
onChunk,
|
|
31
|
+
onSource,
|
|
32
|
+
onName,
|
|
33
|
+
) => {
|
|
34
|
+
const lines = splitIntoLines(source);
|
|
35
|
+
if (lines.length === 0) {
|
|
36
|
+
return {
|
|
37
|
+
generatedLine: 1,
|
|
38
|
+
generatedColumn: 0,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const { sources, sourcesContent, names, mappings } = sourceMap;
|
|
42
|
+
for (let i = 0; i < sources.length; i++) {
|
|
43
|
+
onSource(
|
|
44
|
+
i,
|
|
45
|
+
getSource(sourceMap, i),
|
|
46
|
+
(sourcesContent && sourcesContent[i]) || undefined,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
if (names) {
|
|
50
|
+
for (let i = 0; i < names.length; i++) {
|
|
51
|
+
onName(i, names[i]);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const lastLine = lines[lines.length - 1];
|
|
56
|
+
const lastNewLine = lastLine.endsWith("\n");
|
|
57
|
+
const finalLine = lastNewLine ? lines.length + 1 : lines.length;
|
|
58
|
+
const finalColumn = lastNewLine ? 0 : lastLine.length;
|
|
59
|
+
|
|
60
|
+
let currentGeneratedLine = 1;
|
|
61
|
+
let currentGeneratedColumn = 0;
|
|
62
|
+
|
|
63
|
+
let mappingActive = false;
|
|
64
|
+
let activeMappingSourceIndex = -1;
|
|
65
|
+
let activeMappingOriginalLine = -1;
|
|
66
|
+
let activeMappingOriginalColumn = -1;
|
|
67
|
+
let activeMappingNameIndex = -1;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param {number} generatedLine generated line
|
|
71
|
+
* @param {number} generatedColumn generated column
|
|
72
|
+
* @param {number} sourceIndex source index
|
|
73
|
+
* @param {number} originalLine original line
|
|
74
|
+
* @param {number} originalColumn original column
|
|
75
|
+
* @param {number} nameIndex name index
|
|
76
|
+
* @returns {void}
|
|
77
|
+
*/
|
|
78
|
+
const onMapping = (
|
|
79
|
+
generatedLine,
|
|
80
|
+
generatedColumn,
|
|
81
|
+
sourceIndex,
|
|
82
|
+
originalLine,
|
|
83
|
+
originalColumn,
|
|
84
|
+
nameIndex,
|
|
85
|
+
) => {
|
|
86
|
+
if (mappingActive && currentGeneratedLine <= lines.length) {
|
|
87
|
+
let chunk;
|
|
88
|
+
const mappingLine = currentGeneratedLine;
|
|
89
|
+
const mappingColumn = currentGeneratedColumn;
|
|
90
|
+
const line = lines[currentGeneratedLine - 1];
|
|
91
|
+
if (generatedLine !== currentGeneratedLine) {
|
|
92
|
+
chunk = line.slice(currentGeneratedColumn);
|
|
93
|
+
currentGeneratedLine++;
|
|
94
|
+
currentGeneratedColumn = 0;
|
|
95
|
+
} else {
|
|
96
|
+
chunk = line.slice(currentGeneratedColumn, generatedColumn);
|
|
97
|
+
currentGeneratedColumn = generatedColumn;
|
|
98
|
+
}
|
|
99
|
+
if (chunk) {
|
|
100
|
+
onChunk(
|
|
101
|
+
chunk,
|
|
102
|
+
mappingLine,
|
|
103
|
+
mappingColumn,
|
|
104
|
+
activeMappingSourceIndex,
|
|
105
|
+
activeMappingOriginalLine,
|
|
106
|
+
activeMappingOriginalColumn,
|
|
107
|
+
activeMappingNameIndex,
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
mappingActive = false;
|
|
111
|
+
}
|
|
112
|
+
if (generatedLine > currentGeneratedLine && currentGeneratedColumn > 0) {
|
|
113
|
+
if (currentGeneratedLine <= lines.length) {
|
|
114
|
+
const chunk = lines[currentGeneratedLine - 1].slice(
|
|
115
|
+
currentGeneratedColumn,
|
|
116
|
+
);
|
|
117
|
+
onChunk(
|
|
118
|
+
chunk,
|
|
119
|
+
currentGeneratedLine,
|
|
120
|
+
currentGeneratedColumn,
|
|
121
|
+
-1,
|
|
122
|
+
-1,
|
|
123
|
+
-1,
|
|
124
|
+
-1,
|
|
125
|
+
);
|
|
126
|
+
}
|
|
127
|
+
currentGeneratedLine++;
|
|
128
|
+
currentGeneratedColumn = 0;
|
|
129
|
+
}
|
|
130
|
+
while (generatedLine > currentGeneratedLine) {
|
|
131
|
+
if (currentGeneratedLine <= lines.length) {
|
|
132
|
+
onChunk(
|
|
133
|
+
lines[currentGeneratedLine - 1],
|
|
134
|
+
currentGeneratedLine,
|
|
135
|
+
0,
|
|
136
|
+
-1,
|
|
137
|
+
-1,
|
|
138
|
+
-1,
|
|
139
|
+
-1,
|
|
140
|
+
);
|
|
141
|
+
}
|
|
142
|
+
currentGeneratedLine++;
|
|
143
|
+
}
|
|
144
|
+
if (generatedColumn > currentGeneratedColumn) {
|
|
145
|
+
if (currentGeneratedLine <= lines.length) {
|
|
146
|
+
const chunk = lines[currentGeneratedLine - 1].slice(
|
|
147
|
+
currentGeneratedColumn,
|
|
148
|
+
generatedColumn,
|
|
149
|
+
);
|
|
150
|
+
onChunk(
|
|
151
|
+
chunk,
|
|
152
|
+
currentGeneratedLine,
|
|
153
|
+
currentGeneratedColumn,
|
|
154
|
+
-1,
|
|
155
|
+
-1,
|
|
156
|
+
-1,
|
|
157
|
+
-1,
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
currentGeneratedColumn = generatedColumn;
|
|
161
|
+
}
|
|
162
|
+
if (
|
|
163
|
+
sourceIndex >= 0 &&
|
|
164
|
+
(generatedLine < finalLine ||
|
|
165
|
+
(generatedLine === finalLine && generatedColumn < finalColumn))
|
|
166
|
+
) {
|
|
167
|
+
mappingActive = true;
|
|
168
|
+
activeMappingSourceIndex = sourceIndex;
|
|
169
|
+
activeMappingOriginalLine = originalLine;
|
|
170
|
+
activeMappingOriginalColumn = originalColumn;
|
|
171
|
+
activeMappingNameIndex = nameIndex;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
readMappings(mappings, onMapping);
|
|
175
|
+
onMapping(finalLine, finalColumn, -1, -1, -1, -1);
|
|
176
|
+
return {
|
|
177
|
+
generatedLine: finalLine,
|
|
178
|
+
generatedColumn: finalColumn,
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* @param {string} source source
|
|
184
|
+
* @param {RawSourceMap} sourceMap source map
|
|
185
|
+
* @param {OnChunk} onChunk on chunk
|
|
186
|
+
* @param {OnSource} onSource on source
|
|
187
|
+
* @param {OnName} _onName on name
|
|
188
|
+
* @returns {GeneratedSourceInfo} generated source info
|
|
189
|
+
*/
|
|
190
|
+
const streamChunksOfSourceMapLinesFull = (
|
|
191
|
+
source,
|
|
192
|
+
sourceMap,
|
|
193
|
+
onChunk,
|
|
194
|
+
onSource,
|
|
195
|
+
_onName,
|
|
196
|
+
) => {
|
|
197
|
+
const lines = splitIntoLines(source);
|
|
198
|
+
if (lines.length === 0) {
|
|
199
|
+
return {
|
|
200
|
+
generatedLine: 1,
|
|
201
|
+
generatedColumn: 0,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
const { sources, sourcesContent, mappings } = sourceMap;
|
|
205
|
+
for (let i = 0; i < sources.length; i++) {
|
|
206
|
+
onSource(
|
|
207
|
+
i,
|
|
208
|
+
getSource(sourceMap, i),
|
|
209
|
+
(sourcesContent && sourcesContent[i]) || undefined,
|
|
210
|
+
);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
let currentGeneratedLine = 1;
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @param {number} generatedLine generated line
|
|
217
|
+
* @param {number} _generatedColumn generated column
|
|
218
|
+
* @param {number} sourceIndex source index
|
|
219
|
+
* @param {number} originalLine original line
|
|
220
|
+
* @param {number} originalColumn original column
|
|
221
|
+
* @param {number} _nameIndex name index
|
|
222
|
+
* @returns {void}
|
|
223
|
+
*/
|
|
224
|
+
const onMapping = (
|
|
225
|
+
generatedLine,
|
|
226
|
+
_generatedColumn,
|
|
227
|
+
sourceIndex,
|
|
228
|
+
originalLine,
|
|
229
|
+
originalColumn,
|
|
230
|
+
_nameIndex,
|
|
231
|
+
) => {
|
|
232
|
+
if (
|
|
233
|
+
sourceIndex < 0 ||
|
|
234
|
+
generatedLine < currentGeneratedLine ||
|
|
235
|
+
generatedLine > lines.length
|
|
236
|
+
) {
|
|
237
|
+
return;
|
|
238
|
+
}
|
|
239
|
+
while (generatedLine > currentGeneratedLine) {
|
|
240
|
+
if (currentGeneratedLine <= lines.length) {
|
|
241
|
+
onChunk(
|
|
242
|
+
lines[currentGeneratedLine - 1],
|
|
243
|
+
currentGeneratedLine,
|
|
244
|
+
0,
|
|
245
|
+
-1,
|
|
246
|
+
-1,
|
|
247
|
+
-1,
|
|
248
|
+
-1,
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
currentGeneratedLine++;
|
|
252
|
+
}
|
|
253
|
+
if (generatedLine <= lines.length) {
|
|
254
|
+
onChunk(
|
|
255
|
+
lines[generatedLine - 1],
|
|
256
|
+
generatedLine,
|
|
257
|
+
0,
|
|
258
|
+
sourceIndex,
|
|
259
|
+
originalLine,
|
|
260
|
+
originalColumn,
|
|
261
|
+
-1,
|
|
262
|
+
);
|
|
263
|
+
currentGeneratedLine++;
|
|
264
|
+
}
|
|
265
|
+
};
|
|
266
|
+
readMappings(mappings, onMapping);
|
|
267
|
+
for (; currentGeneratedLine <= lines.length; currentGeneratedLine++) {
|
|
268
|
+
onChunk(
|
|
269
|
+
lines[currentGeneratedLine - 1],
|
|
270
|
+
currentGeneratedLine,
|
|
271
|
+
0,
|
|
272
|
+
-1,
|
|
273
|
+
-1,
|
|
274
|
+
-1,
|
|
275
|
+
-1,
|
|
276
|
+
);
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const lastLine = lines[lines.length - 1];
|
|
280
|
+
const lastNewLine = lastLine.endsWith("\n");
|
|
281
|
+
|
|
282
|
+
const finalLine = lastNewLine ? lines.length + 1 : lines.length;
|
|
283
|
+
const finalColumn = lastNewLine ? 0 : lastLine.length;
|
|
284
|
+
|
|
285
|
+
return {
|
|
286
|
+
generatedLine: finalLine,
|
|
287
|
+
generatedColumn: finalColumn,
|
|
288
|
+
};
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* @param {string} source source
|
|
293
|
+
* @param {RawSourceMap} sourceMap source map
|
|
294
|
+
* @param {OnChunk} onChunk on chunk
|
|
295
|
+
* @param {OnSource} onSource on source
|
|
296
|
+
* @param {OnName} onName on name
|
|
297
|
+
* @returns {GeneratedSourceInfo} generated source info
|
|
298
|
+
*/
|
|
299
|
+
const streamChunksOfSourceMapFinal = (
|
|
300
|
+
source,
|
|
301
|
+
sourceMap,
|
|
302
|
+
onChunk,
|
|
303
|
+
onSource,
|
|
304
|
+
onName,
|
|
305
|
+
) => {
|
|
306
|
+
const result = getGeneratedSourceInfo(source);
|
|
307
|
+
const { generatedLine: finalLine, generatedColumn: finalColumn } = result;
|
|
308
|
+
|
|
309
|
+
if (finalLine === 1 && finalColumn === 0) return result;
|
|
310
|
+
const { sources, sourcesContent, names, mappings } = sourceMap;
|
|
311
|
+
for (let i = 0; i < sources.length; i++) {
|
|
312
|
+
onSource(
|
|
313
|
+
i,
|
|
314
|
+
getSource(sourceMap, i),
|
|
315
|
+
(sourcesContent && sourcesContent[i]) || undefined,
|
|
316
|
+
);
|
|
317
|
+
}
|
|
318
|
+
if (names) {
|
|
319
|
+
for (let i = 0; i < names.length; i++) {
|
|
320
|
+
onName(i, names[i]);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
let mappingActiveLine = 0;
|
|
325
|
+
|
|
326
|
+
/**
|
|
327
|
+
* @param {number} generatedLine generated line
|
|
328
|
+
* @param {number} generatedColumn generated column
|
|
329
|
+
* @param {number} sourceIndex source index
|
|
330
|
+
* @param {number} originalLine original line
|
|
331
|
+
* @param {number} originalColumn original column
|
|
332
|
+
* @param {number} nameIndex name index
|
|
333
|
+
* @returns {void}
|
|
334
|
+
*/
|
|
335
|
+
const onMapping = (
|
|
336
|
+
generatedLine,
|
|
337
|
+
generatedColumn,
|
|
338
|
+
sourceIndex,
|
|
339
|
+
originalLine,
|
|
340
|
+
originalColumn,
|
|
341
|
+
nameIndex,
|
|
342
|
+
) => {
|
|
343
|
+
if (
|
|
344
|
+
generatedLine >= /** @type {number} */ (finalLine) &&
|
|
345
|
+
(generatedColumn >= /** @type {number} */ (finalColumn) ||
|
|
346
|
+
generatedLine > /** @type {number} */ (finalLine))
|
|
347
|
+
) {
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
if (sourceIndex >= 0) {
|
|
351
|
+
onChunk(
|
|
352
|
+
undefined,
|
|
353
|
+
generatedLine,
|
|
354
|
+
generatedColumn,
|
|
355
|
+
sourceIndex,
|
|
356
|
+
originalLine,
|
|
357
|
+
originalColumn,
|
|
358
|
+
nameIndex,
|
|
359
|
+
);
|
|
360
|
+
mappingActiveLine = generatedLine;
|
|
361
|
+
} else if (mappingActiveLine === generatedLine) {
|
|
362
|
+
onChunk(undefined, generatedLine, generatedColumn, -1, -1, -1, -1);
|
|
363
|
+
mappingActiveLine = 0;
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
readMappings(mappings, onMapping);
|
|
367
|
+
return result;
|
|
368
|
+
};
|
|
369
|
+
|
|
370
|
+
/**
|
|
371
|
+
* @param {string} source source
|
|
372
|
+
* @param {RawSourceMap} sourceMap source map
|
|
373
|
+
* @param {OnChunk} onChunk on chunk
|
|
374
|
+
* @param {OnSource} onSource on source
|
|
375
|
+
* @param {OnName} _onName on name
|
|
376
|
+
* @returns {GeneratedSourceInfo} generated source info
|
|
377
|
+
*/
|
|
378
|
+
const streamChunksOfSourceMapLinesFinal = (
|
|
379
|
+
source,
|
|
380
|
+
sourceMap,
|
|
381
|
+
onChunk,
|
|
382
|
+
onSource,
|
|
383
|
+
_onName,
|
|
384
|
+
) => {
|
|
385
|
+
const result = getGeneratedSourceInfo(source);
|
|
386
|
+
const { generatedLine, generatedColumn } = result;
|
|
387
|
+
if (generatedLine === 1 && generatedColumn === 0) {
|
|
388
|
+
return {
|
|
389
|
+
generatedLine: 1,
|
|
390
|
+
generatedColumn: 0,
|
|
391
|
+
};
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
const { sources, sourcesContent, mappings } = sourceMap;
|
|
395
|
+
for (let i = 0; i < sources.length; i++) {
|
|
396
|
+
onSource(
|
|
397
|
+
i,
|
|
398
|
+
getSource(sourceMap, i),
|
|
399
|
+
(sourcesContent && sourcesContent[i]) || undefined,
|
|
400
|
+
);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
const finalLine =
|
|
404
|
+
generatedColumn === 0
|
|
405
|
+
? /** @type {number} */ (generatedLine) - 1
|
|
406
|
+
: /** @type {number} */ (generatedLine);
|
|
407
|
+
|
|
408
|
+
let currentGeneratedLine = 1;
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* @param {number} generatedLine generated line
|
|
412
|
+
* @param {number} _generatedColumn generated column
|
|
413
|
+
* @param {number} sourceIndex source index
|
|
414
|
+
* @param {number} originalLine original line
|
|
415
|
+
* @param {number} originalColumn original column
|
|
416
|
+
* @param {number} _nameIndex name index
|
|
417
|
+
* @returns {void}
|
|
418
|
+
*/
|
|
419
|
+
const onMapping = (
|
|
420
|
+
generatedLine,
|
|
421
|
+
_generatedColumn,
|
|
422
|
+
sourceIndex,
|
|
423
|
+
originalLine,
|
|
424
|
+
originalColumn,
|
|
425
|
+
_nameIndex,
|
|
426
|
+
) => {
|
|
427
|
+
if (
|
|
428
|
+
sourceIndex >= 0 &&
|
|
429
|
+
currentGeneratedLine <= generatedLine &&
|
|
430
|
+
generatedLine <= finalLine
|
|
431
|
+
) {
|
|
432
|
+
onChunk(
|
|
433
|
+
undefined,
|
|
434
|
+
generatedLine,
|
|
435
|
+
0,
|
|
436
|
+
sourceIndex,
|
|
437
|
+
originalLine,
|
|
438
|
+
originalColumn,
|
|
439
|
+
-1,
|
|
440
|
+
);
|
|
441
|
+
currentGeneratedLine = generatedLine + 1;
|
|
442
|
+
}
|
|
443
|
+
};
|
|
444
|
+
readMappings(mappings, onMapping);
|
|
445
|
+
return result;
|
|
446
|
+
};
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* @param {string} source source
|
|
450
|
+
* @param {RawSourceMap} sourceMap source map
|
|
451
|
+
* @param {OnChunk} onChunk on chunk
|
|
452
|
+
* @param {OnSource} onSource on source
|
|
453
|
+
* @param {OnName} onName on name
|
|
454
|
+
* @param {boolean} finalSource final source
|
|
455
|
+
* @param {boolean} columns columns
|
|
456
|
+
* @returns {GeneratedSourceInfo} generated source info
|
|
457
|
+
*/
|
|
458
|
+
module.exports = (
|
|
459
|
+
source,
|
|
460
|
+
sourceMap,
|
|
461
|
+
onChunk,
|
|
462
|
+
onSource,
|
|
463
|
+
onName,
|
|
464
|
+
finalSource,
|
|
465
|
+
columns,
|
|
466
|
+
) => {
|
|
467
|
+
if (columns) {
|
|
468
|
+
return finalSource
|
|
469
|
+
? streamChunksOfSourceMapFinal(
|
|
470
|
+
source,
|
|
471
|
+
sourceMap,
|
|
472
|
+
onChunk,
|
|
473
|
+
onSource,
|
|
474
|
+
onName,
|
|
475
|
+
)
|
|
476
|
+
: streamChunksOfSourceMapFull(
|
|
477
|
+
source,
|
|
478
|
+
sourceMap,
|
|
479
|
+
onChunk,
|
|
480
|
+
onSource,
|
|
481
|
+
onName,
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
return finalSource
|
|
485
|
+
? streamChunksOfSourceMapLinesFinal(
|
|
486
|
+
source,
|
|
487
|
+
sourceMap,
|
|
488
|
+
onChunk,
|
|
489
|
+
onSource,
|
|
490
|
+
onName,
|
|
491
|
+
)
|
|
492
|
+
: streamChunksOfSourceMapLinesFull(
|
|
493
|
+
source,
|
|
494
|
+
sourceMap,
|
|
495
|
+
onChunk,
|
|
496
|
+
onSource,
|
|
497
|
+
onName,
|
|
498
|
+
);
|
|
499
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/*
|
|
2
|
+
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
+
Author Mark Knichel @mknichel
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
"use strict";
|
|
7
|
+
|
|
8
|
+
let dualStringBufferCaching = true;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @returns {boolean} Whether the optimization to cache copies of both the
|
|
12
|
+
* string and buffer version of source content is enabled. This is enabled by
|
|
13
|
+
* default to improve performance but can consume more memory since values are
|
|
14
|
+
* stored twice.
|
|
15
|
+
*/
|
|
16
|
+
function isDualStringBufferCachingEnabled() {
|
|
17
|
+
return dualStringBufferCaching;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Enables an optimization to save both string and buffer in memory to avoid
|
|
22
|
+
* repeat conversions between the two formats when they are requested. This
|
|
23
|
+
* is enabled by default. This option can improve performance but can consume
|
|
24
|
+
* additional memory since values are stored twice.
|
|
25
|
+
* @returns {void}
|
|
26
|
+
*/
|
|
27
|
+
function enableDualStringBufferCaching() {
|
|
28
|
+
dualStringBufferCaching = true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Disables the optimization to save both string and buffer in memory. This
|
|
33
|
+
* may increase performance but should reduce memory usage in the Webpack
|
|
34
|
+
* compiler.
|
|
35
|
+
* @returns {void}
|
|
36
|
+
*/
|
|
37
|
+
function disableDualStringBufferCaching() {
|
|
38
|
+
dualStringBufferCaching = false;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const interningStringMap = new Map();
|
|
42
|
+
|
|
43
|
+
let enableStringInterningRefCount = 0;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* @returns {boolean} value
|
|
47
|
+
*/
|
|
48
|
+
function isStringInterningEnabled() {
|
|
49
|
+
return enableStringInterningRefCount > 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Starts a memory optimization to avoid repeat copies of the same string in
|
|
54
|
+
* memory by caching a single reference to the string. This can reduce memory
|
|
55
|
+
* usage if the same string is repeated many times in the compiler, such as
|
|
56
|
+
* when Webpack layers are used with the same files.
|
|
57
|
+
*
|
|
58
|
+
* {@link exitStringInterningRange} should be called when string interning is
|
|
59
|
+
* no longer necessary to free up the memory used by the interned strings. If
|
|
60
|
+
* {@link enterStringInterningRange} has been called multiple times, then
|
|
61
|
+
* this method may not immediately free all the memory until
|
|
62
|
+
* {@link exitStringInterningRange} has been called to end all string
|
|
63
|
+
* interning ranges.
|
|
64
|
+
* @returns {void}
|
|
65
|
+
*/
|
|
66
|
+
function enterStringInterningRange() {
|
|
67
|
+
enableStringInterningRefCount++;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Stops the current string interning range. Once all string interning ranges
|
|
72
|
+
* have been exited, this method will free all the memory used by the interned
|
|
73
|
+
* strings. This method should be called once for each time that
|
|
74
|
+
* {@link enterStringInterningRange} was called.
|
|
75
|
+
* @returns {void}
|
|
76
|
+
*/
|
|
77
|
+
function exitStringInterningRange() {
|
|
78
|
+
if (--enableStringInterningRefCount <= 0) {
|
|
79
|
+
interningStringMap.clear();
|
|
80
|
+
enableStringInterningRefCount = 0;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Saves the string in a map to ensure that only one copy of the string exists
|
|
86
|
+
* in memory at a given time. This is controlled by {@link enableStringInterning}
|
|
87
|
+
* and {@link disableStringInterning}. Callers are expect to manage the memory
|
|
88
|
+
* of the interned strings by calling {@link disableStringInterning} after the
|
|
89
|
+
* compiler no longer needs to save the interned memory.
|
|
90
|
+
* @param {string} str A string to be interned.
|
|
91
|
+
* @returns {string} The original string or a reference to an existing string of the same value if it has already been interned.
|
|
92
|
+
*/
|
|
93
|
+
function internString(str) {
|
|
94
|
+
if (
|
|
95
|
+
!isStringInterningEnabled() ||
|
|
96
|
+
!str ||
|
|
97
|
+
str.length < 128 ||
|
|
98
|
+
typeof str !== "string"
|
|
99
|
+
) {
|
|
100
|
+
return str;
|
|
101
|
+
}
|
|
102
|
+
let internedString = interningStringMap.get(str);
|
|
103
|
+
if (internedString === undefined) {
|
|
104
|
+
internedString = str;
|
|
105
|
+
interningStringMap.set(str, internedString);
|
|
106
|
+
}
|
|
107
|
+
return internedString;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
module.exports = {
|
|
111
|
+
disableDualStringBufferCaching,
|
|
112
|
+
enableDualStringBufferCaching,
|
|
113
|
+
enterStringInterningRange,
|
|
114
|
+
exitStringInterningRange,
|
|
115
|
+
internString,
|
|
116
|
+
isDualStringBufferCachingEnabled,
|
|
117
|
+
};
|