rollup 4.62.2 → 4.62.3
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/dist/bin/rollup +13 -17
- package/dist/es/getLogFilter.js +2 -2
- package/dist/es/parseAst.js +2 -2
- package/dist/es/rollup.js +2 -2
- package/dist/es/shared/node-entry.js +652 -889
- package/dist/es/shared/parseAst.js +2 -2
- package/dist/es/shared/watch.js +4 -4
- package/dist/getLogFilter.js +2 -2
- package/dist/loadConfigFile.js +2 -2
- package/dist/parseAst.js +2 -2
- package/dist/rollup.d.ts +6 -23
- package/dist/rollup.js +2 -2
- package/dist/shared/fsevents-importer.js +2 -2
- package/dist/shared/index.js +2 -2
- package/dist/shared/loadConfigFile.js +2 -2
- package/dist/shared/parseAst.js +23 -23
- package/dist/shared/rollup.js +824 -1061
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +4 -4
- package/package.json +60 -60
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v4.62.
|
|
4
|
-
|
|
3
|
+
Rollup.js v4.62.3
|
|
4
|
+
Sun, 26 Jul 2026 14:58:21 GMT - commit a80a1974c584bfa8b694fb5d1a20f3fa75ebaf0a
|
|
5
5
|
|
|
6
6
|
https://github.com/rollup/rollup
|
|
7
7
|
|
|
@@ -27,8 +27,8 @@ function _mergeNamespaces(n, m) {
|
|
|
27
27
|
return Object.defineProperty(n, Symbol.toStringTag, { value: 'Module' });
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
var version = "4.62.
|
|
31
|
-
const
|
|
30
|
+
var version = "4.62.3";
|
|
31
|
+
const pkg = {
|
|
32
32
|
version: version};
|
|
33
33
|
|
|
34
34
|
// src/vlq.ts
|
|
@@ -203,214 +203,160 @@ function encode(decoded) {
|
|
|
203
203
|
return writer.flush();
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
-
|
|
206
|
+
//#region src/BitSet.ts
|
|
207
|
+
var BitSet = class BitSet {
|
|
207
208
|
constructor(arg) {
|
|
208
209
|
this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
|
209
210
|
}
|
|
210
|
-
|
|
211
211
|
add(n) {
|
|
212
212
|
this.bits[n >> 5] |= 1 << (n & 31);
|
|
213
213
|
}
|
|
214
|
-
|
|
215
214
|
has(n) {
|
|
216
|
-
return !!(this.bits[n >> 5] &
|
|
215
|
+
return !!(this.bits[n >> 5] & 1 << (n & 31));
|
|
217
216
|
}
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
|
|
217
|
+
};
|
|
218
|
+
//#endregion
|
|
219
|
+
//#region src/Chunk.ts
|
|
220
|
+
var Chunk$1 = class Chunk {
|
|
221
221
|
constructor(start, end, content) {
|
|
222
222
|
this.start = start;
|
|
223
223
|
this.end = end;
|
|
224
224
|
this.original = content;
|
|
225
|
-
|
|
226
|
-
this.
|
|
227
|
-
this.outro = '';
|
|
228
|
-
|
|
225
|
+
this.intro = "";
|
|
226
|
+
this.outro = "";
|
|
229
227
|
this.content = content;
|
|
230
228
|
this.storeName = false;
|
|
231
229
|
this.edited = false;
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
this.previous = null;
|
|
235
|
-
this.next = null;
|
|
236
|
-
}
|
|
230
|
+
this.previous = null;
|
|
231
|
+
this.next = null;
|
|
237
232
|
}
|
|
238
|
-
|
|
239
233
|
appendLeft(content) {
|
|
240
234
|
this.outro += content;
|
|
241
235
|
}
|
|
242
|
-
|
|
243
236
|
appendRight(content) {
|
|
244
237
|
this.intro = this.intro + content;
|
|
245
238
|
}
|
|
246
|
-
|
|
247
239
|
clone() {
|
|
248
240
|
const chunk = new Chunk(this.start, this.end, this.original);
|
|
249
|
-
|
|
250
241
|
chunk.intro = this.intro;
|
|
251
242
|
chunk.outro = this.outro;
|
|
252
243
|
chunk.content = this.content;
|
|
253
244
|
chunk.storeName = this.storeName;
|
|
254
245
|
chunk.edited = this.edited;
|
|
255
|
-
|
|
256
246
|
return chunk;
|
|
257
247
|
}
|
|
258
|
-
|
|
259
248
|
contains(index) {
|
|
260
249
|
return this.start < index && index < this.end;
|
|
261
250
|
}
|
|
262
|
-
|
|
263
251
|
eachNext(fn) {
|
|
264
|
-
|
|
252
|
+
fn(this);
|
|
253
|
+
let chunk = this.next;
|
|
265
254
|
while (chunk) {
|
|
266
255
|
fn(chunk);
|
|
267
256
|
chunk = chunk.next;
|
|
268
257
|
}
|
|
269
258
|
}
|
|
270
|
-
|
|
271
259
|
eachPrevious(fn) {
|
|
272
|
-
|
|
260
|
+
fn(this);
|
|
261
|
+
let chunk = this.previous;
|
|
273
262
|
while (chunk) {
|
|
274
263
|
fn(chunk);
|
|
275
264
|
chunk = chunk.previous;
|
|
276
265
|
}
|
|
277
266
|
}
|
|
278
|
-
|
|
279
267
|
edit(content, storeName, contentOnly) {
|
|
280
268
|
this.content = content;
|
|
281
269
|
if (!contentOnly) {
|
|
282
|
-
this.intro =
|
|
283
|
-
this.outro =
|
|
270
|
+
this.intro = "";
|
|
271
|
+
this.outro = "";
|
|
284
272
|
}
|
|
285
273
|
this.storeName = storeName;
|
|
286
|
-
|
|
287
274
|
this.edited = true;
|
|
288
|
-
|
|
289
275
|
return this;
|
|
290
276
|
}
|
|
291
|
-
|
|
292
277
|
prependLeft(content) {
|
|
293
278
|
this.outro = content + this.outro;
|
|
294
279
|
}
|
|
295
|
-
|
|
296
280
|
prependRight(content) {
|
|
297
281
|
this.intro = content + this.intro;
|
|
298
282
|
}
|
|
299
|
-
|
|
300
283
|
reset() {
|
|
301
|
-
this.intro =
|
|
302
|
-
this.outro =
|
|
284
|
+
this.intro = "";
|
|
285
|
+
this.outro = "";
|
|
303
286
|
if (this.edited) {
|
|
304
287
|
this.content = this.original;
|
|
305
288
|
this.storeName = false;
|
|
306
289
|
this.edited = false;
|
|
307
290
|
}
|
|
308
291
|
}
|
|
309
|
-
|
|
310
292
|
split(index) {
|
|
311
293
|
const sliceIndex = index - this.start;
|
|
312
|
-
|
|
313
294
|
const originalBefore = this.original.slice(0, sliceIndex);
|
|
314
295
|
const originalAfter = this.original.slice(sliceIndex);
|
|
315
|
-
|
|
316
296
|
this.original = originalBefore;
|
|
317
|
-
|
|
318
297
|
const newChunk = new Chunk(index, this.end, originalAfter);
|
|
319
298
|
newChunk.outro = this.outro;
|
|
320
|
-
this.outro =
|
|
321
|
-
|
|
299
|
+
this.outro = "";
|
|
322
300
|
this.end = index;
|
|
323
|
-
|
|
324
301
|
if (this.edited) {
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
// ' test'.trim()
|
|
329
|
-
// split -> ' ' + 'test'
|
|
330
|
-
// ✔️ edit -> '' + 'test'
|
|
331
|
-
// ✖️ edit -> 'test' + ''
|
|
332
|
-
// TODO is this block necessary?...
|
|
333
|
-
newChunk.edit('', false);
|
|
334
|
-
this.content = '';
|
|
335
|
-
} else {
|
|
336
|
-
this.content = originalBefore;
|
|
337
|
-
}
|
|
338
|
-
|
|
302
|
+
newChunk.edit("", false);
|
|
303
|
+
this.content = "";
|
|
304
|
+
} else this.content = originalBefore;
|
|
339
305
|
newChunk.next = this.next;
|
|
340
306
|
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
341
307
|
newChunk.previous = this;
|
|
342
308
|
this.next = newChunk;
|
|
343
|
-
|
|
344
309
|
return newChunk;
|
|
345
310
|
}
|
|
346
|
-
|
|
347
311
|
toString() {
|
|
348
312
|
return this.intro + this.content + this.outro;
|
|
349
313
|
}
|
|
350
|
-
|
|
351
314
|
trimEnd(rx) {
|
|
352
|
-
this.outro = this.outro.replace(rx,
|
|
315
|
+
this.outro = this.outro.replace(rx, "");
|
|
353
316
|
if (this.outro.length) return true;
|
|
354
|
-
|
|
355
|
-
const trimmed = this.content.replace(rx, '');
|
|
356
|
-
|
|
317
|
+
const trimmed = this.content.replace(rx, "");
|
|
357
318
|
if (trimmed.length) {
|
|
358
319
|
if (trimmed !== this.content) {
|
|
359
|
-
this.split(this.start + trimmed.length).edit(
|
|
360
|
-
if (this.edited)
|
|
361
|
-
// save the change, if it has been edited
|
|
362
|
-
this.edit(trimmed, this.storeName, true);
|
|
363
|
-
}
|
|
320
|
+
this.split(this.start + trimmed.length).edit("", void 0, true);
|
|
321
|
+
if (this.edited) this.edit(trimmed, this.storeName, true);
|
|
364
322
|
}
|
|
365
323
|
return true;
|
|
366
324
|
} else {
|
|
367
|
-
this.edit(
|
|
368
|
-
|
|
369
|
-
this.intro = this.intro.replace(rx, '');
|
|
325
|
+
this.edit("", void 0, true);
|
|
326
|
+
this.intro = this.intro.replace(rx, "");
|
|
370
327
|
if (this.intro.length) return true;
|
|
371
328
|
}
|
|
372
329
|
}
|
|
373
|
-
|
|
374
330
|
trimStart(rx) {
|
|
375
|
-
this.intro = this.intro.replace(rx,
|
|
331
|
+
this.intro = this.intro.replace(rx, "");
|
|
376
332
|
if (this.intro.length) return true;
|
|
377
|
-
|
|
378
|
-
const trimmed = this.content.replace(rx, '');
|
|
379
|
-
|
|
333
|
+
const trimmed = this.content.replace(rx, "");
|
|
380
334
|
if (trimmed.length) {
|
|
381
335
|
if (trimmed !== this.content) {
|
|
382
336
|
const newChunk = this.split(this.end - trimmed.length);
|
|
383
|
-
if (this.edited)
|
|
384
|
-
|
|
385
|
-
newChunk.edit(trimmed, this.storeName, true);
|
|
386
|
-
}
|
|
387
|
-
this.edit('', undefined, true);
|
|
337
|
+
if (this.edited) newChunk.edit(trimmed, this.storeName, true);
|
|
338
|
+
this.edit("", void 0, true);
|
|
388
339
|
}
|
|
389
340
|
return true;
|
|
390
341
|
} else {
|
|
391
|
-
this.edit(
|
|
392
|
-
|
|
393
|
-
this.outro = this.outro.replace(rx, '');
|
|
342
|
+
this.edit("", void 0, true);
|
|
343
|
+
this.outro = this.outro.replace(rx, "");
|
|
394
344
|
if (this.outro.length) return true;
|
|
395
345
|
}
|
|
396
346
|
}
|
|
397
347
|
};
|
|
398
|
-
|
|
348
|
+
//#endregion
|
|
349
|
+
//#region src/SourceMap.ts
|
|
399
350
|
function getBtoa() {
|
|
400
|
-
if (typeof globalThis !==
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
|
|
407
|
-
};
|
|
408
|
-
}
|
|
351
|
+
if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
|
|
352
|
+
const buffer = globalThis["Buffer"];
|
|
353
|
+
if (buffer) return (str) => buffer.from(str, "utf-8").toString("base64");
|
|
354
|
+
return () => {
|
|
355
|
+
throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
|
|
356
|
+
};
|
|
409
357
|
}
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
class SourceMap {
|
|
358
|
+
const btoa = /* #__PURE__ */ getBtoa();
|
|
359
|
+
var SourceMap = class {
|
|
414
360
|
constructor(properties) {
|
|
415
361
|
this.version = 3;
|
|
416
362
|
this.file = properties.file;
|
|
@@ -418,103 +364,87 @@ class SourceMap {
|
|
|
418
364
|
this.sourcesContent = properties.sourcesContent;
|
|
419
365
|
this.names = properties.names;
|
|
420
366
|
this.mappings = encode(properties.mappings);
|
|
421
|
-
if (typeof properties.x_google_ignoreList !==
|
|
422
|
-
|
|
423
|
-
}
|
|
424
|
-
if (typeof properties.debugId !== 'undefined') {
|
|
425
|
-
this.debugId = properties.debugId;
|
|
426
|
-
}
|
|
367
|
+
if (typeof properties.x_google_ignoreList !== "undefined") this.x_google_ignoreList = properties.x_google_ignoreList;
|
|
368
|
+
if (typeof properties.debugId !== "undefined") this.debugId = properties.debugId;
|
|
427
369
|
}
|
|
428
|
-
|
|
370
|
+
/**
|
|
371
|
+
* Returns the equivalent of `JSON.stringify(map)`
|
|
372
|
+
*/
|
|
429
373
|
toString() {
|
|
430
374
|
return JSON.stringify(this);
|
|
431
375
|
}
|
|
432
|
-
|
|
376
|
+
/**
|
|
377
|
+
* Returns a DataURI containing the sourcemap. Useful for doing this sort of thing:
|
|
378
|
+
* `generateMap(options?: SourceMapOptions): SourceMap;`
|
|
379
|
+
*/
|
|
433
380
|
toUrl() {
|
|
434
|
-
return
|
|
381
|
+
return `data:application/json;charset=utf-8;base64,${btoa(this.toString())}`;
|
|
435
382
|
}
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
const
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
return null;
|
|
446
|
-
}
|
|
447
|
-
|
|
448
|
-
// More lines tabbed than spaced? Assume tabs, and
|
|
449
|
-
// default to tabs in the case of a tie (or nothing
|
|
450
|
-
// to go on)
|
|
451
|
-
if (tabbed.length >= spaced.length) {
|
|
452
|
-
return '\t';
|
|
383
|
+
};
|
|
384
|
+
//#endregion
|
|
385
|
+
//#region src/utils/getLocator.ts
|
|
386
|
+
function getLocator(source) {
|
|
387
|
+
const originalLines = source.split("\n");
|
|
388
|
+
const lineOffsets = [];
|
|
389
|
+
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
390
|
+
lineOffsets.push(pos);
|
|
391
|
+
pos += originalLines[i].length + 1;
|
|
453
392
|
}
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
393
|
+
return function locate(index) {
|
|
394
|
+
let i = 0;
|
|
395
|
+
let j = lineOffsets.length;
|
|
396
|
+
while (i < j) {
|
|
397
|
+
const m = i + j >> 1;
|
|
398
|
+
if (index < lineOffsets[m]) j = m;
|
|
399
|
+
else i = m + 1;
|
|
400
|
+
}
|
|
401
|
+
const line = i - 1;
|
|
402
|
+
return {
|
|
403
|
+
line,
|
|
404
|
+
column: index - lineOffsets[line]
|
|
405
|
+
};
|
|
406
|
+
};
|
|
462
407
|
}
|
|
463
|
-
|
|
408
|
+
//#endregion
|
|
409
|
+
//#region src/utils/getRelativePath.ts
|
|
464
410
|
function getRelativePath(from, to) {
|
|
465
411
|
const fromParts = from.split(/[/\\]/);
|
|
466
412
|
const toParts = to.split(/[/\\]/);
|
|
467
|
-
|
|
468
|
-
fromParts.pop(); // get dirname
|
|
469
|
-
|
|
413
|
+
fromParts.pop();
|
|
470
414
|
while (fromParts[0] === toParts[0]) {
|
|
471
415
|
fromParts.shift();
|
|
472
416
|
toParts.shift();
|
|
473
417
|
}
|
|
474
|
-
|
|
475
418
|
if (fromParts.length) {
|
|
476
419
|
let i = fromParts.length;
|
|
477
|
-
while (i--) fromParts[i] =
|
|
420
|
+
while (i--) fromParts[i] = "..";
|
|
478
421
|
}
|
|
479
|
-
|
|
480
|
-
return fromParts.concat(toParts).join('/');
|
|
422
|
+
return fromParts.concat(toParts).join("/");
|
|
481
423
|
}
|
|
482
|
-
|
|
424
|
+
//#endregion
|
|
425
|
+
//#region src/utils/guessIndent.ts
|
|
426
|
+
function guessIndent(code) {
|
|
427
|
+
const lines = code.split("\n");
|
|
428
|
+
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
429
|
+
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
430
|
+
if (tabbed.length === 0 && spaced.length === 0) return null;
|
|
431
|
+
if (tabbed.length >= spaced.length) return " ";
|
|
432
|
+
const min = spaced.reduce((previous, current) => {
|
|
433
|
+
const numSpaces = /^ +/.exec(current)[0].length;
|
|
434
|
+
return Math.min(numSpaces, previous);
|
|
435
|
+
}, Infinity);
|
|
436
|
+
return " ".repeat(min);
|
|
437
|
+
}
|
|
438
|
+
//#endregion
|
|
439
|
+
//#region src/utils/isObject.ts
|
|
483
440
|
const toString = Object.prototype.toString;
|
|
484
|
-
|
|
485
441
|
function isObject(thing) {
|
|
486
|
-
return toString.call(thing) ===
|
|
442
|
+
return toString.call(thing) === "[object Object]";
|
|
487
443
|
}
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
const originalLines = source.split('\n');
|
|
491
|
-
const lineOffsets = [];
|
|
492
|
-
|
|
493
|
-
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
494
|
-
lineOffsets.push(pos);
|
|
495
|
-
pos += originalLines[i].length + 1;
|
|
496
|
-
}
|
|
497
|
-
|
|
498
|
-
return function locate(index) {
|
|
499
|
-
let i = 0;
|
|
500
|
-
let j = lineOffsets.length;
|
|
501
|
-
while (i < j) {
|
|
502
|
-
const m = (i + j) >> 1;
|
|
503
|
-
if (index < lineOffsets[m]) {
|
|
504
|
-
j = m;
|
|
505
|
-
} else {
|
|
506
|
-
i = m + 1;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
const line = i - 1;
|
|
510
|
-
const column = index - lineOffsets[line];
|
|
511
|
-
return { line, column };
|
|
512
|
-
};
|
|
513
|
-
}
|
|
514
|
-
|
|
444
|
+
//#endregion
|
|
445
|
+
//#region src/utils/Mappings.ts
|
|
515
446
|
const wordRegex = /\w/;
|
|
516
|
-
|
|
517
|
-
class Mappings {
|
|
447
|
+
var Mappings = class {
|
|
518
448
|
constructor(hires) {
|
|
519
449
|
this.hires = hires;
|
|
520
450
|
this.generatedCodeLine = 0;
|
|
@@ -523,52 +453,47 @@ class Mappings {
|
|
|
523
453
|
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
524
454
|
this.pending = null;
|
|
525
455
|
}
|
|
526
|
-
|
|
527
456
|
addEdit(sourceIndex, content, loc, nameIndex) {
|
|
528
457
|
if (content.length) {
|
|
529
458
|
const contentLengthMinusOne = content.length - 1;
|
|
530
|
-
let contentLineEnd = content.indexOf(
|
|
459
|
+
let contentLineEnd = content.indexOf("\n", 0);
|
|
531
460
|
let previousContentLineEnd = -1;
|
|
532
|
-
// Loop through each line in the content and add a segment, but stop if the last line is empty,
|
|
533
|
-
// else code afterwards would fill one line too many
|
|
534
461
|
while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
|
|
535
|
-
const segment = [
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
462
|
+
const segment = [
|
|
463
|
+
this.generatedCodeColumn,
|
|
464
|
+
sourceIndex,
|
|
465
|
+
loc.line,
|
|
466
|
+
loc.column
|
|
467
|
+
];
|
|
468
|
+
if (nameIndex >= 0) segment.push(nameIndex);
|
|
539
469
|
this.rawSegments.push(segment);
|
|
540
|
-
|
|
541
470
|
this.generatedCodeLine += 1;
|
|
542
471
|
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
543
472
|
this.generatedCodeColumn = 0;
|
|
544
|
-
|
|
545
473
|
previousContentLineEnd = contentLineEnd;
|
|
546
|
-
contentLineEnd = content.indexOf(
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
550
|
-
if (nameIndex >= 0) {
|
|
551
|
-
segment.push(nameIndex);
|
|
474
|
+
contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
|
|
552
475
|
}
|
|
476
|
+
const segment = [
|
|
477
|
+
this.generatedCodeColumn,
|
|
478
|
+
sourceIndex,
|
|
479
|
+
loc.line,
|
|
480
|
+
loc.column
|
|
481
|
+
];
|
|
482
|
+
if (nameIndex >= 0) segment.push(nameIndex);
|
|
553
483
|
this.rawSegments.push(segment);
|
|
554
|
-
|
|
555
484
|
this.advance(content.slice(previousContentLineEnd + 1));
|
|
556
485
|
} else if (this.pending) {
|
|
557
486
|
this.rawSegments.push(this.pending);
|
|
558
487
|
this.advance(content);
|
|
559
488
|
}
|
|
560
|
-
|
|
561
489
|
this.pending = null;
|
|
562
490
|
}
|
|
563
|
-
|
|
564
491
|
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
565
492
|
let originalCharIndex = chunk.start;
|
|
566
493
|
let first = true;
|
|
567
|
-
// when iterating each char, check if it's in a word boundary
|
|
568
494
|
let charInHiresBoundary = false;
|
|
569
|
-
|
|
570
495
|
while (originalCharIndex < chunk.end) {
|
|
571
|
-
if (original[originalCharIndex] ===
|
|
496
|
+
if (original[originalCharIndex] === "\n") {
|
|
572
497
|
loc.line += 1;
|
|
573
498
|
loc.column = 0;
|
|
574
499
|
this.generatedCodeLine += 1;
|
|
@@ -578,42 +503,34 @@ class Mappings {
|
|
|
578
503
|
charInHiresBoundary = false;
|
|
579
504
|
} else {
|
|
580
505
|
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
581
|
-
const segment = [
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
charInHiresBoundary = true;
|
|
590
|
-
}
|
|
591
|
-
} else {
|
|
592
|
-
// for non-word char, end the boundary by pushing a segment
|
|
506
|
+
const segment = [
|
|
507
|
+
this.generatedCodeColumn,
|
|
508
|
+
sourceIndex,
|
|
509
|
+
loc.line,
|
|
510
|
+
loc.column
|
|
511
|
+
];
|
|
512
|
+
if (this.hires === "boundary") if (wordRegex.test(original[originalCharIndex])) {
|
|
513
|
+
if (!charInHiresBoundary) {
|
|
593
514
|
this.rawSegments.push(segment);
|
|
594
|
-
charInHiresBoundary =
|
|
515
|
+
charInHiresBoundary = true;
|
|
595
516
|
}
|
|
596
517
|
} else {
|
|
597
518
|
this.rawSegments.push(segment);
|
|
519
|
+
charInHiresBoundary = false;
|
|
598
520
|
}
|
|
521
|
+
else this.rawSegments.push(segment);
|
|
599
522
|
}
|
|
600
|
-
|
|
601
523
|
loc.column += 1;
|
|
602
524
|
this.generatedCodeColumn += 1;
|
|
603
525
|
first = false;
|
|
604
526
|
}
|
|
605
|
-
|
|
606
527
|
originalCharIndex += 1;
|
|
607
528
|
}
|
|
608
|
-
|
|
609
529
|
this.pending = null;
|
|
610
530
|
}
|
|
611
|
-
|
|
612
531
|
advance(str) {
|
|
613
532
|
if (!str) return;
|
|
614
|
-
|
|
615
|
-
const lines = str.split('\n');
|
|
616
|
-
|
|
533
|
+
const lines = str.split("\n");
|
|
617
534
|
if (lines.length > 1) {
|
|
618
535
|
for (let i = 0; i < lines.length - 1; i++) {
|
|
619
536
|
this.generatedCodeLine++;
|
|
@@ -621,1029 +538,872 @@ class Mappings {
|
|
|
621
538
|
}
|
|
622
539
|
this.generatedCodeColumn = 0;
|
|
623
540
|
}
|
|
624
|
-
|
|
625
541
|
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
626
542
|
}
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
543
|
+
};
|
|
544
|
+
//#endregion
|
|
545
|
+
//#region src/MagicString.ts
|
|
546
|
+
const n = "\n";
|
|
547
|
+
const NEWLINE_CHAR = "\n".charCodeAt(0);
|
|
548
|
+
const CR_CHAR = "\r".charCodeAt(0);
|
|
631
549
|
const warned = {
|
|
632
550
|
insertLeft: false,
|
|
633
551
|
insertRight: false,
|
|
634
|
-
storeName: false
|
|
552
|
+
storeName: false
|
|
635
553
|
};
|
|
636
|
-
|
|
637
|
-
class MagicString {
|
|
554
|
+
var MagicString = class MagicString {
|
|
638
555
|
constructor(string, options = {}) {
|
|
639
556
|
const chunk = new Chunk$1(0, string.length, string);
|
|
640
|
-
|
|
641
557
|
Object.defineProperties(this, {
|
|
642
|
-
original: {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
558
|
+
original: {
|
|
559
|
+
writable: true,
|
|
560
|
+
value: string
|
|
561
|
+
},
|
|
562
|
+
outro: {
|
|
563
|
+
writable: true,
|
|
564
|
+
value: ""
|
|
565
|
+
},
|
|
566
|
+
intro: {
|
|
567
|
+
writable: true,
|
|
568
|
+
value: ""
|
|
569
|
+
},
|
|
570
|
+
firstChunk: {
|
|
571
|
+
writable: true,
|
|
572
|
+
value: chunk
|
|
573
|
+
},
|
|
574
|
+
lastChunk: {
|
|
575
|
+
writable: true,
|
|
576
|
+
value: chunk
|
|
577
|
+
},
|
|
578
|
+
lastSearchedChunk: {
|
|
579
|
+
writable: true,
|
|
580
|
+
value: chunk
|
|
581
|
+
},
|
|
582
|
+
byStart: {
|
|
583
|
+
writable: true,
|
|
584
|
+
value: {}
|
|
585
|
+
},
|
|
586
|
+
byEnd: {
|
|
587
|
+
writable: true,
|
|
588
|
+
value: {}
|
|
589
|
+
},
|
|
590
|
+
filename: {
|
|
591
|
+
writable: true,
|
|
592
|
+
value: options.filename
|
|
593
|
+
},
|
|
594
|
+
indentExclusionRanges: {
|
|
595
|
+
writable: true,
|
|
596
|
+
value: options.indentExclusionRanges
|
|
597
|
+
},
|
|
598
|
+
sourcemapLocations: {
|
|
599
|
+
writable: true,
|
|
600
|
+
value: new BitSet()
|
|
601
|
+
},
|
|
602
|
+
storedNames: {
|
|
603
|
+
writable: true,
|
|
604
|
+
value: {}
|
|
605
|
+
},
|
|
606
|
+
indentStr: {
|
|
607
|
+
writable: true,
|
|
608
|
+
value: void 0
|
|
609
|
+
},
|
|
610
|
+
ignoreList: {
|
|
611
|
+
writable: true,
|
|
612
|
+
value: options.ignoreList
|
|
613
|
+
},
|
|
614
|
+
offset: {
|
|
615
|
+
writable: true,
|
|
616
|
+
value: options.offset || 0
|
|
617
|
+
}
|
|
657
618
|
});
|
|
658
|
-
|
|
659
619
|
this.byStart[0] = chunk;
|
|
660
620
|
this.byEnd[string.length] = chunk;
|
|
661
621
|
}
|
|
662
|
-
|
|
622
|
+
/**
|
|
623
|
+
* Adds the specified character index (with respect to the original string) to sourcemap mappings, if `hires` is false.
|
|
624
|
+
*/
|
|
663
625
|
addSourcemapLocation(char) {
|
|
664
626
|
this.sourcemapLocations.add(char);
|
|
665
627
|
}
|
|
666
|
-
|
|
628
|
+
/**
|
|
629
|
+
* Appends the specified content to the end of the string.
|
|
630
|
+
*/
|
|
667
631
|
append(content) {
|
|
668
|
-
if (typeof content !==
|
|
669
|
-
|
|
632
|
+
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
670
633
|
this.outro += content;
|
|
671
634
|
return this;
|
|
672
635
|
}
|
|
673
|
-
|
|
636
|
+
/**
|
|
637
|
+
* Appends the specified content at the index in the original string.
|
|
638
|
+
* If a range *ending* with index is subsequently moved, the insert will be moved with it.
|
|
639
|
+
* See also `s.prependLeft(...)`.
|
|
640
|
+
*/
|
|
674
641
|
appendLeft(index, content) {
|
|
675
642
|
index = index + this.offset;
|
|
676
|
-
|
|
677
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
678
|
-
|
|
643
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
679
644
|
this._split(index);
|
|
680
|
-
|
|
681
645
|
const chunk = this.byEnd[index];
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
chunk.appendLeft(content);
|
|
685
|
-
} else {
|
|
686
|
-
this.intro += content;
|
|
687
|
-
}
|
|
646
|
+
if (chunk) chunk.appendLeft(content);
|
|
647
|
+
else this.intro += content;
|
|
688
648
|
return this;
|
|
689
649
|
}
|
|
690
|
-
|
|
650
|
+
/**
|
|
651
|
+
* Appends the specified content at the index in the original string.
|
|
652
|
+
* If a range *starting* with index is subsequently moved, the insert will be moved with it.
|
|
653
|
+
* See also `s.prependRight(...)`.
|
|
654
|
+
*/
|
|
691
655
|
appendRight(index, content) {
|
|
692
656
|
index = index + this.offset;
|
|
693
|
-
|
|
694
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
695
|
-
|
|
657
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
696
658
|
this._split(index);
|
|
697
|
-
|
|
698
659
|
const chunk = this.byStart[index];
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
chunk.appendRight(content);
|
|
702
|
-
} else {
|
|
703
|
-
this.outro += content;
|
|
704
|
-
}
|
|
660
|
+
if (chunk) chunk.appendRight(content);
|
|
661
|
+
else this.outro += content;
|
|
705
662
|
return this;
|
|
706
663
|
}
|
|
707
|
-
|
|
664
|
+
/**
|
|
665
|
+
* Does what you'd expect.
|
|
666
|
+
*/
|
|
708
667
|
clone() {
|
|
709
|
-
const cloned = new MagicString(this.original, {
|
|
710
|
-
|
|
668
|
+
const cloned = new MagicString(this.original, {
|
|
669
|
+
filename: this.filename,
|
|
670
|
+
offset: this.offset
|
|
671
|
+
});
|
|
711
672
|
let originalChunk = this.firstChunk;
|
|
712
|
-
let clonedChunk =
|
|
713
|
-
|
|
673
|
+
let clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
|
|
714
674
|
while (originalChunk) {
|
|
715
675
|
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
716
676
|
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
717
|
-
|
|
718
677
|
const nextOriginalChunk = originalChunk.next;
|
|
719
678
|
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
720
|
-
|
|
721
679
|
if (nextClonedChunk) {
|
|
722
680
|
clonedChunk.next = nextClonedChunk;
|
|
723
681
|
nextClonedChunk.previous = clonedChunk;
|
|
724
|
-
|
|
725
682
|
clonedChunk = nextClonedChunk;
|
|
726
683
|
}
|
|
727
|
-
|
|
728
684
|
originalChunk = nextOriginalChunk;
|
|
729
685
|
}
|
|
730
|
-
|
|
731
686
|
cloned.lastChunk = clonedChunk;
|
|
732
|
-
|
|
733
|
-
if (this.indentExclusionRanges) {
|
|
734
|
-
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
735
|
-
}
|
|
736
|
-
|
|
687
|
+
if (this.indentExclusionRanges) cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
737
688
|
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
738
|
-
|
|
739
689
|
cloned.intro = this.intro;
|
|
740
690
|
cloned.outro = this.outro;
|
|
741
|
-
|
|
742
691
|
return cloned;
|
|
743
692
|
}
|
|
744
|
-
|
|
693
|
+
/**
|
|
694
|
+
* Generates a sourcemap object with raw mappings in array form, rather than encoded as a string.
|
|
695
|
+
* Useful if you need to manipulate the sourcemap further, but most of the time you will use `generateMap` instead.
|
|
696
|
+
*/
|
|
745
697
|
generateDecodedMap(options) {
|
|
746
698
|
options = options || {};
|
|
747
|
-
|
|
748
699
|
const sourceIndex = 0;
|
|
749
700
|
const names = Object.keys(this.storedNames);
|
|
750
701
|
const mappings = new Mappings(options.hires);
|
|
751
|
-
|
|
752
702
|
const locate = getLocator(this.original);
|
|
753
|
-
|
|
754
|
-
if (this.intro) {
|
|
755
|
-
mappings.advance(this.intro);
|
|
756
|
-
}
|
|
757
|
-
|
|
703
|
+
if (this.intro) mappings.advance(this.intro);
|
|
758
704
|
this.firstChunk.eachNext((chunk) => {
|
|
759
705
|
const loc = locate(chunk.start);
|
|
760
|
-
|
|
761
706
|
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
mappings.addEdit(
|
|
765
|
-
sourceIndex,
|
|
766
|
-
chunk.content,
|
|
767
|
-
loc,
|
|
768
|
-
chunk.storeName ? names.indexOf(chunk.original) : -1,
|
|
769
|
-
);
|
|
770
|
-
} else {
|
|
771
|
-
mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
|
|
772
|
-
}
|
|
773
|
-
|
|
707
|
+
if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
|
|
708
|
+
else mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
|
|
774
709
|
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
775
710
|
});
|
|
776
|
-
|
|
777
|
-
if (this.outro) {
|
|
778
|
-
mappings.advance(this.outro);
|
|
779
|
-
}
|
|
780
|
-
|
|
711
|
+
if (this.outro) mappings.advance(this.outro);
|
|
781
712
|
return {
|
|
782
|
-
file: options.file ? options.file.split(/[/\\]/).pop() :
|
|
783
|
-
sources: [
|
|
784
|
-
|
|
785
|
-
],
|
|
786
|
-
sourcesContent: options.includeContent ? [this.original] : undefined,
|
|
713
|
+
file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
|
|
714
|
+
sources: [options.source ? getRelativePath(options.file || "", options.source) : options.file || ""],
|
|
715
|
+
sourcesContent: options.includeContent ? [this.original] : void 0,
|
|
787
716
|
names,
|
|
788
717
|
mappings: mappings.raw,
|
|
789
|
-
x_google_ignoreList: this.ignoreList ? [sourceIndex] :
|
|
718
|
+
x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
|
|
790
719
|
};
|
|
791
720
|
}
|
|
792
|
-
|
|
721
|
+
/**
|
|
722
|
+
* Generates a version 3 sourcemap.
|
|
723
|
+
*/
|
|
793
724
|
generateMap(options) {
|
|
794
725
|
return new SourceMap(this.generateDecodedMap(options));
|
|
795
726
|
}
|
|
796
|
-
|
|
727
|
+
/** @internal */
|
|
797
728
|
_ensureindentStr() {
|
|
798
|
-
if (this.indentStr ===
|
|
799
|
-
this.indentStr = guessIndent(this.original);
|
|
800
|
-
}
|
|
729
|
+
if (this.indentStr === void 0) this.indentStr = guessIndent(this.original);
|
|
801
730
|
}
|
|
802
|
-
|
|
731
|
+
/** @internal */
|
|
803
732
|
_getRawIndentString() {
|
|
804
733
|
this._ensureindentStr();
|
|
805
734
|
return this.indentStr;
|
|
806
735
|
}
|
|
807
|
-
|
|
808
736
|
getIndentString() {
|
|
809
737
|
this._ensureindentStr();
|
|
810
|
-
return this.indentStr === null ?
|
|
738
|
+
return this.indentStr === null ? " " : this.indentStr;
|
|
811
739
|
}
|
|
812
|
-
|
|
813
740
|
indent(indentStr, options) {
|
|
814
741
|
const pattern = /^[^\r\n]/gm;
|
|
815
|
-
|
|
816
742
|
if (isObject(indentStr)) {
|
|
817
743
|
options = indentStr;
|
|
818
|
-
indentStr =
|
|
744
|
+
indentStr = void 0;
|
|
819
745
|
}
|
|
820
|
-
|
|
821
|
-
if (indentStr === undefined) {
|
|
746
|
+
if (indentStr === void 0) {
|
|
822
747
|
this._ensureindentStr();
|
|
823
|
-
indentStr = this.indentStr ||
|
|
748
|
+
indentStr = this.indentStr || " ";
|
|
824
749
|
}
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
750
|
+
if (indentStr === "") return this;
|
|
751
|
+
const resolvedIndentStr = indentStr;
|
|
828
752
|
options = options || {};
|
|
829
|
-
|
|
830
|
-
// Process exclusion ranges
|
|
831
753
|
const isExcluded = {};
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
|
|
836
|
-
exclusions.forEach((exclusion) => {
|
|
837
|
-
for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
|
|
838
|
-
isExcluded[i] = true;
|
|
839
|
-
}
|
|
840
|
-
});
|
|
841
|
-
}
|
|
842
|
-
|
|
754
|
+
if (options.exclude) (typeof options.exclude[0] === "number" ? [options.exclude] : options.exclude).forEach((exclusion) => {
|
|
755
|
+
for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded[i] = true;
|
|
756
|
+
});
|
|
843
757
|
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
844
758
|
const replacer = (match) => {
|
|
845
|
-
if (shouldIndentNextCharacter) return `${
|
|
759
|
+
if (shouldIndentNextCharacter) return `${resolvedIndentStr}${match}`;
|
|
846
760
|
shouldIndentNextCharacter = true;
|
|
847
761
|
return match;
|
|
848
762
|
};
|
|
849
|
-
|
|
850
763
|
this.intro = this.intro.replace(pattern, replacer);
|
|
851
|
-
|
|
852
764
|
let charIndex = 0;
|
|
853
765
|
let chunk = this.firstChunk;
|
|
854
|
-
|
|
766
|
+
const indentAt = (index) => {
|
|
767
|
+
shouldIndentNextCharacter = false;
|
|
768
|
+
if (index === chunk.start) chunk.prependRight(resolvedIndentStr);
|
|
769
|
+
else {
|
|
770
|
+
this._splitChunk(chunk, index);
|
|
771
|
+
chunk = chunk.next;
|
|
772
|
+
chunk.prependRight(resolvedIndentStr);
|
|
773
|
+
}
|
|
774
|
+
};
|
|
855
775
|
while (chunk) {
|
|
856
776
|
const end = chunk.end;
|
|
857
|
-
|
|
858
777
|
if (chunk.edited) {
|
|
859
778
|
if (!isExcluded[charIndex]) {
|
|
860
779
|
chunk.content = chunk.content.replace(pattern, replacer);
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
780
|
+
if (chunk.content.length) shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
|
|
781
|
+
}
|
|
782
|
+
} else if (options.exclude) {
|
|
783
|
+
charIndex = chunk.start;
|
|
784
|
+
while (charIndex < end) {
|
|
785
|
+
if (!isExcluded[charIndex]) {
|
|
786
|
+
const char = this.original.charCodeAt(charIndex);
|
|
787
|
+
if (char === NEWLINE_CHAR) shouldIndentNextCharacter = true;
|
|
788
|
+
else if (char !== CR_CHAR && shouldIndentNextCharacter) indentAt(charIndex);
|
|
864
789
|
}
|
|
790
|
+
charIndex += 1;
|
|
865
791
|
}
|
|
866
792
|
} else {
|
|
867
793
|
charIndex = chunk.start;
|
|
868
|
-
|
|
869
794
|
while (charIndex < end) {
|
|
870
|
-
if (!
|
|
871
|
-
const
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
shouldIndentNextCharacter = false;
|
|
877
|
-
|
|
878
|
-
if (charIndex === chunk.start) {
|
|
879
|
-
chunk.prependRight(indentStr);
|
|
880
|
-
} else {
|
|
881
|
-
this._splitChunk(chunk, charIndex);
|
|
882
|
-
chunk = chunk.next;
|
|
883
|
-
chunk.prependRight(indentStr);
|
|
884
|
-
}
|
|
885
|
-
}
|
|
795
|
+
if (!shouldIndentNextCharacter) {
|
|
796
|
+
const nextLine = this.original.indexOf(n, charIndex);
|
|
797
|
+
if (nextLine === -1 || nextLine >= end) break;
|
|
798
|
+
shouldIndentNextCharacter = true;
|
|
799
|
+
charIndex = nextLine + 1;
|
|
800
|
+
continue;
|
|
886
801
|
}
|
|
887
|
-
|
|
802
|
+
const char = this.original.charCodeAt(charIndex);
|
|
803
|
+
if (char === NEWLINE_CHAR || char === CR_CHAR) {
|
|
804
|
+
charIndex += 1;
|
|
805
|
+
continue;
|
|
806
|
+
}
|
|
807
|
+
indentAt(charIndex);
|
|
888
808
|
charIndex += 1;
|
|
889
809
|
}
|
|
890
810
|
}
|
|
891
|
-
|
|
892
811
|
charIndex = chunk.end;
|
|
893
812
|
chunk = chunk.next;
|
|
894
813
|
}
|
|
895
|
-
|
|
896
814
|
this.outro = this.outro.replace(pattern, replacer);
|
|
897
|
-
|
|
898
815
|
return this;
|
|
899
816
|
}
|
|
900
|
-
|
|
817
|
+
/** @internal */
|
|
901
818
|
insert() {
|
|
902
|
-
throw new Error(
|
|
903
|
-
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
|
|
904
|
-
);
|
|
819
|
+
throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)");
|
|
905
820
|
}
|
|
906
|
-
|
|
821
|
+
/** @internal */
|
|
907
822
|
insertLeft(index, content) {
|
|
908
823
|
if (!warned.insertLeft) {
|
|
909
|
-
console.warn(
|
|
910
|
-
'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
|
|
911
|
-
);
|
|
824
|
+
console.warn("magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead");
|
|
912
825
|
warned.insertLeft = true;
|
|
913
826
|
}
|
|
914
|
-
|
|
915
827
|
return this.appendLeft(index, content);
|
|
916
828
|
}
|
|
917
|
-
|
|
829
|
+
/** @internal */
|
|
918
830
|
insertRight(index, content) {
|
|
919
831
|
if (!warned.insertRight) {
|
|
920
|
-
console.warn(
|
|
921
|
-
'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
|
|
922
|
-
);
|
|
832
|
+
console.warn("magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead");
|
|
923
833
|
warned.insertRight = true;
|
|
924
834
|
}
|
|
925
|
-
|
|
926
835
|
return this.prependRight(index, content);
|
|
927
836
|
}
|
|
928
|
-
|
|
837
|
+
/**
|
|
838
|
+
* Moves the characters from `start` and `end` to `index`.
|
|
839
|
+
*/
|
|
929
840
|
move(start, end, index) {
|
|
930
841
|
start = start + this.offset;
|
|
931
842
|
end = end + this.offset;
|
|
932
843
|
index = index + this.offset;
|
|
933
|
-
|
|
934
|
-
if (index >= start && index <= end) throw new Error(
|
|
935
|
-
|
|
844
|
+
if (start === end) return this;
|
|
845
|
+
if (index >= start && index <= end) throw new Error("Cannot move a selection inside itself");
|
|
936
846
|
this._split(start);
|
|
937
847
|
this._split(end);
|
|
938
848
|
this._split(index);
|
|
939
|
-
|
|
940
849
|
const first = this.byStart[start];
|
|
941
850
|
const last = this.byEnd[end];
|
|
942
|
-
|
|
943
851
|
const oldLeft = first.previous;
|
|
944
852
|
const oldRight = last.next;
|
|
945
|
-
|
|
946
853
|
const newRight = this.byStart[index];
|
|
947
854
|
if (!newRight && last === this.lastChunk) return this;
|
|
948
855
|
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
949
|
-
|
|
950
856
|
if (oldLeft) oldLeft.next = oldRight;
|
|
951
857
|
if (oldRight) oldRight.previous = oldLeft;
|
|
952
|
-
|
|
953
858
|
if (newLeft) newLeft.next = first;
|
|
954
859
|
if (newRight) newRight.previous = last;
|
|
955
|
-
|
|
956
860
|
if (!first.previous) this.firstChunk = last.next;
|
|
957
861
|
if (!last.next) {
|
|
958
862
|
this.lastChunk = first.previous;
|
|
959
863
|
this.lastChunk.next = null;
|
|
960
864
|
}
|
|
961
|
-
|
|
962
865
|
first.previous = newLeft;
|
|
963
866
|
last.next = newRight || null;
|
|
964
|
-
|
|
965
867
|
if (!newLeft) this.firstChunk = first;
|
|
966
868
|
if (!newRight) this.lastChunk = last;
|
|
967
869
|
return this;
|
|
968
870
|
}
|
|
969
|
-
|
|
871
|
+
/**
|
|
872
|
+
* Replaces the characters from `start` to `end` with `content`, along with the appended/prepended content in
|
|
873
|
+
* that range. The same restrictions as `s.remove()` apply.
|
|
874
|
+
*
|
|
875
|
+
* The fourth argument is optional. It can have a storeName property - if true, the original name will be stored
|
|
876
|
+
* for later inclusion in a sourcemap's names array - and a contentOnly property which determines whether only
|
|
877
|
+
* the content is overwritten, or anything that was appended/prepended to the range as well.
|
|
878
|
+
*
|
|
879
|
+
* It may be preferred to use `s.update(...)` instead if you wish to avoid overwriting the appended/prepended content.
|
|
880
|
+
*/
|
|
970
881
|
overwrite(start, end, content, options) {
|
|
971
|
-
|
|
972
|
-
return this.update(start, end, content, {
|
|
882
|
+
const optionObject = typeof options === "object" && options ? options : {};
|
|
883
|
+
return this.update(start, end, content, {
|
|
884
|
+
...optionObject,
|
|
885
|
+
overwrite: !optionObject.contentOnly
|
|
886
|
+
});
|
|
973
887
|
}
|
|
974
|
-
|
|
888
|
+
/**
|
|
889
|
+
* Replaces the characters from `start` to `end` with `content`. The same restrictions as `s.remove()` apply.
|
|
890
|
+
*
|
|
891
|
+
* The fourth argument is optional. It can have a storeName property - if true, the original name will be stored
|
|
892
|
+
* for later inclusion in a sourcemap's names array - and an overwrite property which determines whether only
|
|
893
|
+
* the content is overwritten, or anything that was appended/prepended to the range as well.
|
|
894
|
+
*/
|
|
975
895
|
update(start, end, content, options) {
|
|
976
896
|
start = start + this.offset;
|
|
977
897
|
end = end + this.offset;
|
|
978
|
-
|
|
979
|
-
if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
|
|
980
|
-
|
|
898
|
+
if (typeof content !== "string") throw new TypeError("replacement content must be a string");
|
|
981
899
|
if (this.original.length !== 0) {
|
|
982
900
|
while (start < 0) start += this.original.length;
|
|
983
901
|
while (end < 0) end += this.original.length;
|
|
984
902
|
}
|
|
985
|
-
|
|
986
|
-
if (
|
|
987
|
-
if (start === end)
|
|
988
|
-
throw new Error(
|
|
989
|
-
'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
|
|
990
|
-
);
|
|
991
|
-
|
|
903
|
+
if (end > this.original.length) throw new Error("end is out of bounds");
|
|
904
|
+
if (start === end) throw new Error("Cannot overwrite a zero-length range – use appendLeft or prependRight instead");
|
|
992
905
|
this._split(start);
|
|
993
906
|
this._split(end);
|
|
994
|
-
|
|
995
907
|
if (options === true) {
|
|
996
908
|
if (!warned.storeName) {
|
|
997
|
-
console.warn(
|
|
998
|
-
'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
|
|
999
|
-
);
|
|
909
|
+
console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string");
|
|
1000
910
|
warned.storeName = true;
|
|
1001
911
|
}
|
|
1002
|
-
|
|
1003
912
|
options = { storeName: true };
|
|
1004
913
|
}
|
|
1005
|
-
const
|
|
1006
|
-
const
|
|
1007
|
-
|
|
914
|
+
const optionObject = typeof options === "object" && options ? options : {};
|
|
915
|
+
const storeName = optionObject.storeName || false;
|
|
916
|
+
const overwrite = optionObject.overwrite || false;
|
|
1008
917
|
if (storeName) {
|
|
1009
918
|
const original = this.original.slice(start, end);
|
|
1010
919
|
Object.defineProperty(this.storedNames, original, {
|
|
1011
920
|
writable: true,
|
|
1012
921
|
value: true,
|
|
1013
|
-
enumerable: true
|
|
922
|
+
enumerable: true
|
|
1014
923
|
});
|
|
1015
924
|
}
|
|
1016
|
-
|
|
1017
925
|
const first = this.byStart[start];
|
|
1018
926
|
const last = this.byEnd[end];
|
|
1019
|
-
|
|
1020
927
|
if (first) {
|
|
1021
928
|
let chunk = first;
|
|
1022
929
|
while (chunk !== last) {
|
|
1023
|
-
if (chunk.next !== this.byStart[chunk.end])
|
|
1024
|
-
throw new Error('Cannot overwrite across a split point');
|
|
1025
|
-
}
|
|
930
|
+
if (chunk.next !== this.byStart[chunk.end]) throw new Error("Cannot overwrite across a split point");
|
|
1026
931
|
chunk = chunk.next;
|
|
1027
|
-
chunk.edit(
|
|
932
|
+
chunk.edit("", false);
|
|
1028
933
|
}
|
|
1029
|
-
|
|
1030
934
|
first.edit(content, storeName, !overwrite);
|
|
1031
935
|
} else {
|
|
1032
|
-
|
|
1033
|
-
const newChunk = new Chunk$1(start, end, '').edit(content, storeName);
|
|
1034
|
-
|
|
1035
|
-
// TODO last chunk in the array may not be the last chunk, if it's moved...
|
|
936
|
+
const newChunk = new Chunk$1(start, end, "").edit(content, storeName);
|
|
1036
937
|
last.next = newChunk;
|
|
1037
938
|
newChunk.previous = last;
|
|
1038
939
|
}
|
|
1039
940
|
return this;
|
|
1040
941
|
}
|
|
1041
|
-
|
|
942
|
+
/**
|
|
943
|
+
* Prepends the string with the specified content.
|
|
944
|
+
*/
|
|
1042
945
|
prepend(content) {
|
|
1043
|
-
if (typeof content !==
|
|
1044
|
-
|
|
946
|
+
if (typeof content !== "string") throw new TypeError("outro content must be a string");
|
|
1045
947
|
this.intro = content + this.intro;
|
|
1046
948
|
return this;
|
|
1047
949
|
}
|
|
1048
|
-
|
|
950
|
+
/**
|
|
951
|
+
* Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
|
|
952
|
+
*/
|
|
1049
953
|
prependLeft(index, content) {
|
|
1050
954
|
index = index + this.offset;
|
|
1051
|
-
|
|
1052
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
1053
|
-
|
|
955
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
1054
956
|
this._split(index);
|
|
1055
|
-
|
|
1056
957
|
const chunk = this.byEnd[index];
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
chunk.prependLeft(content);
|
|
1060
|
-
} else {
|
|
1061
|
-
this.intro = content + this.intro;
|
|
1062
|
-
}
|
|
958
|
+
if (chunk) chunk.prependLeft(content);
|
|
959
|
+
else this.intro = content + this.intro;
|
|
1063
960
|
return this;
|
|
1064
961
|
}
|
|
1065
|
-
|
|
962
|
+
/**
|
|
963
|
+
* Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
|
|
964
|
+
*/
|
|
1066
965
|
prependRight(index, content) {
|
|
1067
966
|
index = index + this.offset;
|
|
1068
|
-
|
|
1069
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
1070
|
-
|
|
967
|
+
if (typeof content !== "string") throw new TypeError("inserted content must be a string");
|
|
1071
968
|
this._split(index);
|
|
1072
|
-
|
|
1073
969
|
const chunk = this.byStart[index];
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
chunk.prependRight(content);
|
|
1077
|
-
} else {
|
|
1078
|
-
this.outro = content + this.outro;
|
|
1079
|
-
}
|
|
970
|
+
if (chunk) chunk.prependRight(content);
|
|
971
|
+
else this.outro = content + this.outro;
|
|
1080
972
|
return this;
|
|
1081
973
|
}
|
|
1082
|
-
|
|
974
|
+
/**
|
|
975
|
+
* Removes the characters from `start` to `end` (of the original string, **not** the generated string).
|
|
976
|
+
* Removing the same content twice, or making removals that partially overlap, will cause an error.
|
|
977
|
+
*/
|
|
1083
978
|
remove(start, end) {
|
|
1084
979
|
start = start + this.offset;
|
|
1085
980
|
end = end + this.offset;
|
|
1086
|
-
|
|
1087
981
|
if (this.original.length !== 0) {
|
|
1088
982
|
while (start < 0) start += this.original.length;
|
|
1089
983
|
while (end < 0) end += this.original.length;
|
|
1090
984
|
}
|
|
1091
|
-
|
|
1092
985
|
if (start === end) return this;
|
|
1093
|
-
|
|
1094
|
-
if (start
|
|
1095
|
-
if (start > end) throw new Error('end must be greater than start');
|
|
1096
|
-
|
|
986
|
+
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
987
|
+
if (start > end) throw new Error("end must be greater than start");
|
|
1097
988
|
this._split(start);
|
|
1098
989
|
this._split(end);
|
|
1099
|
-
|
|
1100
990
|
let chunk = this.byStart[start];
|
|
1101
|
-
|
|
1102
991
|
while (chunk) {
|
|
1103
|
-
chunk.intro =
|
|
1104
|
-
chunk.outro =
|
|
1105
|
-
chunk.edit(
|
|
1106
|
-
|
|
992
|
+
chunk.intro = "";
|
|
993
|
+
chunk.outro = "";
|
|
994
|
+
chunk.edit("");
|
|
1107
995
|
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
1108
996
|
}
|
|
1109
997
|
return this;
|
|
1110
998
|
}
|
|
1111
|
-
|
|
999
|
+
/**
|
|
1000
|
+
* Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).
|
|
1001
|
+
*/
|
|
1112
1002
|
reset(start, end) {
|
|
1113
1003
|
start = start + this.offset;
|
|
1114
1004
|
end = end + this.offset;
|
|
1115
|
-
|
|
1116
1005
|
if (this.original.length !== 0) {
|
|
1117
1006
|
while (start < 0) start += this.original.length;
|
|
1118
1007
|
while (end < 0) end += this.original.length;
|
|
1119
1008
|
}
|
|
1120
|
-
|
|
1121
1009
|
if (start === end) return this;
|
|
1122
|
-
|
|
1123
|
-
if (start
|
|
1124
|
-
if (start > end) throw new Error('end must be greater than start');
|
|
1125
|
-
|
|
1010
|
+
if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
|
|
1011
|
+
if (start > end) throw new Error("end must be greater than start");
|
|
1126
1012
|
this._split(start);
|
|
1127
1013
|
this._split(end);
|
|
1128
|
-
|
|
1129
1014
|
let chunk = this.byStart[start];
|
|
1130
|
-
|
|
1131
1015
|
while (chunk) {
|
|
1132
1016
|
chunk.reset();
|
|
1133
|
-
|
|
1134
1017
|
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
1135
1018
|
}
|
|
1136
1019
|
return this;
|
|
1137
1020
|
}
|
|
1138
|
-
|
|
1139
1021
|
lastChar() {
|
|
1140
1022
|
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
1141
1023
|
let chunk = this.lastChunk;
|
|
1142
|
-
|
|
1024
|
+
while (chunk) {
|
|
1143
1025
|
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
1144
1026
|
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
1145
1027
|
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
1146
|
-
|
|
1028
|
+
chunk = chunk.previous;
|
|
1029
|
+
}
|
|
1147
1030
|
if (this.intro.length) return this.intro[this.intro.length - 1];
|
|
1148
|
-
return
|
|
1031
|
+
return "";
|
|
1149
1032
|
}
|
|
1150
|
-
|
|
1151
1033
|
lastLine() {
|
|
1152
1034
|
let lineIndex = this.outro.lastIndexOf(n);
|
|
1153
1035
|
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
1154
1036
|
let lineStr = this.outro;
|
|
1155
1037
|
let chunk = this.lastChunk;
|
|
1156
|
-
|
|
1038
|
+
while (chunk) {
|
|
1157
1039
|
if (chunk.outro.length > 0) {
|
|
1158
1040
|
lineIndex = chunk.outro.lastIndexOf(n);
|
|
1159
1041
|
if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
1160
1042
|
lineStr = chunk.outro + lineStr;
|
|
1161
1043
|
}
|
|
1162
|
-
|
|
1163
1044
|
if (chunk.content.length > 0) {
|
|
1164
1045
|
lineIndex = chunk.content.lastIndexOf(n);
|
|
1165
1046
|
if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
|
|
1166
1047
|
lineStr = chunk.content + lineStr;
|
|
1167
1048
|
}
|
|
1168
|
-
|
|
1169
1049
|
if (chunk.intro.length > 0) {
|
|
1170
1050
|
lineIndex = chunk.intro.lastIndexOf(n);
|
|
1171
1051
|
if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
1172
1052
|
lineStr = chunk.intro + lineStr;
|
|
1173
1053
|
}
|
|
1174
|
-
|
|
1054
|
+
chunk = chunk.previous;
|
|
1055
|
+
}
|
|
1175
1056
|
lineIndex = this.intro.lastIndexOf(n);
|
|
1176
1057
|
if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
|
|
1177
1058
|
return this.intro + lineStr;
|
|
1178
1059
|
}
|
|
1179
|
-
|
|
1060
|
+
/**
|
|
1061
|
+
* Returns the content of the generated string that corresponds to the slice between `start` and `end` of the original string.
|
|
1062
|
+
* Throws error if the indices are for characters that were already removed.
|
|
1063
|
+
*/
|
|
1180
1064
|
slice(start = 0, end = this.original.length - this.offset) {
|
|
1181
1065
|
start = start + this.offset;
|
|
1182
1066
|
end = end + this.offset;
|
|
1183
|
-
|
|
1184
1067
|
if (this.original.length !== 0) {
|
|
1185
1068
|
while (start < 0) start += this.original.length;
|
|
1186
1069
|
while (end < 0) end += this.original.length;
|
|
1187
1070
|
}
|
|
1188
|
-
|
|
1189
|
-
let result = '';
|
|
1190
|
-
|
|
1191
|
-
// find start chunk
|
|
1071
|
+
let result = "";
|
|
1192
1072
|
let chunk = this.firstChunk;
|
|
1193
1073
|
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
1194
|
-
|
|
1195
|
-
if (chunk.start < end && chunk.end >= end) {
|
|
1196
|
-
return result;
|
|
1197
|
-
}
|
|
1198
|
-
|
|
1074
|
+
if (chunk.start < end && chunk.end >= end) return result;
|
|
1199
1075
|
chunk = chunk.next;
|
|
1200
1076
|
}
|
|
1201
|
-
|
|
1202
|
-
if (chunk && chunk.edited && chunk.start !== start)
|
|
1203
|
-
throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
1204
|
-
|
|
1077
|
+
if (chunk && chunk.edited && chunk.start !== start) throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
1205
1078
|
const startChunk = chunk;
|
|
1206
1079
|
while (chunk) {
|
|
1207
|
-
if (chunk.intro && (startChunk !== chunk || chunk.start === start))
|
|
1208
|
-
result += chunk.intro;
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1080
|
+
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) result += chunk.intro;
|
|
1211
1081
|
const containsEnd = chunk.start < end && chunk.end >= end;
|
|
1212
|
-
if (containsEnd && chunk.edited && chunk.end !== end)
|
|
1213
|
-
throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
1214
|
-
|
|
1082
|
+
if (containsEnd && chunk.edited && chunk.end !== end) throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
1215
1083
|
const sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
1216
1084
|
const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
1217
|
-
|
|
1218
1085
|
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
1219
|
-
|
|
1220
|
-
if (
|
|
1221
|
-
result += chunk.outro;
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
if (containsEnd) {
|
|
1225
|
-
break;
|
|
1226
|
-
}
|
|
1227
|
-
|
|
1086
|
+
if (chunk.outro && (!containsEnd || chunk.end === end)) result += chunk.outro;
|
|
1087
|
+
if (containsEnd) break;
|
|
1228
1088
|
chunk = chunk.next;
|
|
1229
1089
|
}
|
|
1230
|
-
|
|
1231
1090
|
return result;
|
|
1232
1091
|
}
|
|
1233
|
-
|
|
1234
|
-
|
|
1092
|
+
/**
|
|
1093
|
+
* Returns a clone of `s`, with all content before the `start` and `end` characters of the original string removed.
|
|
1094
|
+
*/
|
|
1235
1095
|
snip(start, end) {
|
|
1236
1096
|
const clone = this.clone();
|
|
1237
1097
|
clone.remove(0, start);
|
|
1238
1098
|
clone.remove(end, clone.original.length);
|
|
1239
|
-
|
|
1240
1099
|
return clone;
|
|
1241
1100
|
}
|
|
1242
|
-
|
|
1101
|
+
/** @internal */
|
|
1243
1102
|
_split(index) {
|
|
1244
1103
|
if (this.byStart[index] || this.byEnd[index]) return;
|
|
1245
|
-
|
|
1246
1104
|
let chunk = this.lastSearchedChunk;
|
|
1247
1105
|
let previousChunk = chunk;
|
|
1248
1106
|
const searchForward = index > chunk.end;
|
|
1249
|
-
|
|
1250
1107
|
while (chunk) {
|
|
1251
1108
|
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
1252
|
-
|
|
1253
1109
|
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
1254
|
-
|
|
1255
|
-
// Prevent infinite loop (e.g. via empty chunks, where start === end)
|
|
1256
1110
|
if (chunk === previousChunk) return;
|
|
1257
|
-
|
|
1258
1111
|
previousChunk = chunk;
|
|
1259
1112
|
}
|
|
1260
1113
|
}
|
|
1261
|
-
|
|
1114
|
+
/** @internal */
|
|
1262
1115
|
_splitChunk(chunk, index) {
|
|
1263
1116
|
if (chunk.edited && chunk.content.length) {
|
|
1264
|
-
// zero-length edited chunks are a special case (overlapping replacements)
|
|
1265
1117
|
const loc = getLocator(this.original)(index);
|
|
1266
|
-
throw new Error(
|
|
1267
|
-
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
|
|
1268
|
-
);
|
|
1118
|
+
throw new Error(`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`);
|
|
1269
1119
|
}
|
|
1270
|
-
|
|
1271
1120
|
const newChunk = chunk.split(index);
|
|
1272
|
-
|
|
1273
1121
|
this.byEnd[index] = chunk;
|
|
1274
1122
|
this.byStart[index] = newChunk;
|
|
1275
1123
|
this.byEnd[newChunk.end] = newChunk;
|
|
1276
|
-
|
|
1277
1124
|
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
1278
|
-
|
|
1279
1125
|
this.lastSearchedChunk = chunk;
|
|
1280
1126
|
return true;
|
|
1281
1127
|
}
|
|
1282
|
-
|
|
1128
|
+
/**
|
|
1129
|
+
* Returns the generated string.
|
|
1130
|
+
*/
|
|
1283
1131
|
toString() {
|
|
1284
1132
|
let str = this.intro;
|
|
1285
|
-
|
|
1286
1133
|
let chunk = this.firstChunk;
|
|
1287
1134
|
while (chunk) {
|
|
1288
1135
|
str += chunk.toString();
|
|
1289
1136
|
chunk = chunk.next;
|
|
1290
1137
|
}
|
|
1291
|
-
|
|
1292
1138
|
return str + this.outro;
|
|
1293
1139
|
}
|
|
1294
|
-
|
|
1140
|
+
/**
|
|
1141
|
+
* Returns true if the resulting source is empty (disregarding white space).
|
|
1142
|
+
*/
|
|
1295
1143
|
isEmpty() {
|
|
1296
1144
|
let chunk = this.firstChunk;
|
|
1297
|
-
|
|
1298
|
-
if (
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
(chunk.outro.length && chunk.outro.trim())
|
|
1302
|
-
)
|
|
1303
|
-
return false;
|
|
1304
|
-
} while ((chunk = chunk.next));
|
|
1145
|
+
while (chunk) {
|
|
1146
|
+
if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim()) return false;
|
|
1147
|
+
chunk = chunk.next;
|
|
1148
|
+
}
|
|
1305
1149
|
return true;
|
|
1306
1150
|
}
|
|
1307
|
-
|
|
1308
1151
|
length() {
|
|
1309
1152
|
let chunk = this.firstChunk;
|
|
1310
1153
|
let length = 0;
|
|
1311
|
-
|
|
1154
|
+
while (chunk) {
|
|
1312
1155
|
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
1313
|
-
|
|
1156
|
+
chunk = chunk.next;
|
|
1157
|
+
}
|
|
1314
1158
|
return length;
|
|
1315
1159
|
}
|
|
1316
|
-
|
|
1160
|
+
/**
|
|
1161
|
+
* Removes empty lines from the start and end.
|
|
1162
|
+
*/
|
|
1317
1163
|
trimLines() {
|
|
1318
|
-
return this.trim(
|
|
1164
|
+
return this.trim("[\\r\\n]");
|
|
1319
1165
|
}
|
|
1320
|
-
|
|
1166
|
+
/**
|
|
1167
|
+
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start and end.
|
|
1168
|
+
*/
|
|
1321
1169
|
trim(charType) {
|
|
1322
1170
|
return this.trimStart(charType).trimEnd(charType);
|
|
1323
1171
|
}
|
|
1324
|
-
|
|
1172
|
+
/** @internal */
|
|
1325
1173
|
trimEndAborted(charType) {
|
|
1326
|
-
const rx = new RegExp(
|
|
1327
|
-
|
|
1328
|
-
this.outro = this.outro.replace(rx, '');
|
|
1174
|
+
const rx = new RegExp(`${charType || "\\s"}+$`);
|
|
1175
|
+
this.outro = this.outro.replace(rx, "");
|
|
1329
1176
|
if (this.outro.length) return true;
|
|
1330
|
-
|
|
1331
1177
|
let chunk = this.lastChunk;
|
|
1332
|
-
|
|
1333
1178
|
do {
|
|
1334
1179
|
const end = chunk.end;
|
|
1335
1180
|
const aborted = chunk.trimEnd(rx);
|
|
1336
|
-
|
|
1337
|
-
// if chunk was trimmed, we have a new lastChunk
|
|
1338
1181
|
if (chunk.end !== end) {
|
|
1339
|
-
if (this.lastChunk === chunk)
|
|
1340
|
-
this.lastChunk = chunk.next;
|
|
1341
|
-
}
|
|
1342
|
-
|
|
1182
|
+
if (this.lastChunk === chunk) this.lastChunk = chunk.next;
|
|
1343
1183
|
this.byEnd[chunk.end] = chunk;
|
|
1344
1184
|
this.byStart[chunk.next.start] = chunk.next;
|
|
1345
1185
|
this.byEnd[chunk.next.end] = chunk.next;
|
|
1346
1186
|
}
|
|
1347
|
-
|
|
1348
1187
|
if (aborted) return true;
|
|
1349
1188
|
chunk = chunk.previous;
|
|
1350
1189
|
} while (chunk);
|
|
1351
|
-
|
|
1352
1190
|
return false;
|
|
1353
1191
|
}
|
|
1354
|
-
|
|
1192
|
+
/**
|
|
1193
|
+
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.
|
|
1194
|
+
*/
|
|
1355
1195
|
trimEnd(charType) {
|
|
1356
1196
|
this.trimEndAborted(charType);
|
|
1357
1197
|
return this;
|
|
1358
1198
|
}
|
|
1199
|
+
/** @internal */
|
|
1359
1200
|
trimStartAborted(charType) {
|
|
1360
|
-
const rx = new RegExp(
|
|
1361
|
-
|
|
1362
|
-
this.intro = this.intro.replace(rx, '');
|
|
1201
|
+
const rx = new RegExp(`^${charType || "\\s"}+`);
|
|
1202
|
+
this.intro = this.intro.replace(rx, "");
|
|
1363
1203
|
if (this.intro.length) return true;
|
|
1364
|
-
|
|
1365
1204
|
let chunk = this.firstChunk;
|
|
1366
|
-
|
|
1367
1205
|
do {
|
|
1368
1206
|
const end = chunk.end;
|
|
1369
1207
|
const aborted = chunk.trimStart(rx);
|
|
1370
|
-
|
|
1371
1208
|
if (chunk.end !== end) {
|
|
1372
|
-
// special case...
|
|
1373
1209
|
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
1374
|
-
|
|
1375
1210
|
this.byEnd[chunk.end] = chunk;
|
|
1376
1211
|
this.byStart[chunk.next.start] = chunk.next;
|
|
1377
1212
|
this.byEnd[chunk.next.end] = chunk.next;
|
|
1378
1213
|
}
|
|
1379
|
-
|
|
1380
1214
|
if (aborted) return true;
|
|
1381
1215
|
chunk = chunk.next;
|
|
1382
1216
|
} while (chunk);
|
|
1383
|
-
|
|
1384
1217
|
return false;
|
|
1385
1218
|
}
|
|
1386
|
-
|
|
1219
|
+
/**
|
|
1220
|
+
* Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.
|
|
1221
|
+
*/
|
|
1387
1222
|
trimStart(charType) {
|
|
1388
1223
|
this.trimStartAborted(charType);
|
|
1389
1224
|
return this;
|
|
1390
1225
|
}
|
|
1391
|
-
|
|
1226
|
+
/**
|
|
1227
|
+
* Indicates if the string has been changed.
|
|
1228
|
+
*/
|
|
1392
1229
|
hasChanged() {
|
|
1393
1230
|
return this.original !== this.toString();
|
|
1394
1231
|
}
|
|
1395
|
-
|
|
1232
|
+
/** @internal */
|
|
1396
1233
|
_replaceRegexp(searchValue, replacement) {
|
|
1397
1234
|
function getReplacement(match, str) {
|
|
1398
|
-
if (typeof replacement ===
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
return `$${i}`;
|
|
1406
|
-
});
|
|
1407
|
-
} else {
|
|
1408
|
-
return replacement(...match, match.index, str, match.groups);
|
|
1409
|
-
}
|
|
1235
|
+
if (typeof replacement === "string") return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
1236
|
+
if (i === "$") return "$";
|
|
1237
|
+
if (i === "&") return match[0];
|
|
1238
|
+
if (+i < match.length) return match[+i];
|
|
1239
|
+
return `$${i}`;
|
|
1240
|
+
});
|
|
1241
|
+
else return replacement(match[0], ...match.slice(1), match.index, str, match.groups);
|
|
1410
1242
|
}
|
|
1411
1243
|
function matchAll(re, str) {
|
|
1412
|
-
let match;
|
|
1413
1244
|
const matches = [];
|
|
1414
|
-
while (
|
|
1245
|
+
while (true) {
|
|
1246
|
+
const match = re.exec(str);
|
|
1247
|
+
if (!match) break;
|
|
1415
1248
|
matches.push(match);
|
|
1416
1249
|
}
|
|
1417
1250
|
return matches;
|
|
1418
1251
|
}
|
|
1419
|
-
if (searchValue.global) {
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
if (match.index
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
}
|
|
1427
|
-
}
|
|
1428
|
-
});
|
|
1429
|
-
} else {
|
|
1252
|
+
if (searchValue.global) matchAll(searchValue, this.original).forEach((match) => {
|
|
1253
|
+
if (match.index != null) {
|
|
1254
|
+
const replacement = getReplacement(match, this.original);
|
|
1255
|
+
if (replacement !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
1256
|
+
}
|
|
1257
|
+
});
|
|
1258
|
+
else {
|
|
1430
1259
|
const match = this.original.match(searchValue);
|
|
1431
1260
|
if (match && match.index != null) {
|
|
1432
1261
|
const replacement = getReplacement(match, this.original);
|
|
1433
|
-
if (replacement !== match[0])
|
|
1434
|
-
this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
1435
|
-
}
|
|
1262
|
+
if (replacement !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement);
|
|
1436
1263
|
}
|
|
1437
1264
|
}
|
|
1438
1265
|
return this;
|
|
1439
1266
|
}
|
|
1440
|
-
|
|
1267
|
+
/** @internal */
|
|
1441
1268
|
_replaceString(string, replacement) {
|
|
1442
1269
|
const { original } = this;
|
|
1443
1270
|
const index = original.indexOf(string);
|
|
1444
|
-
|
|
1445
1271
|
if (index !== -1) {
|
|
1446
|
-
if (typeof replacement ===
|
|
1447
|
-
|
|
1448
|
-
}
|
|
1449
|
-
if (string !== replacement) {
|
|
1450
|
-
this.overwrite(index, index + string.length, replacement);
|
|
1451
|
-
}
|
|
1272
|
+
if (typeof replacement === "function") replacement = replacement(string, index, original);
|
|
1273
|
+
if (string !== replacement) this.overwrite(index, index + string.length, replacement);
|
|
1452
1274
|
}
|
|
1453
|
-
|
|
1454
1275
|
return this;
|
|
1455
1276
|
}
|
|
1456
|
-
|
|
1277
|
+
/**
|
|
1278
|
+
* String replacement with RegExp or string.
|
|
1279
|
+
*/
|
|
1457
1280
|
replace(searchValue, replacement) {
|
|
1458
|
-
if (typeof searchValue ===
|
|
1459
|
-
return this._replaceString(searchValue, replacement);
|
|
1460
|
-
}
|
|
1461
|
-
|
|
1281
|
+
if (typeof searchValue === "string") return this._replaceString(searchValue, replacement);
|
|
1462
1282
|
return this._replaceRegexp(searchValue, replacement);
|
|
1463
1283
|
}
|
|
1464
|
-
|
|
1284
|
+
/** @internal */
|
|
1465
1285
|
_replaceAllString(string, replacement) {
|
|
1466
1286
|
const { original } = this;
|
|
1467
1287
|
const stringLength = string.length;
|
|
1468
|
-
for (
|
|
1469
|
-
let index = original.indexOf(string);
|
|
1470
|
-
index !== -1;
|
|
1471
|
-
index = original.indexOf(string, index + stringLength)
|
|
1472
|
-
) {
|
|
1288
|
+
for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
|
|
1473
1289
|
const previous = original.slice(index, index + stringLength);
|
|
1474
|
-
|
|
1475
|
-
if (typeof replacement === 'function') {
|
|
1476
|
-
_replacement = replacement(previous, index, original);
|
|
1477
|
-
}
|
|
1290
|
+
const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : replacement;
|
|
1478
1291
|
if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
|
|
1479
1292
|
}
|
|
1480
|
-
|
|
1481
1293
|
return this;
|
|
1482
1294
|
}
|
|
1483
|
-
|
|
1295
|
+
/**
|
|
1296
|
+
* Same as `s.replace`, but replace all matched strings instead of just one.
|
|
1297
|
+
*/
|
|
1484
1298
|
replaceAll(searchValue, replacement) {
|
|
1485
|
-
if (typeof searchValue ===
|
|
1486
|
-
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
if (!searchValue.global) {
|
|
1490
|
-
throw new TypeError(
|
|
1491
|
-
'MagicString.prototype.replaceAll called with a non-global RegExp argument',
|
|
1492
|
-
);
|
|
1493
|
-
}
|
|
1494
|
-
|
|
1299
|
+
if (typeof searchValue === "string") return this._replaceAllString(searchValue, replacement);
|
|
1300
|
+
if (!searchValue.global) throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");
|
|
1495
1301
|
return this._replaceRegexp(searchValue, replacement);
|
|
1496
1302
|
}
|
|
1497
|
-
}
|
|
1498
|
-
|
|
1303
|
+
};
|
|
1304
|
+
//#endregion
|
|
1305
|
+
//#region src/Bundle.ts
|
|
1499
1306
|
const hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1500
|
-
|
|
1501
|
-
let Bundle$1 = class Bundle {
|
|
1307
|
+
var Bundle$1 = class Bundle {
|
|
1502
1308
|
constructor(options = {}) {
|
|
1503
|
-
this.intro = options.intro ||
|
|
1504
|
-
this.separator = options.separator !==
|
|
1309
|
+
this.intro = options.intro || "";
|
|
1310
|
+
this.separator = options.separator !== void 0 ? options.separator : "\n";
|
|
1505
1311
|
this.sources = [];
|
|
1506
1312
|
this.uniqueSources = [];
|
|
1507
1313
|
this.uniqueSourceIndexByFilename = {};
|
|
1508
1314
|
}
|
|
1509
|
-
|
|
1315
|
+
/**
|
|
1316
|
+
* Adds the specified source to the bundle, which can either be a `MagicString` object directly,
|
|
1317
|
+
* or an options object that holds a magic string `content` property and optionally provides
|
|
1318
|
+
* a `filename` for the source within the bundle, as well as an optional `ignoreList` hint
|
|
1319
|
+
* (which defaults to `false`). The `filename` is used when constructing the source map for the
|
|
1320
|
+
* bundle, to identify this `source` in the source map's `sources` field. The `ignoreList` hint
|
|
1321
|
+
* is used to populate the `x_google_ignoreList` extension field in the source map, which is a
|
|
1322
|
+
* mechanism for tools to signal to debuggers that certain sources should be ignored by default
|
|
1323
|
+
* (depending on user preferences).
|
|
1324
|
+
*/
|
|
1510
1325
|
addSource(source) {
|
|
1511
|
-
if (source instanceof MagicString) {
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
}
|
|
1524
|
-
|
|
1525
|
-
['filename', 'ignoreList', 'indentExclusionRanges', 'separator'].forEach((option) => {
|
|
1326
|
+
if (source instanceof MagicString) return this.addSource({
|
|
1327
|
+
content: source,
|
|
1328
|
+
filename: source.filename,
|
|
1329
|
+
separator: this.separator
|
|
1330
|
+
});
|
|
1331
|
+
if (!isObject(source) || !source.content) throw new Error("bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`");
|
|
1332
|
+
[
|
|
1333
|
+
"filename",
|
|
1334
|
+
"ignoreList",
|
|
1335
|
+
"indentExclusionRanges",
|
|
1336
|
+
"separator"
|
|
1337
|
+
].forEach((option) => {
|
|
1526
1338
|
if (!hasOwnProp.call(source, option)) source[option] = source.content[option];
|
|
1527
1339
|
});
|
|
1528
|
-
|
|
1529
|
-
if (source.
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
} else {
|
|
1539
|
-
const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
|
|
1540
|
-
if (source.content.original !== uniqueSource.content) {
|
|
1541
|
-
throw new Error(`Illegal source: same filename (${source.filename}), different contents`);
|
|
1542
|
-
}
|
|
1543
|
-
}
|
|
1340
|
+
if (source.separator === void 0) source.separator = this.separator;
|
|
1341
|
+
if (source.filename) if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
|
|
1342
|
+
this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
|
|
1343
|
+
this.uniqueSources.push({
|
|
1344
|
+
filename: source.filename,
|
|
1345
|
+
content: source.content.original
|
|
1346
|
+
});
|
|
1347
|
+
} else {
|
|
1348
|
+
const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
|
|
1349
|
+
if (source.content.original !== uniqueSource.content) throw new Error(`Illegal source: same filename (${source.filename}), different contents`);
|
|
1544
1350
|
}
|
|
1545
|
-
|
|
1546
1351
|
this.sources.push(source);
|
|
1547
1352
|
return this;
|
|
1548
1353
|
}
|
|
1549
|
-
|
|
1550
1354
|
append(str, options) {
|
|
1551
1355
|
this.addSource({
|
|
1552
1356
|
content: new MagicString(str),
|
|
1553
|
-
separator:
|
|
1357
|
+
separator: options && options.separator || ""
|
|
1554
1358
|
});
|
|
1555
|
-
|
|
1556
1359
|
return this;
|
|
1557
1360
|
}
|
|
1558
|
-
|
|
1559
1361
|
clone() {
|
|
1560
1362
|
const bundle = new Bundle({
|
|
1561
1363
|
intro: this.intro,
|
|
1562
|
-
separator: this.separator
|
|
1364
|
+
separator: this.separator
|
|
1563
1365
|
});
|
|
1564
|
-
|
|
1565
1366
|
this.sources.forEach((source) => {
|
|
1566
1367
|
bundle.addSource({
|
|
1567
1368
|
filename: source.filename,
|
|
1568
1369
|
content: source.content.clone(),
|
|
1569
|
-
separator: source.separator
|
|
1370
|
+
separator: source.separator
|
|
1570
1371
|
});
|
|
1571
1372
|
});
|
|
1572
|
-
|
|
1573
1373
|
return bundle;
|
|
1574
1374
|
}
|
|
1575
|
-
|
|
1576
1375
|
generateDecodedMap(options = {}) {
|
|
1577
1376
|
const names = [];
|
|
1578
|
-
let x_google_ignoreList
|
|
1377
|
+
let x_google_ignoreList;
|
|
1579
1378
|
this.sources.forEach((source) => {
|
|
1580
1379
|
Object.keys(source.content.storedNames).forEach((name) => {
|
|
1581
|
-
if (
|
|
1380
|
+
if (!names.includes(name)) names.push(name);
|
|
1582
1381
|
});
|
|
1583
1382
|
});
|
|
1584
|
-
|
|
1585
1383
|
const mappings = new Mappings(options.hires);
|
|
1586
|
-
|
|
1587
|
-
if (this.intro) {
|
|
1588
|
-
mappings.advance(this.intro);
|
|
1589
|
-
}
|
|
1590
|
-
|
|
1384
|
+
if (this.intro) mappings.advance(this.intro);
|
|
1591
1385
|
this.sources.forEach((source, i) => {
|
|
1592
|
-
if (i > 0)
|
|
1593
|
-
mappings.advance(this.separator);
|
|
1594
|
-
}
|
|
1595
|
-
|
|
1386
|
+
if (i > 0) mappings.advance(this.separator);
|
|
1596
1387
|
const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
|
|
1597
1388
|
const magicString = source.content;
|
|
1598
1389
|
const locate = getLocator(magicString.original);
|
|
1599
|
-
|
|
1600
|
-
if (magicString.intro) {
|
|
1601
|
-
mappings.advance(magicString.intro);
|
|
1602
|
-
}
|
|
1603
|
-
|
|
1390
|
+
if (magicString.intro) mappings.advance(magicString.intro);
|
|
1604
1391
|
magicString.firstChunk.eachNext((chunk) => {
|
|
1605
1392
|
const loc = locate(chunk.start);
|
|
1606
|
-
|
|
1607
1393
|
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
1608
|
-
|
|
1609
|
-
|
|
1610
|
-
|
|
1611
|
-
mappings.addEdit(
|
|
1612
|
-
sourceIndex,
|
|
1613
|
-
chunk.content,
|
|
1614
|
-
loc,
|
|
1615
|
-
chunk.storeName ? names.indexOf(chunk.original) : -1,
|
|
1616
|
-
);
|
|
1617
|
-
} else {
|
|
1618
|
-
mappings.addUneditedChunk(
|
|
1619
|
-
sourceIndex,
|
|
1620
|
-
chunk,
|
|
1621
|
-
magicString.original,
|
|
1622
|
-
loc,
|
|
1623
|
-
magicString.sourcemapLocations,
|
|
1624
|
-
);
|
|
1625
|
-
}
|
|
1626
|
-
} else {
|
|
1627
|
-
mappings.advance(chunk.content);
|
|
1628
|
-
}
|
|
1629
|
-
|
|
1394
|
+
if (source.filename) if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
|
|
1395
|
+
else mappings.addUneditedChunk(sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations);
|
|
1396
|
+
else mappings.advance(chunk.content);
|
|
1630
1397
|
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
1631
1398
|
});
|
|
1632
|
-
|
|
1633
|
-
if (magicString.outro) {
|
|
1634
|
-
mappings.advance(magicString.outro);
|
|
1635
|
-
}
|
|
1636
|
-
|
|
1399
|
+
if (magicString.outro) mappings.advance(magicString.outro);
|
|
1637
1400
|
if (source.ignoreList && sourceIndex !== -1) {
|
|
1638
|
-
if (x_google_ignoreList ===
|
|
1639
|
-
x_google_ignoreList = [];
|
|
1640
|
-
}
|
|
1401
|
+
if (x_google_ignoreList === void 0) x_google_ignoreList = [];
|
|
1641
1402
|
x_google_ignoreList.push(sourceIndex);
|
|
1642
1403
|
}
|
|
1643
1404
|
});
|
|
1644
|
-
|
|
1645
1405
|
return {
|
|
1646
|
-
file: options.file ? options.file.split(/[/\\]/).pop() :
|
|
1406
|
+
file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
|
|
1647
1407
|
sources: this.uniqueSources.map((source) => {
|
|
1648
1408
|
return options.file ? getRelativePath(options.file, source.filename) : source.filename;
|
|
1649
1409
|
}),
|
|
@@ -1652,137 +1412,91 @@ let Bundle$1 = class Bundle {
|
|
|
1652
1412
|
}),
|
|
1653
1413
|
names,
|
|
1654
1414
|
mappings: mappings.raw,
|
|
1655
|
-
x_google_ignoreList
|
|
1415
|
+
x_google_ignoreList
|
|
1656
1416
|
};
|
|
1657
1417
|
}
|
|
1658
|
-
|
|
1659
1418
|
generateMap(options) {
|
|
1660
1419
|
return new SourceMap(this.generateDecodedMap(options));
|
|
1661
1420
|
}
|
|
1662
|
-
|
|
1663
1421
|
getIndentString() {
|
|
1664
1422
|
const indentStringCounts = {};
|
|
1665
|
-
|
|
1666
1423
|
this.sources.forEach((source) => {
|
|
1667
1424
|
const indentStr = source.content._getRawIndentString();
|
|
1668
|
-
|
|
1669
1425
|
if (indentStr === null) return;
|
|
1670
|
-
|
|
1671
1426
|
if (!indentStringCounts[indentStr]) indentStringCounts[indentStr] = 0;
|
|
1672
1427
|
indentStringCounts[indentStr] += 1;
|
|
1673
1428
|
});
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
return indentStringCounts[a] - indentStringCounts[b];
|
|
1678
|
-
})[0] || '\t'
|
|
1679
|
-
);
|
|
1429
|
+
return Object.keys(indentStringCounts).sort((a, b) => {
|
|
1430
|
+
return indentStringCounts[a] - indentStringCounts[b];
|
|
1431
|
+
})[0] || " ";
|
|
1680
1432
|
}
|
|
1681
|
-
|
|
1682
1433
|
indent(indentStr) {
|
|
1683
|
-
if (!arguments.length)
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
if (indentStr === '') return this; // noop
|
|
1688
|
-
|
|
1689
|
-
let trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
|
|
1690
|
-
|
|
1434
|
+
if (!arguments.length) indentStr = this.getIndentString();
|
|
1435
|
+
if (indentStr === "") return this;
|
|
1436
|
+
let trailingNewline = !this.intro || this.intro.slice(-1) === "\n";
|
|
1691
1437
|
this.sources.forEach((source, i) => {
|
|
1692
|
-
const separator = source.separator !==
|
|
1693
|
-
const indentStart = trailingNewline ||
|
|
1694
|
-
|
|
1438
|
+
const separator = source.separator !== void 0 ? source.separator : this.separator;
|
|
1439
|
+
const indentStart = trailingNewline || i > 0 && /\r?\n$/.test(separator);
|
|
1695
1440
|
source.content.indent(indentStr, {
|
|
1696
1441
|
exclude: source.indentExclusionRanges,
|
|
1697
|
-
indentStart
|
|
1442
|
+
indentStart
|
|
1698
1443
|
});
|
|
1699
|
-
|
|
1700
|
-
|
|
1444
|
+
trailingNewline = source.content.lastChar() === "\n";
|
|
1445
|
+
});
|
|
1446
|
+
if (this.intro) this.intro = indentStr + this.intro.replace(/^[^\n]/gm, (match, index) => {
|
|
1447
|
+
return index > 0 ? indentStr + match : match;
|
|
1701
1448
|
});
|
|
1702
|
-
|
|
1703
|
-
if (this.intro) {
|
|
1704
|
-
this.intro =
|
|
1705
|
-
indentStr +
|
|
1706
|
-
this.intro.replace(/^[^\n]/gm, (match, index) => {
|
|
1707
|
-
return index > 0 ? indentStr + match : match;
|
|
1708
|
-
});
|
|
1709
|
-
}
|
|
1710
|
-
|
|
1711
1449
|
return this;
|
|
1712
1450
|
}
|
|
1713
|
-
|
|
1714
1451
|
prepend(str) {
|
|
1715
1452
|
this.intro = str + this.intro;
|
|
1716
1453
|
return this;
|
|
1717
1454
|
}
|
|
1718
|
-
|
|
1719
1455
|
toString() {
|
|
1720
|
-
const body = this.sources
|
|
1721
|
-
.
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
return str;
|
|
1726
|
-
})
|
|
1727
|
-
.join('');
|
|
1728
|
-
|
|
1456
|
+
const body = this.sources.map((source, i) => {
|
|
1457
|
+
const separator = source.separator !== void 0 ? source.separator : this.separator;
|
|
1458
|
+
return (i > 0 ? separator : "") + source.content.toString();
|
|
1459
|
+
}).join("");
|
|
1729
1460
|
return this.intro + body;
|
|
1730
1461
|
}
|
|
1731
|
-
|
|
1732
1462
|
isEmpty() {
|
|
1733
1463
|
if (this.intro.length && this.intro.trim()) return false;
|
|
1734
1464
|
if (this.sources.some((source) => !source.content.isEmpty())) return false;
|
|
1735
1465
|
return true;
|
|
1736
1466
|
}
|
|
1737
|
-
|
|
1738
1467
|
length() {
|
|
1739
|
-
return this.sources.reduce(
|
|
1740
|
-
(length, source) => length + source.content.length(),
|
|
1741
|
-
this.intro.length,
|
|
1742
|
-
);
|
|
1468
|
+
return this.sources.reduce((length, source) => length + source.content.length(), this.intro.length);
|
|
1743
1469
|
}
|
|
1744
|
-
|
|
1745
1470
|
trimLines() {
|
|
1746
|
-
return this.trim(
|
|
1471
|
+
return this.trim("[\\r\\n]");
|
|
1747
1472
|
}
|
|
1748
|
-
|
|
1749
1473
|
trim(charType) {
|
|
1750
1474
|
return this.trimStart(charType).trimEnd(charType);
|
|
1751
1475
|
}
|
|
1752
|
-
|
|
1753
1476
|
trimStart(charType) {
|
|
1754
|
-
const rx = new RegExp(
|
|
1755
|
-
this.intro = this.intro.replace(rx,
|
|
1756
|
-
|
|
1477
|
+
const rx = new RegExp(`^${charType || "\\s"}+`);
|
|
1478
|
+
this.intro = this.intro.replace(rx, "");
|
|
1757
1479
|
if (!this.intro) {
|
|
1758
1480
|
let source;
|
|
1759
1481
|
let i = 0;
|
|
1760
|
-
|
|
1761
1482
|
do {
|
|
1762
1483
|
source = this.sources[i++];
|
|
1763
|
-
if (!source)
|
|
1764
|
-
break;
|
|
1765
|
-
}
|
|
1484
|
+
if (!source) break;
|
|
1766
1485
|
} while (!source.content.trimStartAborted(charType));
|
|
1767
1486
|
}
|
|
1768
|
-
|
|
1769
1487
|
return this;
|
|
1770
1488
|
}
|
|
1771
|
-
|
|
1772
1489
|
trimEnd(charType) {
|
|
1773
|
-
const rx = new RegExp(
|
|
1774
|
-
|
|
1490
|
+
const rx = new RegExp(`${charType || "\\s"}+$`);
|
|
1775
1491
|
let source;
|
|
1776
1492
|
let i = this.sources.length - 1;
|
|
1777
|
-
|
|
1778
1493
|
do {
|
|
1779
1494
|
source = this.sources[i--];
|
|
1780
1495
|
if (!source) {
|
|
1781
|
-
this.intro = this.intro.replace(rx,
|
|
1496
|
+
this.intro = this.intro.replace(rx, "");
|
|
1782
1497
|
break;
|
|
1783
1498
|
}
|
|
1784
1499
|
} while (!source.content.trimEndAborted(charType));
|
|
1785
|
-
|
|
1786
1500
|
return this;
|
|
1787
1501
|
}
|
|
1788
1502
|
};
|
|
@@ -2558,13 +2272,14 @@ const RESERVED_NAMES = new Set([
|
|
|
2558
2272
|
]);
|
|
2559
2273
|
|
|
2560
2274
|
const illegalCharacters = /[^\w$]/g;
|
|
2275
|
+
const illegalCharacter = /[^\w$]/;
|
|
2561
2276
|
const startsWithDigit = (value) => /\d/.test(value[0]);
|
|
2562
2277
|
const needsEscape = (value) => startsWithDigit(value) || RESERVED_NAMES.has(value) || value === 'arguments';
|
|
2563
2278
|
function isLegal(value) {
|
|
2564
2279
|
if (needsEscape(value)) {
|
|
2565
2280
|
return false;
|
|
2566
2281
|
}
|
|
2567
|
-
return !
|
|
2282
|
+
return !illegalCharacter.test(value);
|
|
2568
2283
|
}
|
|
2569
2284
|
function makeLegal(value) {
|
|
2570
2285
|
value = value
|
|
@@ -5340,12 +5055,12 @@ class IdentifierBase extends NodeBase {
|
|
|
5340
5055
|
this.variable.module.hasTreeShakingPassStarted)) {
|
|
5341
5056
|
return (this.isTDZAccess = false);
|
|
5342
5057
|
}
|
|
5343
|
-
let
|
|
5058
|
+
let declaration_id;
|
|
5344
5059
|
if (this.variable.declarations &&
|
|
5345
5060
|
this.variable.declarations.length === 1 &&
|
|
5346
|
-
(
|
|
5347
|
-
this.start <
|
|
5348
|
-
closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(
|
|
5061
|
+
(declaration_id = this.variable.declarations[0]) &&
|
|
5062
|
+
this.start < declaration_id.start &&
|
|
5063
|
+
closestParentFunctionOrProgram(this) === closestParentFunctionOrProgram(declaration_id)) {
|
|
5349
5064
|
// a variable accessed before its declaration
|
|
5350
5065
|
// in the same function or at top level of module
|
|
5351
5066
|
return (this.isTDZAccess = true);
|
|
@@ -8239,13 +7954,13 @@ function getExportBlock$1(exports, dependencies, namedExportsMode, interop, snip
|
|
|
8239
7954
|
}
|
|
8240
7955
|
let exportBlock = '';
|
|
8241
7956
|
if (namedExportsMode) {
|
|
8242
|
-
for (const { defaultVariableName, importPath, isChunk, name, namedExportsMode:
|
|
7957
|
+
for (const { defaultVariableName, importPath, isChunk, name, namedExportsMode: dependencyNamedExportsMode, namespaceVariableName, reexports } of dependencies) {
|
|
8243
7958
|
if (!reexports) {
|
|
8244
7959
|
continue;
|
|
8245
7960
|
}
|
|
8246
7961
|
for (const specifier of reexports) {
|
|
8247
7962
|
if (specifier.reexported !== '*') {
|
|
8248
|
-
const importName = getReexportedImportName(name, specifier.imported,
|
|
7963
|
+
const importName = getReexportedImportName(name, specifier.imported, dependencyNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, importPath, externalLiveBindings, getPropertyAccess);
|
|
8249
7964
|
if (exportBlock)
|
|
8250
7965
|
exportBlock += n;
|
|
8251
7966
|
if (specifier.imported !== '*' && specifier.needsLiveBinding) {
|
|
@@ -8324,14 +8039,14 @@ function getSingleDefaultExport(exports, dependencies, interop, externalLiveBind
|
|
|
8324
8039
|
return exports[0].local;
|
|
8325
8040
|
}
|
|
8326
8041
|
else {
|
|
8327
|
-
for (const { defaultVariableName, importPath, isChunk, name, namedExportsMode:
|
|
8042
|
+
for (const { defaultVariableName, importPath, isChunk, name, namedExportsMode: dependencyNamedExportsMode, namespaceVariableName, reexports } of dependencies) {
|
|
8328
8043
|
if (reexports) {
|
|
8329
|
-
return getReexportedImportName(name, reexports[0].imported,
|
|
8044
|
+
return getReexportedImportName(name, reexports[0].imported, dependencyNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, importPath, externalLiveBindings, getPropertyAccess);
|
|
8330
8045
|
}
|
|
8331
8046
|
}
|
|
8332
8047
|
}
|
|
8333
8048
|
}
|
|
8334
|
-
function getReexportedImportName(moduleVariableName, imported,
|
|
8049
|
+
function getReexportedImportName(moduleVariableName, imported, dependencyNamedExportsMode, isChunk, defaultVariableName, namespaceVariableName, interop, moduleId, externalLiveBindings, getPropertyAccess) {
|
|
8335
8050
|
if (imported === 'default') {
|
|
8336
8051
|
if (!isChunk) {
|
|
8337
8052
|
const moduleInterop = interop(moduleId);
|
|
@@ -8342,12 +8057,14 @@ function getReexportedImportName(moduleVariableName, imported, depNamedExportsMo
|
|
|
8342
8057
|
? `${variableName}${getPropertyAccess('default')}`
|
|
8343
8058
|
: variableName;
|
|
8344
8059
|
}
|
|
8345
|
-
return
|
|
8060
|
+
return dependencyNamedExportsMode
|
|
8346
8061
|
? `${moduleVariableName}${getPropertyAccess('default')}`
|
|
8347
8062
|
: moduleVariableName;
|
|
8348
8063
|
}
|
|
8349
8064
|
if (imported === '*') {
|
|
8350
|
-
return (isChunk
|
|
8065
|
+
return (isChunk
|
|
8066
|
+
? !dependencyNamedExportsMode
|
|
8067
|
+
: namespaceInteropHelpersByInteropType[interop(moduleId)])
|
|
8351
8068
|
? namespaceVariableName
|
|
8352
8069
|
: moduleVariableName;
|
|
8353
8070
|
}
|
|
@@ -8572,6 +8289,7 @@ const builtinModules = [
|
|
|
8572
8289
|
"util/types",
|
|
8573
8290
|
"node:v8",
|
|
8574
8291
|
"v8",
|
|
8292
|
+
"node:vfs",
|
|
8575
8293
|
"node:vm",
|
|
8576
8294
|
"vm",
|
|
8577
8295
|
"node:wasi",
|
|
@@ -8861,7 +8579,7 @@ function iife(magicString, { accessedGlobals, dependencies, exports, hasDefaultE
|
|
|
8861
8579
|
}
|
|
8862
8580
|
warnOnBuiltins(log, dependencies);
|
|
8863
8581
|
const external = trimEmptyImports(dependencies);
|
|
8864
|
-
const deps = external.map(
|
|
8582
|
+
const deps = external.map(dependency => dependency.globalName || 'null');
|
|
8865
8583
|
const parameters = external.map(m => m.name);
|
|
8866
8584
|
if (hasExports && !name) {
|
|
8867
8585
|
log(LOGLEVEL_WARN, logMissingNameOptionForIifeExport());
|
|
@@ -9082,21 +8800,21 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasDefaultEx
|
|
|
9082
8800
|
}
|
|
9083
8801
|
throwOnPhase('umd', id, dependencies);
|
|
9084
8802
|
warnOnBuiltins(log, dependencies);
|
|
9085
|
-
const
|
|
9086
|
-
const
|
|
8803
|
+
const amdDependencies = dependencies.map(m => `'${updateExtensionForRelativeAmdId(m.importPath, amd.forceJsExtensionForImports)}'`);
|
|
8804
|
+
const cjsDependencies = dependencies.map(m => `require('${m.importPath}')`);
|
|
9087
8805
|
const trimmedImports = trimEmptyImports(dependencies);
|
|
9088
|
-
const
|
|
8806
|
+
const globalDependencies = trimmedImports.map(module => globalProperty(module.globalName, globalVariable, getPropertyAccess));
|
|
9089
8807
|
const factoryParameters = trimmedImports.map(m => m.name);
|
|
9090
8808
|
if ((hasExports || noConflict) &&
|
|
9091
8809
|
(namedExportsMode || (hasExports && exports[0]?.local === 'exports.default'))) {
|
|
9092
|
-
|
|
9093
|
-
|
|
9094
|
-
|
|
8810
|
+
amdDependencies.unshift(`'exports'`);
|
|
8811
|
+
cjsDependencies.unshift(`exports`);
|
|
8812
|
+
globalDependencies.unshift(assignToDeepVariable(name, globalVariable, globals, `${extend ? `${globalProperty(name, globalVariable, getPropertyAccess)}${_}||${_}` : ''}{}`, snippets, log));
|
|
9095
8813
|
factoryParameters.unshift('exports');
|
|
9096
8814
|
}
|
|
9097
8815
|
const completeAmdId = getCompleteAmdId(amd, id);
|
|
9098
8816
|
const amdParameters = (completeAmdId ? `'${completeAmdId}',${_}` : ``) +
|
|
9099
|
-
(
|
|
8817
|
+
(amdDependencies.length > 0 ? `[${amdDependencies.join(`,${_}`)}],${_}` : ``);
|
|
9100
8818
|
const define = amd.define;
|
|
9101
8819
|
const cjsExport = !namedExportsMode && hasExports ? `module.exports${_}=${_}` : ``;
|
|
9102
8820
|
const useStrict = strict ? `${_}'use strict';${n}` : ``;
|
|
@@ -9105,13 +8823,13 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasDefaultEx
|
|
|
9105
8823
|
const noConflictExportsVariable = compact ? 'e' : 'exports';
|
|
9106
8824
|
let factory;
|
|
9107
8825
|
if (!namedExportsMode && hasExports) {
|
|
9108
|
-
factory = `${cnst} ${noConflictExportsVariable}${_}=${_}${assignToDeepVariable(name, globalVariable, globals, `${factoryVariable}(${
|
|
8826
|
+
factory = `${cnst} ${noConflictExportsVariable}${_}=${_}${assignToDeepVariable(name, globalVariable, globals, `${factoryVariable}(${globalDependencies.join(`,${_}`)})`, snippets, log)};`;
|
|
9109
8827
|
}
|
|
9110
8828
|
else {
|
|
9111
|
-
const module =
|
|
8829
|
+
const module = globalDependencies.shift();
|
|
9112
8830
|
factory =
|
|
9113
8831
|
`${cnst} ${noConflictExportsVariable}${_}=${_}${module};${n}` +
|
|
9114
|
-
`${t}${t}${factoryVariable}(${[noConflictExportsVariable, ...
|
|
8832
|
+
`${t}${t}${factoryVariable}(${[noConflictExportsVariable, ...globalDependencies].join(`,${_}`)});`;
|
|
9115
8833
|
}
|
|
9116
8834
|
iifeExport =
|
|
9117
8835
|
`(${getFunctionIntro([], { isAsync: false, name: null })}{${n}` +
|
|
@@ -9125,12 +8843,12 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasDefaultEx
|
|
|
9125
8843
|
`${t}})()`;
|
|
9126
8844
|
}
|
|
9127
8845
|
else {
|
|
9128
|
-
iifeExport = `${factoryVariable}(${
|
|
8846
|
+
iifeExport = `${factoryVariable}(${globalDependencies.join(`,${_}`)})`;
|
|
9129
8847
|
if (!namedExportsMode && hasExports) {
|
|
9130
8848
|
iifeExport = assignToDeepVariable(name, globalVariable, globals, iifeExport, snippets, log);
|
|
9131
8849
|
}
|
|
9132
8850
|
}
|
|
9133
|
-
const iifeNeedsGlobal = hasExports || (noConflict && namedExportsMode) ||
|
|
8851
|
+
const iifeNeedsGlobal = hasExports || (noConflict && namedExportsMode) || globalDependencies.length > 0;
|
|
9134
8852
|
const wrapperParameters = [factoryVariable];
|
|
9135
8853
|
if (iifeNeedsGlobal) {
|
|
9136
8854
|
wrapperParameters.unshift(globalVariable);
|
|
@@ -9142,7 +8860,7 @@ function umd(magicString, { accessedGlobals, dependencies, exports, hasDefaultEx
|
|
|
9142
8860
|
const iifeEnd = iifeNeedsGlobal ? ')' : '';
|
|
9143
8861
|
const cjsIntro = iifeNeedsGlobal
|
|
9144
8862
|
? `${t}typeof exports${_}===${_}'object'${_}&&${_}typeof module${_}!==${_}'undefined'${_}?` +
|
|
9145
|
-
`${_}${cjsExport}${factoryVariable}(${
|
|
8863
|
+
`${_}${cjsExport}${factoryVariable}(${cjsDependencies.join(`,${_}`)})${_}:${n}`
|
|
9146
8864
|
: '';
|
|
9147
8865
|
const wrapperIntro = `(${getNonArrowFunctionIntro(wrapperParameters, { isAsync: false, name: null })}{${n}` +
|
|
9148
8866
|
cjsIntro +
|
|
@@ -10109,7 +9827,15 @@ function requireParse () {
|
|
|
10109
9827
|
}
|
|
10110
9828
|
};
|
|
10111
9829
|
|
|
10112
|
-
const
|
|
9830
|
+
const buildCharClassStar = chars => {
|
|
9831
|
+
const source = chars.length === 1
|
|
9832
|
+
? utils.escapeRegex(chars[0])
|
|
9833
|
+
: `[${chars.map(ch => utils.escapeRegex(ch)).join('')}]`;
|
|
9834
|
+
|
|
9835
|
+
return `${source}*`;
|
|
9836
|
+
};
|
|
9837
|
+
|
|
9838
|
+
const getStarExtglobSequenceChars = pattern => {
|
|
10113
9839
|
let index = 0;
|
|
10114
9840
|
const chars = [];
|
|
10115
9841
|
|
|
@@ -10138,11 +9864,7 @@ function requireParse () {
|
|
|
10138
9864
|
return;
|
|
10139
9865
|
}
|
|
10140
9866
|
|
|
10141
|
-
|
|
10142
|
-
? utils.escapeRegex(chars[0])
|
|
10143
|
-
: `[${chars.map(ch => utils.escapeRegex(ch)).join('')}]`;
|
|
10144
|
-
|
|
10145
|
-
return `${source}*`;
|
|
9867
|
+
return chars;
|
|
10146
9868
|
};
|
|
10147
9869
|
|
|
10148
9870
|
const repeatedExtglobRecursion = pattern => {
|
|
@@ -10181,17 +9903,43 @@ function requireParse () {
|
|
|
10181
9903
|
}
|
|
10182
9904
|
}
|
|
10183
9905
|
|
|
9906
|
+
// A repeated extglob is "risky" (prone to catastrophic backtracking) when a
|
|
9907
|
+
// branch is itself a `*(...)` sequence, since that nests an unbounded quantifier
|
|
9908
|
+
// inside the outer `+(...)`/`*(...)`. When *every* branch reduces to single
|
|
9909
|
+
// characters we can emit one flat, ReDoS-safe character class that preserves the
|
|
9910
|
+
// meaning of ALL branches (e.g. `+(*(a)|*(b))` -> `[ab]*`), rather than dropping
|
|
9911
|
+
// every branch but the first.
|
|
9912
|
+
const safeChars = [];
|
|
9913
|
+
let sawStarSequence = false;
|
|
9914
|
+
let combinable = true;
|
|
9915
|
+
|
|
10184
9916
|
for (const branch of branches) {
|
|
10185
|
-
const
|
|
10186
|
-
if (
|
|
10187
|
-
|
|
9917
|
+
const chars = getStarExtglobSequenceChars(branch);
|
|
9918
|
+
if (chars) {
|
|
9919
|
+
sawStarSequence = true;
|
|
9920
|
+
safeChars.push(...chars);
|
|
9921
|
+
continue;
|
|
10188
9922
|
}
|
|
10189
9923
|
|
|
9924
|
+
const literal = normalizeSimpleBranch(branch);
|
|
9925
|
+
if (literal && literal.length === 1) {
|
|
9926
|
+
safeChars.push(literal);
|
|
9927
|
+
continue;
|
|
9928
|
+
}
|
|
9929
|
+
|
|
9930
|
+
combinable = false;
|
|
9931
|
+
|
|
10190
9932
|
if (repeatedExtglobRecursion(branch) > max) {
|
|
10191
9933
|
return { risky: true };
|
|
10192
9934
|
}
|
|
10193
9935
|
}
|
|
10194
9936
|
|
|
9937
|
+
if (sawStarSequence) {
|
|
9938
|
+
return combinable
|
|
9939
|
+
? { risky: true, safeOutput: buildCharClassStar([...new Set(safeChars)]) }
|
|
9940
|
+
: { risky: true };
|
|
9941
|
+
}
|
|
9942
|
+
|
|
10195
9943
|
return { risky: false };
|
|
10196
9944
|
};
|
|
10197
9945
|
|
|
@@ -11293,6 +11041,18 @@ function requirePicomatch$1 () {
|
|
|
11293
11041
|
* const isMatch = picomatch('*.!(*a)');
|
|
11294
11042
|
* console.log(isMatch('a.a')); //=> false
|
|
11295
11043
|
* console.log(isMatch('a.b')); //=> true
|
|
11044
|
+
*
|
|
11045
|
+
* // For environments without `node.js`, `picomatch/posix` provides you a dependency-free matcher, without automatic OS detection.
|
|
11046
|
+
* const picomatch = require('picomatch/posix');
|
|
11047
|
+
* // the same API, defaulting to posix paths
|
|
11048
|
+
* const isMatch = picomatch('a/*');
|
|
11049
|
+
* console.log(isMatch('a\\b')); //=> false
|
|
11050
|
+
* console.log(isMatch('a/b')); //=> true
|
|
11051
|
+
*
|
|
11052
|
+
* // you can still configure the matcher function to accept windows paths
|
|
11053
|
+
* const isMatch = picomatch('a/*', { options: windows });
|
|
11054
|
+
* console.log(isMatch('a\\b')); //=> true
|
|
11055
|
+
* console.log(isMatch('a/b')); //=> true
|
|
11296
11056
|
* ```
|
|
11297
11057
|
* @name picomatch
|
|
11298
11058
|
* @param {String|Array} `globs` One or more glob patterns.
|
|
@@ -11430,9 +11190,9 @@ function requirePicomatch$1 () {
|
|
|
11430
11190
|
* @api public
|
|
11431
11191
|
*/
|
|
11432
11192
|
|
|
11433
|
-
picomatch.matchBase = (input, glob, options) => {
|
|
11193
|
+
picomatch.matchBase = (input, glob, options, posix = options && options.windows) => {
|
|
11434
11194
|
const regex = glob instanceof RegExp ? glob : picomatch.makeRe(glob, options);
|
|
11435
|
-
return regex.test(utils.basename(input));
|
|
11195
|
+
return regex.test(utils.basename(input, { windows: posix }));
|
|
11436
11196
|
};
|
|
11437
11197
|
|
|
11438
11198
|
/**
|
|
@@ -13683,19 +13443,19 @@ class ImportExpression extends NodeBase {
|
|
|
13683
13443
|
return null;
|
|
13684
13444
|
const chunkInfos = [];
|
|
13685
13445
|
const importerPath = ownChunk.getFileName();
|
|
13686
|
-
for (const
|
|
13687
|
-
const resolvedImportPath = `'${
|
|
13688
|
-
if (
|
|
13446
|
+
for (const dependency of targetChunk.dependencies) {
|
|
13447
|
+
const resolvedImportPath = `'${dependency.getImportPath(importerPath)}'`;
|
|
13448
|
+
if (dependency instanceof ExternalChunk) {
|
|
13689
13449
|
chunkInfos.push({
|
|
13690
|
-
fileName:
|
|
13450
|
+
fileName: dependency.getFileName(),
|
|
13691
13451
|
resolvedImportPath,
|
|
13692
13452
|
type: 'external'
|
|
13693
13453
|
});
|
|
13694
13454
|
}
|
|
13695
13455
|
else {
|
|
13696
13456
|
chunkInfos.push({
|
|
13697
|
-
chunk:
|
|
13698
|
-
fileName:
|
|
13457
|
+
chunk: dependency.getPreRenderedChunkInfo(),
|
|
13458
|
+
fileName: dependency.getFileName(),
|
|
13699
13459
|
resolvedImportPath,
|
|
13700
13460
|
type: 'internal'
|
|
13701
13461
|
});
|
|
@@ -18993,9 +18753,9 @@ class Chunk {
|
|
|
18993
18753
|
// for static and dynamic entry points, add transitive dependencies to this
|
|
18994
18754
|
// chunk's dependencies to avoid loading latency
|
|
18995
18755
|
if (hoistTransitiveImports && !preserveModules && facadeModule !== null) {
|
|
18996
|
-
for (const
|
|
18997
|
-
if (
|
|
18998
|
-
this.inlineChunkDependencies(
|
|
18756
|
+
for (const dependency of dependencies) {
|
|
18757
|
+
if (dependency instanceof Chunk)
|
|
18758
|
+
this.inlineChunkDependencies(dependency);
|
|
18999
18759
|
}
|
|
19000
18760
|
}
|
|
19001
18761
|
}
|
|
@@ -19167,11 +18927,11 @@ class Chunk {
|
|
|
19167
18927
|
if (!chunk || format !== 'es') {
|
|
19168
18928
|
continue;
|
|
19169
18929
|
}
|
|
19170
|
-
const
|
|
19171
|
-
if (!
|
|
18930
|
+
const chunkDependency = this.renderedDependencies.get(chunk);
|
|
18931
|
+
if (!chunkDependency) {
|
|
19172
18932
|
continue;
|
|
19173
18933
|
}
|
|
19174
|
-
const { imports, reexports } =
|
|
18934
|
+
const { imports, reexports } = chunkDependency;
|
|
19175
18935
|
const importedByReexported = reexports?.find(({ reexported }) => reexported === exportName);
|
|
19176
18936
|
const isImported = imports?.find(({ imported }) => imported === importedByReexported?.imported);
|
|
19177
18937
|
if (!isImported) {
|
|
@@ -19381,6 +19141,10 @@ class Chunk {
|
|
|
19381
19141
|
return predefinedChunkName;
|
|
19382
19142
|
const { preserveModulesRoot, sanitizeFileName } = this.outputOptions;
|
|
19383
19143
|
const sanitizedId = sanitizeFileName(normalize(module.id.split(QUERY_HASH_REGEX, 1)[0]));
|
|
19144
|
+
// The module id was sanitized, so the base must be sanitized as well before
|
|
19145
|
+
// comparing paths; otherwise ids containing sanitized characters escape the
|
|
19146
|
+
// base via "../" and trip the placeholder validation (#5446).
|
|
19147
|
+
const sanitizedBase = sanitizeFileName(this.inputBase);
|
|
19384
19148
|
const extensionName = extname(sanitizedId);
|
|
19385
19149
|
const idWithoutExtension = NON_ASSET_EXTENSIONS.has(extensionName)
|
|
19386
19150
|
? sanitizedId.slice(0, -extensionName.length)
|
|
@@ -19391,10 +19155,10 @@ class Chunk {
|
|
|
19391
19155
|
}
|
|
19392
19156
|
else {
|
|
19393
19157
|
// handle edge case in Windows
|
|
19394
|
-
if (
|
|
19395
|
-
return relative$1(
|
|
19158
|
+
if (sanitizedBase === '/' && idWithoutExtension[0] !== '/') {
|
|
19159
|
+
return relative$1(sanitizedBase, idWithoutExtension.replace(/^[a-zA-Z]:[/\\]/, '/'));
|
|
19396
19160
|
}
|
|
19397
|
-
return relative$1(
|
|
19161
|
+
return relative$1(sanitizedBase, idWithoutExtension);
|
|
19398
19162
|
}
|
|
19399
19163
|
}
|
|
19400
19164
|
else {
|
|
@@ -19509,12 +19273,12 @@ class Chunk {
|
|
|
19509
19273
|
return (this.renderedDependencies = renderedDependencies);
|
|
19510
19274
|
}
|
|
19511
19275
|
inlineChunkDependencies(chunk) {
|
|
19512
|
-
for (const
|
|
19513
|
-
if (this.dependencies.has(
|
|
19276
|
+
for (const dependency of chunk.dependencies) {
|
|
19277
|
+
if (this.dependencies.has(dependency))
|
|
19514
19278
|
continue;
|
|
19515
|
-
this.dependencies.add(
|
|
19516
|
-
if (
|
|
19517
|
-
this.inlineChunkDependencies(
|
|
19279
|
+
this.dependencies.add(dependency);
|
|
19280
|
+
if (dependency instanceof Chunk) {
|
|
19281
|
+
this.inlineChunkDependencies(dependency);
|
|
19518
19282
|
}
|
|
19519
19283
|
}
|
|
19520
19284
|
}
|
|
@@ -20988,7 +20752,7 @@ function addChunksToBundle(renderedChunksByPlaceholder, hashesByPlaceholder, bun
|
|
|
20988
20752
|
finalSourcemapFileName = sourcemapFileName
|
|
20989
20753
|
? replacePlaceholders(sourcemapFileName, hashesByPlaceholder)
|
|
20990
20754
|
: `${finalFileName}.map`;
|
|
20991
|
-
map.file = replacePlaceholders(map.file, hashesByPlaceholder);
|
|
20755
|
+
map.file = replacePlaceholders(map.file ?? '', hashesByPlaceholder);
|
|
20992
20756
|
updatedCode += emitSourceMapAndGetComment(finalSourcemapFileName, map, pluginDriver, options);
|
|
20993
20757
|
}
|
|
20994
20758
|
bundle[finalFileName] = chunk.finalizeChunk(updatedCode, map, finalSourcemapFileName, hashesByPlaceholder);
|
|
@@ -21766,7 +21530,6 @@ async function transform(source, module, pluginDriver, options) {
|
|
|
21766
21530
|
}
|
|
21767
21531
|
return new SourceMap({
|
|
21768
21532
|
...combinedMap,
|
|
21769
|
-
file: null,
|
|
21770
21533
|
sourcesContent: combinedMap.sourcesContent
|
|
21771
21534
|
});
|
|
21772
21535
|
},
|
|
@@ -22668,7 +22431,7 @@ function getLogHandler(level, code, logger, pluginName, logLevel) {
|
|
|
22668
22431
|
};
|
|
22669
22432
|
}
|
|
22670
22433
|
|
|
22671
|
-
const rollupVersion$2 =
|
|
22434
|
+
const rollupVersion$2 = pkg.version;
|
|
22672
22435
|
function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, existingPluginNames) {
|
|
22673
22436
|
const { logLevel, onLog } = options;
|
|
22674
22437
|
let cacheable = true;
|
|
@@ -23390,7 +23153,7 @@ async function catchUnfinishedHookActions(pluginDriver, callback) {
|
|
|
23390
23153
|
|
|
23391
23154
|
async function initWasm() { }
|
|
23392
23155
|
|
|
23393
|
-
const rollupVersion$1 =
|
|
23156
|
+
const rollupVersion$1 = pkg.version;
|
|
23394
23157
|
function getLogger(plugins, onLog, watchMode, logLevel) {
|
|
23395
23158
|
plugins = getSortedValidatedPlugins('onLog', plugins);
|
|
23396
23159
|
const minimalPriority = logLevelPriority[logLevel];
|
|
@@ -23886,7 +23649,7 @@ const getSourcemapBaseUrl = (config) => {
|
|
|
23886
23649
|
}
|
|
23887
23650
|
};
|
|
23888
23651
|
|
|
23889
|
-
const rollupVersion =
|
|
23652
|
+
const rollupVersion = pkg.version;
|
|
23890
23653
|
// @ts-expect-error TS2540: the polyfill of `asyncDispose`.
|
|
23891
23654
|
Symbol.asyncDispose ??= Symbol('Symbol.asyncDispose');
|
|
23892
23655
|
function rollup(rawInputOptions) {
|
|
@@ -24521,6 +24284,6 @@ async function watchInternal(configs, emitter) {
|
|
|
24521
24284
|
new Watcher(watchOptionsList, emitter);
|
|
24522
24285
|
}
|
|
24523
24286
|
|
|
24524
|
-
const VERSION =
|
|
24287
|
+
const VERSION = pkg.version;
|
|
24525
24288
|
|
|
24526
24289
|
export { VERSION, createFilter$1 as createFilter, defineConfig, fseventsImporter, getAugmentedNamespace, getDefaultExportFromCjs, rollup, rollupInternal, watch };
|