rollup 4.63.1 → 4.63.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.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.63.1
4
- Fri, 28 Aug 2026 05:58:50 GMT - commit 78bfef0cb94479566f81012fafa372c84b90bd34
3
+ Rollup.js v4.63.3
4
+ Mon, 14 Sep 2026 12:44:36 GMT - commit 250deca2945f8817350564f7d52bab0f79175d1b
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -27,7 +27,7 @@ function _mergeNamespaces(n, m) {
27
27
  return Object.defineProperty(n, Symbol.toStringTag, { value: 'Module' });
28
28
  }
29
29
 
30
- var version = "4.63.1";
30
+ var version = "4.63.3";
31
31
  const pkg = {
32
32
  version: version};
33
33
 
@@ -42,7 +42,7 @@ for (let i = 0; i < chars$1.length; i++) {
42
42
  intToChar[i] = c;
43
43
  charToInt[c] = i;
44
44
  }
45
- function decodeInteger(reader, relative) {
45
+ function decodeInteger(reader) {
46
46
  let value = 0;
47
47
  let shift = 0;
48
48
  let integer = 0;
@@ -52,23 +52,21 @@ function decodeInteger(reader, relative) {
52
52
  value |= (integer & 31) << shift;
53
53
  shift += 5;
54
54
  } while (integer & 32);
55
- const shouldNegate = value & 1;
56
- value >>>= 1;
57
- if (shouldNegate) {
58
- value = -2147483648 | -value;
59
- }
60
- return relative + value;
55
+ return value;
56
+ }
57
+ function decodeSign(num) {
58
+ return num & 1 ? -2147483648 | -(num >>> 1) : num >>> 1;
61
59
  }
62
- function encodeInteger(builder, num, relative) {
63
- let delta = num - relative;
64
- delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
60
+ function encodeInteger(builder, num) {
65
61
  do {
66
- let clamped = delta & 31;
67
- delta >>>= 5;
68
- if (delta > 0) clamped |= 32;
62
+ let clamped = num & 31;
63
+ num >>>= 5;
64
+ if (num > 0) clamped |= 32;
69
65
  builder.write(intToChar[clamped]);
70
- } while (delta > 0);
71
- return num;
66
+ } while (num > 0);
67
+ }
68
+ function encodeSign(num) {
69
+ return num < 0 ? -num << 1 | 1 : num << 1;
72
70
  }
73
71
  function hasMoreVlq(reader, max) {
74
72
  if (reader.pos >= max) return false;
@@ -127,6 +125,21 @@ var StringReader = class {
127
125
  return idx === -1 ? buffer.length : idx;
128
126
  }
129
127
  };
128
+ function encodeRangeMappings(decoded) {
129
+ if (decoded.length === 0) return "";
130
+ const writer = new StringWriter();
131
+ for (let i = 0; i < decoded.length; i++) {
132
+ const indices = decoded[i];
133
+ if (i > 0) writer.write(semicolon);
134
+ let index = 0;
135
+ for (let j = 0; j < indices.length; j++) {
136
+ const offset = indices[j];
137
+ encodeInteger(writer, offset - index);
138
+ index = offset;
139
+ }
140
+ }
141
+ return writer.flush();
142
+ }
130
143
 
131
144
  // src/sourcemap-codec.ts
132
145
  function decode(mappings) {
@@ -146,15 +159,15 @@ function decode(mappings) {
146
159
  genColumn = 0;
147
160
  while (reader.pos < semi) {
148
161
  let seg;
149
- genColumn = decodeInteger(reader, genColumn);
162
+ genColumn += decodeSign(decodeInteger(reader));
150
163
  if (genColumn < lastCol) sorted = false;
151
164
  lastCol = genColumn;
152
165
  if (hasMoreVlq(reader, semi)) {
153
- sourcesIndex = decodeInteger(reader, sourcesIndex);
154
- sourceLine = decodeInteger(reader, sourceLine);
155
- sourceColumn = decodeInteger(reader, sourceColumn);
166
+ sourcesIndex += decodeSign(decodeInteger(reader));
167
+ sourceLine += decodeSign(decodeInteger(reader));
168
+ sourceColumn += decodeSign(decodeInteger(reader));
156
169
  if (hasMoreVlq(reader, semi)) {
157
- namesIndex = decodeInteger(reader, namesIndex);
170
+ namesIndex += decodeSign(decodeInteger(reader));
158
171
  seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];
159
172
  } else {
160
173
  seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
@@ -191,13 +204,18 @@ function encode(decoded) {
191
204
  for (let j = 0; j < line.length; j++) {
192
205
  const segment = line[j];
193
206
  if (j > 0) writer.write(comma);
194
- genColumn = encodeInteger(writer, segment[0], genColumn);
207
+ encodeInteger(writer, encodeSign(segment[0] - genColumn));
208
+ genColumn = segment[0];
195
209
  if (segment.length === 1) continue;
196
- sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
197
- sourceLine = encodeInteger(writer, segment[2], sourceLine);
198
- sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
210
+ encodeInteger(writer, encodeSign(segment[1] - sourcesIndex));
211
+ encodeInteger(writer, encodeSign(segment[2] - sourceLine));
212
+ encodeInteger(writer, encodeSign(segment[3] - sourceColumn));
213
+ sourcesIndex = segment[1];
214
+ sourceLine = segment[2];
215
+ sourceColumn = segment[3];
199
216
  if (segment.length === 4) continue;
200
- namesIndex = encodeInteger(writer, segment[4], namesIndex);
217
+ encodeInteger(writer, encodeSign(segment[4] - namesIndex));
218
+ namesIndex = segment[4];
201
219
  }
202
220
  }
203
221
  return writer.flush();
@@ -316,8 +334,10 @@ var Chunk$1 = class Chunk {
316
334
  if (this.outro.length) return true;
317
335
  const trimmed = this.content.replace(rx, "");
318
336
  if (trimmed.length) {
319
- if (trimmed !== this.content) if (this.edited) this.edit(trimmed, this.storeName, true);
320
- else this.split(this.start + trimmed.length).edit("", void 0, true);
337
+ if (trimmed !== this.content) {
338
+ if (this.edited) this.edit(trimmed, this.storeName, true);
339
+ else this.split(this.start + trimmed.length).edit("", void 0, true);
340
+ }
321
341
  return true;
322
342
  } else {
323
343
  this.edit("", void 0, true);
@@ -330,10 +350,12 @@ var Chunk$1 = class Chunk {
330
350
  if (this.intro.length) return true;
331
351
  const trimmed = this.content.replace(rx, "");
332
352
  if (trimmed.length) {
333
- if (trimmed !== this.content) if (this.edited) this.edit(trimmed, this.storeName, true);
334
- else {
335
- this.split(this.end - trimmed.length);
336
- this.edit("", void 0, true);
353
+ if (trimmed !== this.content) {
354
+ if (this.edited) this.edit(trimmed, this.storeName, true);
355
+ else {
356
+ this.split(this.end - trimmed.length);
357
+ this.edit("", void 0, true);
358
+ }
337
359
  }
338
360
  return true;
339
361
  } else {
@@ -360,12 +382,14 @@ var MagicStringError = class extends Error {
360
382
  //#endregion
361
383
  //#region src/SourceMap.ts
362
384
  function getBtoa() {
385
+ /* v8 ignore next -- environment fallback, unreachable when `btoa` is present */
363
386
  if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
364
387
  const buffer = globalThis["Buffer"];
365
388
  if (buffer) return (str) => buffer.from(str, "utf-8").toString("base64");
366
389
  return () => {
367
390
  throw new MagicStringError("unsupported environment: `btoa` or `Buffer` is required");
368
391
  };
392
+ /* v8 ignore stop */
369
393
  }
370
394
  const btoa = /* #__PURE__ */ getBtoa();
371
395
  var SourceMap = class {
@@ -378,6 +402,14 @@ var SourceMap = class {
378
402
  this.mappings = encode(properties.mappings);
379
403
  if (typeof properties.x_google_ignoreList !== "undefined") this.x_google_ignoreList = properties.x_google_ignoreList;
380
404
  if (typeof properties.debugId !== "undefined") this.debugId = properties.debugId;
405
+ if (typeof properties.rangeMappings !== "undefined") {
406
+ let shouldOutputRangeMapping = false;
407
+ for (const line of properties.rangeMappings) if (line.length !== 0) {
408
+ shouldOutputRangeMapping = true;
409
+ break;
410
+ }
411
+ if (shouldOutputRangeMapping) this.rangeMappings = encodeRangeMappings(properties.rangeMappings);
412
+ }
381
413
  }
382
414
  /**
383
415
  * Returns the equivalent of `JSON.stringify(map)`
@@ -396,12 +428,8 @@ var SourceMap = class {
396
428
  //#endregion
397
429
  //#region src/utils/getLocator.ts
398
430
  function getLocator(source) {
399
- const originalLines = source.split("\n");
400
- const lineOffsets = [];
401
- for (let i = 0, pos = 0; i < originalLines.length; i++) {
402
- lineOffsets.push(pos);
403
- pos += originalLines[i].length + 1;
404
- }
431
+ const lineOffsets = [0];
432
+ for (let i = source.indexOf("\n"); i !== -1; i = source.indexOf("\n", i + 1)) lineOffsets.push(i + 1);
405
433
  return function locate(index) {
406
434
  let i = 0;
407
435
  let j = lineOffsets.length;
@@ -455,7 +483,10 @@ function isObject(thing) {
455
483
  }
456
484
  //#endregion
457
485
  //#region src/utils/Mappings.ts
458
- const wordRegex = /\w/;
486
+ const NEWLINE_CHAR$1 = 10;
487
+ function isWordCode(code) {
488
+ return code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57 || code === 95;
489
+ }
459
490
  var Mappings = class {
460
491
  constructor(hires) {
461
492
  this.hires = hires;
@@ -463,9 +494,12 @@ var Mappings = class {
463
494
  this.generatedCodeColumn = 0;
464
495
  this.raw = [];
465
496
  this.rawSegments = this.raw[this.generatedCodeLine] = [];
497
+ this.rawRangeMappings = [];
498
+ this.rawRangeMappingsIndices = this.rawRangeMappings[this.generatedCodeLine] = [];
466
499
  this.pending = null;
467
500
  }
468
501
  addEdit(sourceIndex, content, loc, nameIndex) {
502
+ /* v8 ignore else -- `pending` is never assigned a truthy value */
469
503
  if (content.length) {
470
504
  const contentLengthMinusOne = content.length - 1;
471
505
  let contentLineEnd = content.indexOf("\n", 0);
@@ -481,6 +515,7 @@ var Mappings = class {
481
515
  this.rawSegments.push(segment);
482
516
  this.generatedCodeLine += 1;
483
517
  this.raw[this.generatedCodeLine] = this.rawSegments = [];
518
+ this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
484
519
  this.generatedCodeColumn = 0;
485
520
  previousContentLineEnd = contentLineEnd;
486
521
  contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
@@ -501,56 +536,128 @@ var Mappings = class {
501
536
  this.pending = null;
502
537
  }
503
538
  addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
504
- let originalCharIndex = chunk.start;
505
- let first = true;
506
- let charInHiresBoundary = false;
507
- while (originalCharIndex < chunk.end) {
508
- if (original[originalCharIndex] === "\n") {
509
- loc.line += 1;
510
- loc.column = 0;
511
- this.generatedCodeLine += 1;
512
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
513
- this.generatedCodeColumn = 0;
514
- first = true;
515
- charInHiresBoundary = false;
516
- } else {
517
- if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
518
- const segment = [
539
+ const end = chunk.end;
540
+ let i = chunk.start;
541
+ if (this.hires) {
542
+ const boundary = this.hires === "boundary";
543
+ const experimentalRange = this.hires === "experimental-range";
544
+ let charInHiresBoundary = false;
545
+ while (i < end) {
546
+ if (experimentalRange && i + 1 >= end) this.rawSegments.push([
547
+ this.generatedCodeColumn,
548
+ sourceIndex,
549
+ loc.line,
550
+ loc.column
551
+ ]);
552
+ const code = original.charCodeAt(i);
553
+ if (code === NEWLINE_CHAR$1) {
554
+ loc.line += 1;
555
+ loc.column = 0;
556
+ this.generatedCodeLine += 1;
557
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
558
+ this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
559
+ this.generatedCodeColumn = 0;
560
+ charInHiresBoundary = false;
561
+ } else {
562
+ if (boundary) {
563
+ if (isWordCode(code)) {
564
+ if (!charInHiresBoundary) {
565
+ this.rawSegments.push([
566
+ this.generatedCodeColumn,
567
+ sourceIndex,
568
+ loc.line,
569
+ loc.column
570
+ ]);
571
+ charInHiresBoundary = true;
572
+ }
573
+ } else {
574
+ this.rawSegments.push([
575
+ this.generatedCodeColumn,
576
+ sourceIndex,
577
+ loc.line,
578
+ loc.column
579
+ ]);
580
+ charInHiresBoundary = false;
581
+ }
582
+ } else if (experimentalRange) {
583
+ if (i === chunk.start) {
584
+ this.rawRangeMappingsIndices.push(this.rawSegments.length);
585
+ this.rawSegments.push([
586
+ this.generatedCodeColumn,
587
+ sourceIndex,
588
+ loc.line,
589
+ loc.column
590
+ ]);
591
+ }
592
+ } else this.rawSegments.push([
593
+ this.generatedCodeColumn,
594
+ sourceIndex,
595
+ loc.line,
596
+ loc.column
597
+ ]);
598
+ loc.column += 1;
599
+ this.generatedCodeColumn += 1;
600
+ }
601
+ i += 1;
602
+ }
603
+ } else {
604
+ const bits = sourcemapLocations.bits;
605
+ while (i < end) {
606
+ let newline = original.indexOf("\n", i);
607
+ if (newline === -1 || newline > end) newline = end;
608
+ if (newline > i) {
609
+ this.rawSegments.push([
519
610
  this.generatedCodeColumn,
520
611
  sourceIndex,
521
612
  loc.line,
522
613
  loc.column
523
- ];
524
- if (this.hires === "boundary") if (wordRegex.test(original[originalCharIndex])) {
525
- if (!charInHiresBoundary) {
526
- this.rawSegments.push(segment);
527
- charInHiresBoundary = true;
614
+ ]);
615
+ for (let w = i + 1 >> 5, last = newline - 1 >> 5; w <= last; w++) {
616
+ let word = bits[w];
617
+ if (!word) continue;
618
+ const base = w << 5;
619
+ while (word) {
620
+ const lowest = word & -word;
621
+ const index = base + 31 - Math.clz32(lowest);
622
+ if (index > i && index < newline) {
623
+ const offset = index - i;
624
+ this.rawSegments.push([
625
+ this.generatedCodeColumn + offset,
626
+ sourceIndex,
627
+ loc.line,
628
+ loc.column + offset
629
+ ]);
630
+ }
631
+ word ^= lowest;
528
632
  }
529
- } else {
530
- this.rawSegments.push(segment);
531
- charInHiresBoundary = false;
532
633
  }
533
- else this.rawSegments.push(segment);
634
+ loc.column += newline - i;
635
+ this.generatedCodeColumn += newline - i;
534
636
  }
535
- loc.column += 1;
536
- this.generatedCodeColumn += 1;
537
- first = false;
637
+ if (newline === end) break;
638
+ loc.line += 1;
639
+ loc.column = 0;
640
+ this.generatedCodeLine += 1;
641
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
642
+ this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
643
+ this.generatedCodeColumn = 0;
644
+ i = newline + 1;
538
645
  }
539
- originalCharIndex += 1;
540
646
  }
541
647
  this.pending = null;
542
648
  }
543
649
  advance(str) {
544
650
  if (!str) return;
545
- const lines = str.split("\n");
546
- if (lines.length > 1) {
547
- for (let i = 0; i < lines.length - 1; i++) {
651
+ const lastNewline = str.lastIndexOf("\n");
652
+ if (lastNewline !== -1) {
653
+ for (let i = str.indexOf("\n"); i !== -1; i = str.indexOf("\n", i + 1)) {
548
654
  this.generatedCodeLine++;
549
655
  this.raw[this.generatedCodeLine] = this.rawSegments = [];
656
+ this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
550
657
  }
551
658
  this.generatedCodeColumn = 0;
552
659
  }
553
- this.generatedCodeColumn += lines[lines.length - 1].length;
660
+ this.generatedCodeColumn += str.length - lastNewline - 1;
554
661
  }
555
662
  };
556
663
  //#endregion
@@ -563,6 +670,63 @@ const warned = {
563
670
  insertRight: false,
564
671
  storeName: false
565
672
  };
673
+ /**
674
+ * Expands the `$` substitution patterns that `String.prototype.replace` accepts
675
+ * in a string replacement.
676
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
677
+ *
678
+ * `captures` holds the capture groups in order, so `captures[0]` is `$1`.
679
+ * `namedCaptures` is `undefined` when the pattern has no named groups, and
680
+ * `$<name>` is then literal text - which is also the case for a string search
681
+ * value, where there are no groups of either kind.
682
+ */
683
+ function expandReplacement(replacement, matched, position, str, captures, namedCaptures) {
684
+ if (!replacement.includes("$")) return replacement;
685
+ let result = "";
686
+ let index = 0;
687
+ while (index < replacement.length) {
688
+ const dollar = replacement.indexOf("$", index);
689
+ if (dollar === -1) {
690
+ result += replacement.slice(index);
691
+ break;
692
+ }
693
+ result += replacement.slice(index, dollar);
694
+ const char = replacement[dollar + 1];
695
+ let expansion = "$";
696
+ let consumed = 1;
697
+ if (char === "$") consumed = 2;
698
+ else if (char === "&") {
699
+ expansion = matched;
700
+ consumed = 2;
701
+ } else if (char === "`") {
702
+ expansion = str.slice(0, position);
703
+ consumed = 2;
704
+ } else if (char === "'") {
705
+ expansion = str.slice(position + matched.length);
706
+ consumed = 2;
707
+ } else if (char === "<" && namedCaptures !== void 0) {
708
+ const close = replacement.indexOf(">", dollar + 2);
709
+ if (close !== -1) {
710
+ expansion = namedCaptures[replacement.slice(dollar + 2, close)] ?? "";
711
+ consumed = close + 1 - dollar;
712
+ }
713
+ } else if (char >= "0" && char <= "9") {
714
+ const second = replacement[dollar + 2];
715
+ const double = second >= "0" && second <= "9" ? Number(char + second) : NaN;
716
+ const single = Number(char);
717
+ if (double >= 1 && double <= captures.length) {
718
+ expansion = captures[double - 1] ?? "";
719
+ consumed = 3;
720
+ } else if (single >= 1 && single <= captures.length) {
721
+ expansion = captures[single - 1] ?? "";
722
+ consumed = 2;
723
+ }
724
+ }
725
+ result += expansion;
726
+ index = dollar + consumed;
727
+ }
728
+ return result;
729
+ }
566
730
  var MagicString = class MagicString {
567
731
  constructor(string, options = {}) {
568
732
  const chunk = new Chunk$1(0, string.length, string);
@@ -732,7 +896,8 @@ var MagicString = class MagicString {
732
896
  sourcesContent: options.includeContent ? [this.original] : void 0,
733
897
  names,
734
898
  mappings: mappings.raw,
735
- x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
899
+ x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0,
900
+ rangeMappings: mappings.rawRangeMappings
736
901
  };
737
902
  }
738
903
  /**
@@ -772,17 +937,18 @@ var MagicString = class MagicString {
772
937
  for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded[i] = true;
773
938
  });
774
939
  let shouldIndentNextCharacter = options.indentStart !== false;
775
- const replacer = (match) => {
776
- if (shouldIndentNextCharacter) return `${resolvedIndentStr}${match}`;
777
- shouldIndentNextCharacter = true;
778
- return match;
940
+ const indentPiece = (str) => {
941
+ if (str === "") return str;
942
+ const indented = str.replace(pattern, (match, offset) => offset > 0 || shouldIndentNextCharacter ? `${resolvedIndentStr}${match}` : match);
943
+ shouldIndentNextCharacter = str[str.length - 1] === "\n";
944
+ return indented;
779
945
  };
780
- this.intro = this.intro.replace(pattern, replacer);
946
+ this.intro = indentPiece(this.intro);
781
947
  let charIndex = 0;
782
948
  let chunk = this.firstChunk;
783
949
  const indentAt = (index) => {
784
950
  shouldIndentNextCharacter = false;
785
- if (index === chunk.start) chunk.prependRight(resolvedIndentStr);
951
+ if (index === chunk.start) chunk.appendRight(resolvedIndentStr);
786
952
  else {
787
953
  this._splitChunk(chunk, index);
788
954
  chunk = chunk.next;
@@ -791,11 +957,9 @@ var MagicString = class MagicString {
791
957
  };
792
958
  while (chunk) {
793
959
  const end = chunk.end;
960
+ if (!isExcluded[chunk.start]) chunk.intro = indentPiece(chunk.intro);
794
961
  if (chunk.edited) {
795
- if (!isExcluded[charIndex]) {
796
- chunk.content = chunk.content.replace(pattern, replacer);
797
- if (chunk.content.length) shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
798
- }
962
+ if (!isExcluded[charIndex]) chunk.content = indentPiece(chunk.content);
799
963
  } else if (options.exclude) {
800
964
  charIndex = chunk.start;
801
965
  while (charIndex < end) {
@@ -825,10 +989,11 @@ var MagicString = class MagicString {
825
989
  charIndex += 1;
826
990
  }
827
991
  }
992
+ if (!isExcluded[chunk.end - 1]) chunk.outro = indentPiece(chunk.outro);
828
993
  charIndex = chunk.end;
829
994
  chunk = chunk.next;
830
995
  }
831
- this.outro = this.outro.replace(pattern, replacer);
996
+ this.outro = indentPiece(this.outro);
832
997
  return this;
833
998
  }
834
999
  /** @internal */
@@ -922,8 +1087,8 @@ var MagicString = class MagicString {
922
1087
  end = end + this.offset;
923
1088
  if (typeof content !== "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
924
1089
  if (this.original.length !== 0) {
925
- while (start < 0) start += this.original.length;
926
- while (end < 0) end += this.original.length;
1090
+ if (start < 0) start = Math.max(0, start + this.original.length);
1091
+ if (end < 0) end = Math.max(0, end + this.original.length);
927
1092
  }
928
1093
  if (start < 0) throw new MagicStringError(`start ${start} is out of bounds`);
929
1094
  if (end > this.original.length) throw new MagicStringError(`end ${end} is out of bounds`);
@@ -951,6 +1116,7 @@ var MagicString = class MagicString {
951
1116
  }
952
1117
  const first = this.byStart.get(start);
953
1118
  const last = this.byEnd.get(end);
1119
+ /* v8 ignore else -- unreachable: a valid start/end always yields a `first` chunk */
954
1120
  if (first) {
955
1121
  let chunk = first;
956
1122
  while (chunk !== last) {
@@ -1006,8 +1172,8 @@ var MagicString = class MagicString {
1006
1172
  start = start + this.offset;
1007
1173
  end = end + this.offset;
1008
1174
  if (this.original.length !== 0) {
1009
- while (start < 0) start += this.original.length;
1010
- while (end < 0) end += this.original.length;
1175
+ if (start < 0) start = Math.max(0, start + this.original.length);
1176
+ if (end < 0) end = Math.max(0, end + this.original.length);
1011
1177
  }
1012
1178
  if (start === end) return this;
1013
1179
  if (start < 0 || end > this.original.length) throw new MagicStringError(`range ${start}–${end} is out of bounds`);
@@ -1030,8 +1196,8 @@ var MagicString = class MagicString {
1030
1196
  start = start + this.offset;
1031
1197
  end = end + this.offset;
1032
1198
  if (this.original.length !== 0) {
1033
- while (start < 0) start += this.original.length;
1034
- while (end < 0) end += this.original.length;
1199
+ if (start < 0) start = Math.max(0, start + this.original.length);
1200
+ if (end < 0) end = Math.max(0, end + this.original.length);
1035
1201
  }
1036
1202
  if (start === end) return this;
1037
1203
  if (start < 0 || end > this.original.length) throw new MagicStringError(`range ${start}–${end} is out of bounds`);
@@ -1092,8 +1258,8 @@ var MagicString = class MagicString {
1092
1258
  start = start + this.offset;
1093
1259
  end = end + this.offset;
1094
1260
  if (this.original.length !== 0) {
1095
- while (start < 0) start += this.original.length;
1096
- while (end < 0) end += this.original.length;
1261
+ if (start < 0) start = Math.max(0, start + this.original.length);
1262
+ if (end < 0) end = Math.max(0, end + this.original.length);
1097
1263
  }
1098
1264
  let result = "";
1099
1265
  let chunk = this.firstChunk;
@@ -1168,11 +1334,13 @@ var MagicString = class MagicString {
1168
1334
  * Returns true if the resulting source is empty (disregarding white space).
1169
1335
  */
1170
1336
  isEmpty() {
1337
+ if (this.intro.length && this.intro.trim()) return false;
1171
1338
  let chunk = this.firstChunk;
1172
1339
  while (chunk) {
1173
1340
  if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim()) return false;
1174
1341
  chunk = chunk.next;
1175
1342
  }
1343
+ if (this.outro.length && this.outro.trim()) return false;
1176
1344
  return true;
1177
1345
  }
1178
1346
  length() {
@@ -1271,35 +1439,23 @@ var MagicString = class MagicString {
1271
1439
  /** @internal */
1272
1440
  _replaceRegexp(searchValue, replacement) {
1273
1441
  function getReplacement(match, str) {
1274
- if (typeof replacement === "string") return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
1275
- if (i === "$") return "$";
1276
- if (i === "&") return match[0];
1277
- if (+i < match.length) return match[+i];
1278
- return `$${i}`;
1279
- });
1280
- else return replacement(match[0], ...match.slice(1), match.index, str, match.groups);
1281
- }
1282
- function matchAll(re, str) {
1283
- const matches = [];
1284
- while (true) {
1285
- const match = re.exec(str);
1286
- if (!match) break;
1287
- matches.push(match);
1288
- }
1289
- return matches;
1442
+ if (typeof replacement === "string") return expandReplacement(replacement, match[0], match.index, str, match.slice(1), match.groups);
1443
+ else return match.groups === void 0 ? replacement(match[0], ...match.slice(1), match.index, str) : replacement(match[0], ...match.slice(1), match.index, str, match.groups);
1290
1444
  }
1291
- if (searchValue.global) matchAll(searchValue, this.original).forEach((match) => {
1292
- if (match.index != null) {
1293
- const replacement = getReplacement(match, this.original);
1294
- if (replacement !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement);
1295
- }
1296
- });
1297
- else {
1445
+ const replaceMatch = (match) => {
1446
+ /* v8 ignore next 2 -- `match.index` is always defined for matches from `matchAll` */
1447
+ if (match.index == null) return;
1448
+ const replacement = getReplacement(match, this.original);
1449
+ if (replacement === match[0]) return;
1450
+ if (match[0].length === 0) this.appendRight(match.index, replacement);
1451
+ else this.overwrite(match.index, match.index + match[0].length, replacement);
1452
+ };
1453
+ if (searchValue.global) {
1454
+ searchValue.lastIndex = 0;
1455
+ for (const match of this.original.matchAll(searchValue)) replaceMatch(match);
1456
+ } else {
1298
1457
  const match = this.original.match(searchValue);
1299
- if (match && match.index != null) {
1300
- const replacement = getReplacement(match, this.original);
1301
- if (replacement !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement);
1302
- }
1458
+ if (match) replaceMatch(match);
1303
1459
  }
1304
1460
  return this;
1305
1461
  }
@@ -1309,7 +1465,11 @@ var MagicString = class MagicString {
1309
1465
  const index = original.indexOf(string);
1310
1466
  if (index !== -1) {
1311
1467
  if (typeof replacement === "function") replacement = replacement(string, index, original);
1312
- if (string !== replacement) this.overwrite(index, index + string.length, replacement);
1468
+ else replacement = expandReplacement(replacement, string, index, original, [], void 0);
1469
+ if (string !== replacement) {
1470
+ if (string.length === 0) this.appendRight(index, replacement);
1471
+ else this.overwrite(index, index + string.length, replacement);
1472
+ }
1313
1473
  }
1314
1474
  return this;
1315
1475
  }
@@ -1324,9 +1484,16 @@ var MagicString = class MagicString {
1324
1484
  _replaceAllString(string, replacement) {
1325
1485
  const { original } = this;
1326
1486
  const stringLength = string.length;
1487
+ if (stringLength === 0) {
1488
+ for (let index = 0; index <= original.length; index += 1) {
1489
+ const _replacement = typeof replacement === "function" ? replacement("", index, original) : expandReplacement(replacement, "", index, original, [], void 0);
1490
+ if (_replacement !== "") this.appendRight(index, _replacement);
1491
+ }
1492
+ return this;
1493
+ }
1327
1494
  for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
1328
1495
  const previous = original.slice(index, index + stringLength);
1329
- const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : replacement;
1496
+ const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : expandReplacement(replacement, previous, index, original, [], void 0);
1330
1497
  if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
1331
1498
  }
1332
1499
  return this;
@@ -1377,15 +1544,17 @@ var Bundle$1 = class Bundle {
1377
1544
  if (!hasOwnProp.call(source, option)) source[option] = source.content[option];
1378
1545
  });
1379
1546
  if (source.separator === void 0) source.separator = this.separator;
1380
- if (source.filename) if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
1381
- this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
1382
- this.uniqueSources.push({
1383
- filename: source.filename,
1384
- content: source.content.original
1385
- });
1386
- } else {
1387
- const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
1388
- if (source.content.original !== uniqueSource.content) throw new MagicStringError(`duplicate filename "${source.filename}" with different content, use unique filenames`);
1547
+ if (source.filename) {
1548
+ if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
1549
+ this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
1550
+ this.uniqueSources.push({
1551
+ filename: source.filename,
1552
+ content: source.content.original
1553
+ });
1554
+ } else {
1555
+ const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
1556
+ if (source.content.original !== uniqueSource.content) throw new MagicStringError(`duplicate filename "${source.filename}" with different content, use unique filenames`);
1557
+ }
1389
1558
  }
1390
1559
  this.sources.push(source);
1391
1560
  return this;
@@ -1424,7 +1593,9 @@ var Bundle$1 = class Bundle {
1424
1593
  const mappings = new Mappings(options.hires);
1425
1594
  if (this.intro) mappings.advance(this.intro);
1426
1595
  this.sources.forEach((source, i) => {
1427
- if (i > 0) mappings.advance(source.separator !== void 0 ? source.separator : this.separator);
1596
+ if (i > 0)
1597
+ /* v8 ignore next -- addSource always normalizes source.separator */
1598
+ mappings.advance(source.separator !== void 0 ? source.separator : this.separator);
1428
1599
  const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
1429
1600
  const magicString = source.content;
1430
1601
  const locate = getLocator(magicString.original);
@@ -1432,9 +1603,10 @@ var Bundle$1 = class Bundle {
1432
1603
  magicString.firstChunk.eachNext((chunk) => {
1433
1604
  const loc = locate(chunk.start);
1434
1605
  if (chunk.intro.length) mappings.advance(chunk.intro);
1435
- if (source.filename) if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
1436
- else mappings.addUneditedChunk(sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations);
1437
- else mappings.advance(chunk.content);
1606
+ if (source.filename) {
1607
+ if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
1608
+ else mappings.addUneditedChunk(sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations);
1609
+ } else mappings.advance(chunk.content);
1438
1610
  if (chunk.outro.length) mappings.advance(chunk.outro);
1439
1611
  });
1440
1612
  if (magicString.outro) mappings.advance(magicString.outro);
@@ -1449,11 +1621,12 @@ var Bundle$1 = class Bundle {
1449
1621
  return options.file ? getRelativePath(options.file, source.filename) : source.filename;
1450
1622
  }),
1451
1623
  sourcesContent: this.uniqueSources.map((source) => {
1452
- return options.includeContent ? source.content : null;
1624
+ return (typeof options.includeContent === "function" ? options.includeContent(source) : options.includeContent) ? source.content : null;
1453
1625
  }),
1454
1626
  names,
1455
1627
  mappings: mappings.raw,
1456
- x_google_ignoreList
1628
+ x_google_ignoreList,
1629
+ rangeMappings: mappings.rawRangeMappings
1457
1630
  };
1458
1631
  }
1459
1632
  generateMap(options) {
@@ -1468,7 +1641,7 @@ var Bundle$1 = class Bundle {
1468
1641
  indentStringCounts[indentStr] += 1;
1469
1642
  });
1470
1643
  return Object.keys(indentStringCounts).sort((a, b) => {
1471
- return indentStringCounts[a] - indentStringCounts[b];
1644
+ return indentStringCounts[b] - indentStringCounts[a];
1472
1645
  })[0] || " ";
1473
1646
  }
1474
1647
  indent(indentStr) {
@@ -1476,6 +1649,7 @@ var Bundle$1 = class Bundle {
1476
1649
  if (indentStr === "") return this;
1477
1650
  let trailingNewline = !this.intro || this.intro.slice(-1) === "\n";
1478
1651
  this.sources.forEach((source, i) => {
1652
+ /* v8 ignore next -- addSource always normalizes source.separator */
1479
1653
  const separator = source.separator !== void 0 ? source.separator : this.separator;
1480
1654
  const indentStart = trailingNewline || i > 0 && /\r?\n$/.test(separator);
1481
1655
  source.content.indent(indentStr, {
@@ -1495,6 +1669,7 @@ var Bundle$1 = class Bundle {
1495
1669
  }
1496
1670
  toString() {
1497
1671
  const body = this.sources.map((source, i) => {
1672
+ /* v8 ignore next -- addSource always normalizes source.separator */
1498
1673
  const separator = source.separator !== void 0 ? source.separator : this.separator;
1499
1674
  return (i > 0 ? separator : "") + source.content.toString();
1500
1675
  }).join("");
@@ -1503,6 +1678,7 @@ var Bundle$1 = class Bundle {
1503
1678
  isEmpty() {
1504
1679
  if (this.intro.length && this.intro.trim()) return false;
1505
1680
  if (this.sources.some((source, i) => {
1681
+ /* v8 ignore next -- addSource always normalizes source.separator */
1506
1682
  const separator = source.separator !== void 0 ? source.separator : this.separator;
1507
1683
  return i > 0 && separator.trim() !== "" || !source.content.isEmpty();
1508
1684
  })) return false;
@@ -1510,8 +1686,9 @@ var Bundle$1 = class Bundle {
1510
1686
  }
1511
1687
  length() {
1512
1688
  return this.sources.reduce((length, source, i) => {
1689
+ /* v8 ignore next -- addSource always normalizes source.separator */
1513
1690
  const separator = source.separator !== void 0 ? source.separator : this.separator;
1514
- return length + (i > 0 ? separator.length : 0) + source.content.length();
1691
+ return length + (i > 0 ? separator.length : 0) + source.content.toString().length;
1515
1692
  }, this.intro.length);
1516
1693
  }
1517
1694
  trimLines() {
@@ -1523,27 +1700,27 @@ var Bundle$1 = class Bundle {
1523
1700
  trimStart(charType) {
1524
1701
  const rx = new RegExp(`^${charType || "\\s"}+`);
1525
1702
  this.intro = this.intro.replace(rx, "");
1526
- if (!this.intro) {
1527
- let source;
1528
- let i = 0;
1529
- do {
1530
- source = this.sources[i++];
1531
- if (!source) break;
1532
- } while (!source.content.trimStartAborted(charType));
1703
+ if (!this.intro) for (let i = 0; i < this.sources.length; i += 1) {
1704
+ const source = this.sources[i];
1705
+ if (i > 0) {
1706
+ source.separator = (source.separator !== void 0 ? source.separator : this.separator).replace(rx, "");
1707
+ if (source.separator) break;
1708
+ }
1709
+ if (source.content.trimStartAborted(charType)) break;
1533
1710
  }
1534
1711
  return this;
1535
1712
  }
1536
1713
  trimEnd(charType) {
1537
1714
  const rx = new RegExp(`${charType || "\\s"}+$`);
1538
- let source;
1539
- let i = this.sources.length - 1;
1540
- do {
1541
- source = this.sources[i--];
1542
- if (!source) {
1543
- this.intro = this.intro.replace(rx, "");
1544
- break;
1715
+ for (let i = this.sources.length - 1; i >= 0; i -= 1) {
1716
+ const source = this.sources[i];
1717
+ if (source.content.trimEndAborted(charType)) return this;
1718
+ if (i > 0) {
1719
+ source.separator = (source.separator !== void 0 ? source.separator : this.separator).replace(rx, "");
1720
+ if (source.separator) return this;
1545
1721
  }
1546
- } while (!source.content.trimEndAborted(charType));
1722
+ }
1723
+ this.intro = this.intro.replace(rx, "");
1547
1724
  return this;
1548
1725
  }
1549
1726
  };
@@ -1594,6 +1771,14 @@ function findLastWhiteSpaceReverse(code, start, end) {
1594
1771
  }
1595
1772
  }
1596
1773
  }
1774
+ // A CRLF pair is one line break and must be removed as one. Removing only the
1775
+ // LF leaves the CR, which is still a line terminator, so ASI fires anyway and
1776
+ // the operand after a `return` or `throw` becomes dead code.
1777
+ function getLineBreakStart(code, lineBreakPos) {
1778
+ return lineBreakPos > 0 && code.charCodeAt(lineBreakPos - 1) === 13 /*"\r"*/
1779
+ ? lineBreakPos - 1
1780
+ : lineBreakPos;
1781
+ }
1597
1782
  // This assumes "code" only contains white-space and comments
1598
1783
  // Returns position of line-comment if applicable
1599
1784
  function findFirstLineBreakOutsideComment(code) {
@@ -1602,7 +1787,7 @@ function findFirstLineBreakOutsideComment(code) {
1602
1787
  while (true) {
1603
1788
  start = code.indexOf('/', start);
1604
1789
  if (start === -1 || start > lineBreakPos)
1605
- return [lineBreakPos, lineBreakPos + 1];
1790
+ return [getLineBreakStart(code, lineBreakPos), lineBreakPos + 1];
1606
1791
  // With our assumption, '/' always starts a comment. Determine comment type:
1607
1792
  charCodeAfterSlash = code.charCodeAt(start + 1);
1608
1793
  if (charCodeAfterSlash === 47 /*"/"*/)