rollup 4.63.2 → 4.63.4

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.2
4
- Sat, 12 Sep 2026 06:36:48 GMT - commit 43ed4ec364940fbce7054d8da1f92c695d1e6808
3
+ Rollup.js v4.63.4
4
+ Sat, 19 Sep 2026 06:35:38 GMT - commit ba78d5752a1e1ff4ff4af3a8bffab7691d822f7d
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.2";
30
+ var version = "4.63.4";
31
31
  const pkg = {
32
32
  version: version};
33
33
 
@@ -35,11 +35,11 @@ const pkg = {
35
35
  var comma = ",".charCodeAt(0);
36
36
  var semicolon = ";".charCodeAt(0);
37
37
  var chars$1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
38
- var intToChar = new Uint8Array(64);
38
+ var intToChar$1 = new Uint8Array(64);
39
39
  var charToInt = new Uint8Array(128);
40
40
  for (let i = 0; i < chars$1.length; i++) {
41
41
  const c = chars$1.charCodeAt(i);
42
- intToChar[i] = c;
42
+ intToChar$1[i] = c;
43
43
  charToInt[c] = i;
44
44
  }
45
45
  function decodeInteger(reader) {
@@ -62,7 +62,7 @@ function encodeInteger(builder, num) {
62
62
  let clamped = num & 31;
63
63
  num >>>= 5;
64
64
  if (num > 0) clamped |= 32;
65
- builder.write(intToChar[clamped]);
65
+ builder.write(intToChar$1[clamped]);
66
66
  } while (num > 0);
67
67
  }
68
68
  function encodeSign(num) {
@@ -125,6 +125,21 @@ var StringReader = class {
125
125
  return idx === -1 ? buffer.length : idx;
126
126
  }
127
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
+ }
128
143
 
129
144
  // src/sourcemap-codec.ts
130
145
  function decode(mappings) {
@@ -319,8 +334,10 @@ var Chunk$1 = class Chunk {
319
334
  if (this.outro.length) return true;
320
335
  const trimmed = this.content.replace(rx, "");
321
336
  if (trimmed.length) {
322
- if (trimmed !== this.content) if (this.edited) this.edit(trimmed, this.storeName, true);
323
- 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
+ }
324
341
  return true;
325
342
  } else {
326
343
  this.edit("", void 0, true);
@@ -333,10 +350,12 @@ var Chunk$1 = class Chunk {
333
350
  if (this.intro.length) return true;
334
351
  const trimmed = this.content.replace(rx, "");
335
352
  if (trimmed.length) {
336
- if (trimmed !== this.content) if (this.edited) this.edit(trimmed, this.storeName, true);
337
- else {
338
- this.split(this.end - trimmed.length);
339
- 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
+ }
340
359
  }
341
360
  return true;
342
361
  } else {
@@ -363,12 +382,14 @@ var MagicStringError = class extends Error {
363
382
  //#endregion
364
383
  //#region src/SourceMap.ts
365
384
  function getBtoa() {
385
+ /* v8 ignore next -- environment fallback, unreachable when `btoa` is present */
366
386
  if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
367
387
  const buffer = globalThis["Buffer"];
368
388
  if (buffer) return (str) => buffer.from(str, "utf-8").toString("base64");
369
389
  return () => {
370
390
  throw new MagicStringError("unsupported environment: `btoa` or `Buffer` is required");
371
391
  };
392
+ /* v8 ignore stop */
372
393
  }
373
394
  const btoa = /* #__PURE__ */ getBtoa();
374
395
  var SourceMap = class {
@@ -378,9 +399,17 @@ var SourceMap = class {
378
399
  this.sources = properties.sources;
379
400
  this.sourcesContent = properties.sourcesContent;
380
401
  this.names = properties.names;
381
- this.mappings = encode(properties.mappings);
402
+ this.mappings = typeof properties.mappings === "string" ? properties.mappings : encode(properties.mappings);
382
403
  if (typeof properties.x_google_ignoreList !== "undefined") this.x_google_ignoreList = properties.x_google_ignoreList;
383
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
+ }
384
413
  }
385
414
  /**
386
415
  * Returns the equivalent of `JSON.stringify(map)`
@@ -399,12 +428,8 @@ var SourceMap = class {
399
428
  //#endregion
400
429
  //#region src/utils/getLocator.ts
401
430
  function getLocator(source) {
402
- const originalLines = source.split("\n");
403
- const lineOffsets = [];
404
- for (let i = 0, pos = 0; i < originalLines.length; i++) {
405
- lineOffsets.push(pos);
406
- pos += originalLines[i].length + 1;
407
- }
431
+ const lineOffsets = [0];
432
+ for (let i = source.indexOf("\n"); i !== -1; i = source.indexOf("\n", i + 1)) lineOffsets.push(i + 1);
408
433
  return function locate(index) {
409
434
  let i = 0;
410
435
  let j = lineOffsets.length;
@@ -456,17 +481,122 @@ const toString = Object.prototype.toString;
456
481
  function isObject(thing) {
457
482
  return toString.call(thing) === "[object Object]";
458
483
  }
484
+ const BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
485
+ const intToChar = /* #__PURE__ */ (() => {
486
+ const chars = /* @__PURE__ */ new Uint8Array(64);
487
+ for (let i = 0; i < 64; i++) chars[i] = BASE64_CHARS.charCodeAt(i);
488
+ return chars;
489
+ })();
490
+ const COMMA = 44;
491
+ const SEMICOLON = 59;
492
+ const BUFFER_SIZE = 16384;
493
+ const FLUSH_THRESHOLD = 16348;
494
+ const scratch = /* #__PURE__ */ new Uint8Array(BUFFER_SIZE);
495
+ function writeVlq(pos, num) {
496
+ num = num < 0 ? -num << 1 | 1 : num << 1;
497
+ do {
498
+ let clamped = num & 31;
499
+ num >>>= 5;
500
+ if (num > 0) clamped |= 32;
501
+ scratch[pos++] = intToChar[clamped];
502
+ } while (num > 0);
503
+ return pos;
504
+ }
505
+ const decoder = /* #__PURE__ */ new TextDecoder();
506
+ var MappingsEncoder = class {
507
+ constructor() {
508
+ this.out = "";
509
+ this.pos = 0;
510
+ this.lines = [];
511
+ this.buffered = 0;
512
+ this.needsComma = false;
513
+ this.prevGenColumn = 0;
514
+ this.prevSourceIndex = 0;
515
+ this.prevSourceLine = 0;
516
+ this.prevSourceColumn = 0;
517
+ this.prevNameIndex = 0;
518
+ }
519
+ endLine(segments) {
520
+ this.lines.push(segments);
521
+ this.buffered += segments.length + 1;
522
+ if (this.buffered >= 4096) this.drain(null);
523
+ }
524
+ segments(segments) {
525
+ this.drain(segments);
526
+ }
527
+ finish(segments) {
528
+ this.drain(segments);
529
+ this.flush();
530
+ return this.out;
531
+ }
532
+ drain(trailing) {
533
+ const lines = this.lines;
534
+ const lineCount = lines.length;
535
+ for (let l = 0; l <= lineCount; l++) {
536
+ const line = l < lineCount ? lines[l] : trailing;
537
+ if (line === null) break;
538
+ for (let i = 0; i < line.length; i++) {
539
+ if (this.pos > FLUSH_THRESHOLD) this.flush();
540
+ const segment = line[i];
541
+ if (this.needsComma) scratch[this.pos++] = COMMA;
542
+ this.needsComma = true;
543
+ this.pos = writeVlq(this.pos, segment[0] - this.prevGenColumn);
544
+ this.prevGenColumn = segment[0];
545
+ this.pos = writeVlq(this.pos, segment[1] - this.prevSourceIndex);
546
+ this.prevSourceIndex = segment[1];
547
+ this.pos = writeVlq(this.pos, segment[2] - this.prevSourceLine);
548
+ this.prevSourceLine = segment[2];
549
+ this.pos = writeVlq(this.pos, segment[3] - this.prevSourceColumn);
550
+ this.prevSourceColumn = segment[3];
551
+ if (segment.length === 5) {
552
+ this.pos = writeVlq(this.pos, segment[4] - this.prevNameIndex);
553
+ this.prevNameIndex = segment[4];
554
+ }
555
+ }
556
+ if (l < lineCount) {
557
+ if (this.pos > FLUSH_THRESHOLD) this.flush();
558
+ scratch[this.pos++] = SEMICOLON;
559
+ this.needsComma = false;
560
+ this.prevGenColumn = 0;
561
+ }
562
+ }
563
+ lines.length = 0;
564
+ this.buffered = 0;
565
+ this.flush();
566
+ }
567
+ flush() {
568
+ this.out += decoder.decode(scratch.subarray(0, this.pos));
569
+ this.pos = 0;
570
+ }
571
+ };
459
572
  //#endregion
460
573
  //#region src/utils/Mappings.ts
461
- const wordRegex = /\w/;
574
+ const NEWLINE_CHAR$1 = 10;
575
+ function isWordCode(code) {
576
+ return code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57 || code === 95;
577
+ }
462
578
  var Mappings = class {
463
- constructor(hires) {
579
+ constructor(hires, encoder = null) {
464
580
  this.hires = hires;
465
581
  this.generatedCodeLine = 0;
466
582
  this.generatedCodeColumn = 0;
467
583
  this.raw = [];
468
584
  this.rawSegments = this.raw[this.generatedCodeLine] = [];
469
- this.pending = null;
585
+ this.rawRangeMappings = [];
586
+ this.rawRangeMappingsIndices = this.rawRangeMappings[this.generatedCodeLine] = [];
587
+ this.encoder = encoder;
588
+ }
589
+ nextLine() {
590
+ if (this.encoder === null) {
591
+ this.generatedCodeLine += 1;
592
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
593
+ } else {
594
+ this.encoder.endLine(this.rawSegments);
595
+ this.rawSegments = [];
596
+ this.generatedCodeLine += 1;
597
+ }
598
+ this.generatedCodeColumn = 0;
599
+ this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
470
600
  }
471
601
  addEdit(sourceIndex, content, loc, nameIndex) {
472
602
  if (content.length) {
@@ -482,9 +612,7 @@ var Mappings = class {
482
612
  ];
483
613
  if (nameIndex >= 0) segment.push(nameIndex);
484
614
  this.rawSegments.push(segment);
485
- this.generatedCodeLine += 1;
486
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
487
- this.generatedCodeColumn = 0;
615
+ this.nextLine();
488
616
  previousContentLineEnd = contentLineEnd;
489
617
  contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
490
618
  }
@@ -497,63 +625,122 @@ var Mappings = class {
497
625
  if (nameIndex >= 0) segment.push(nameIndex);
498
626
  this.rawSegments.push(segment);
499
627
  this.advance(content.slice(previousContentLineEnd + 1));
500
- } else if (this.pending) {
501
- this.rawSegments.push(this.pending);
502
- this.advance(content);
503
628
  }
504
- this.pending = null;
505
629
  }
506
630
  addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
507
- let originalCharIndex = chunk.start;
508
- let first = true;
509
- let charInHiresBoundary = false;
510
- while (originalCharIndex < chunk.end) {
511
- if (original[originalCharIndex] === "\n") {
512
- loc.line += 1;
513
- loc.column = 0;
514
- this.generatedCodeLine += 1;
515
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
516
- this.generatedCodeColumn = 0;
517
- first = true;
518
- charInHiresBoundary = false;
519
- } else {
520
- if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
521
- const segment = [
631
+ const end = chunk.end;
632
+ let i = chunk.start;
633
+ if (this.hires) {
634
+ const boundary = this.hires === "boundary";
635
+ const experimentalRange = this.hires === "experimental-range";
636
+ const encoder = experimentalRange ? null : this.encoder;
637
+ let charInHiresBoundary = false;
638
+ while (i < end) {
639
+ if (encoder !== null && this.rawSegments.length >= 4096) {
640
+ encoder.segments(this.rawSegments);
641
+ this.rawSegments.length = 0;
642
+ }
643
+ if (experimentalRange && i + 1 >= end) this.rawSegments.push([
644
+ this.generatedCodeColumn,
645
+ sourceIndex,
646
+ loc.line,
647
+ loc.column
648
+ ]);
649
+ const code = original.charCodeAt(i);
650
+ if (code === NEWLINE_CHAR$1) {
651
+ loc.line += 1;
652
+ loc.column = 0;
653
+ this.nextLine();
654
+ charInHiresBoundary = false;
655
+ } else {
656
+ if (boundary) {
657
+ if (isWordCode(code)) {
658
+ if (!charInHiresBoundary) {
659
+ this.rawSegments.push([
660
+ this.generatedCodeColumn,
661
+ sourceIndex,
662
+ loc.line,
663
+ loc.column
664
+ ]);
665
+ charInHiresBoundary = true;
666
+ }
667
+ } else {
668
+ this.rawSegments.push([
669
+ this.generatedCodeColumn,
670
+ sourceIndex,
671
+ loc.line,
672
+ loc.column
673
+ ]);
674
+ charInHiresBoundary = false;
675
+ }
676
+ } else if (experimentalRange) {
677
+ if (i === chunk.start) {
678
+ this.rawRangeMappingsIndices.push(this.rawSegments.length);
679
+ this.rawSegments.push([
680
+ this.generatedCodeColumn,
681
+ sourceIndex,
682
+ loc.line,
683
+ loc.column
684
+ ]);
685
+ }
686
+ } else this.rawSegments.push([
687
+ this.generatedCodeColumn,
688
+ sourceIndex,
689
+ loc.line,
690
+ loc.column
691
+ ]);
692
+ loc.column += 1;
693
+ this.generatedCodeColumn += 1;
694
+ }
695
+ i += 1;
696
+ }
697
+ } else {
698
+ const bits = sourcemapLocations.bits;
699
+ while (i < end) {
700
+ let newline = original.indexOf("\n", i);
701
+ if (newline === -1 || newline > end) newline = end;
702
+ if (newline > i) {
703
+ this.rawSegments.push([
522
704
  this.generatedCodeColumn,
523
705
  sourceIndex,
524
706
  loc.line,
525
707
  loc.column
526
- ];
527
- if (this.hires === "boundary") if (wordRegex.test(original[originalCharIndex])) {
528
- if (!charInHiresBoundary) {
529
- this.rawSegments.push(segment);
530
- charInHiresBoundary = true;
708
+ ]);
709
+ for (let w = i + 1 >> 5, last = newline - 1 >> 5; w <= last; w++) {
710
+ let word = bits[w];
711
+ if (!word) continue;
712
+ const base = w << 5;
713
+ while (word) {
714
+ const lowest = word & -word;
715
+ const index = base + 31 - Math.clz32(lowest);
716
+ if (index > i && index < newline) {
717
+ const offset = index - i;
718
+ this.rawSegments.push([
719
+ this.generatedCodeColumn + offset,
720
+ sourceIndex,
721
+ loc.line,
722
+ loc.column + offset
723
+ ]);
724
+ }
725
+ word ^= lowest;
531
726
  }
532
- } else {
533
- this.rawSegments.push(segment);
534
- charInHiresBoundary = false;
535
727
  }
536
- else this.rawSegments.push(segment);
728
+ loc.column += newline - i;
729
+ this.generatedCodeColumn += newline - i;
537
730
  }
538
- loc.column += 1;
539
- this.generatedCodeColumn += 1;
540
- first = false;
731
+ if (newline === end) break;
732
+ loc.line += 1;
733
+ loc.column = 0;
734
+ this.nextLine();
735
+ i = newline + 1;
541
736
  }
542
- originalCharIndex += 1;
543
737
  }
544
- this.pending = null;
545
738
  }
546
739
  advance(str) {
547
740
  if (!str) return;
548
- const lines = str.split("\n");
549
- if (lines.length > 1) {
550
- for (let i = 0; i < lines.length - 1; i++) {
551
- this.generatedCodeLine++;
552
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
553
- }
554
- this.generatedCodeColumn = 0;
555
- }
556
- this.generatedCodeColumn += lines[lines.length - 1].length;
741
+ const lastNewline = str.lastIndexOf("\n");
742
+ for (let i = str.indexOf("\n"); i !== -1; i = str.indexOf("\n", i + 1)) this.nextLine();
743
+ this.generatedCodeColumn += str.length - lastNewline - 1;
557
744
  }
558
745
  };
559
746
  //#endregion
@@ -566,6 +753,63 @@ const warned = {
566
753
  insertRight: false,
567
754
  storeName: false
568
755
  };
756
+ /**
757
+ * Expands the `$` substitution patterns that `String.prototype.replace` accepts
758
+ * in a string replacement.
759
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
760
+ *
761
+ * `captures` holds the capture groups in order, so `captures[0]` is `$1`.
762
+ * `namedCaptures` is `undefined` when the pattern has no named groups, and
763
+ * `$<name>` is then literal text - which is also the case for a string search
764
+ * value, where there are no groups of either kind.
765
+ */
766
+ function expandReplacement(replacement, matched, position, str, captures, namedCaptures) {
767
+ if (!replacement.includes("$")) return replacement;
768
+ let result = "";
769
+ let index = 0;
770
+ while (index < replacement.length) {
771
+ const dollar = replacement.indexOf("$", index);
772
+ if (dollar === -1) {
773
+ result += replacement.slice(index);
774
+ break;
775
+ }
776
+ result += replacement.slice(index, dollar);
777
+ const char = replacement[dollar + 1];
778
+ let expansion = "$";
779
+ let consumed = 1;
780
+ if (char === "$") consumed = 2;
781
+ else if (char === "&") {
782
+ expansion = matched;
783
+ consumed = 2;
784
+ } else if (char === "`") {
785
+ expansion = str.slice(0, position);
786
+ consumed = 2;
787
+ } else if (char === "'") {
788
+ expansion = str.slice(position + matched.length);
789
+ consumed = 2;
790
+ } else if (char === "<" && namedCaptures !== void 0) {
791
+ const close = replacement.indexOf(">", dollar + 2);
792
+ if (close !== -1) {
793
+ expansion = namedCaptures[replacement.slice(dollar + 2, close)] ?? "";
794
+ consumed = close + 1 - dollar;
795
+ }
796
+ } else if (char >= "0" && char <= "9") {
797
+ const second = replacement[dollar + 2];
798
+ const double = second >= "0" && second <= "9" ? Number(char + second) : NaN;
799
+ const single = Number(char);
800
+ if (double >= 1 && double <= captures.length) {
801
+ expansion = captures[double - 1] ?? "";
802
+ consumed = 3;
803
+ } else if (single >= 1 && single <= captures.length) {
804
+ expansion = captures[single - 1] ?? "";
805
+ consumed = 2;
806
+ }
807
+ }
808
+ result += expansion;
809
+ index = dollar + consumed;
810
+ }
811
+ return result;
812
+ }
569
813
  var MagicString = class MagicString {
570
814
  constructor(string, options = {}) {
571
815
  const chunk = new Chunk$1(0, string.length, string);
@@ -716,9 +960,32 @@ var MagicString = class MagicString {
716
960
  */
717
961
  generateDecodedMap(options) {
718
962
  options = options || {};
963
+ const mappings = new Mappings(options.hires);
964
+ const names = this._generateMappings(mappings);
965
+ return {
966
+ ...this._mapProperties(options, names),
967
+ mappings: mappings.raw,
968
+ rangeMappings: mappings.rawRangeMappings
969
+ };
970
+ }
971
+ /**
972
+ * Generates a version 3 sourcemap.
973
+ */
974
+ generateMap(options) {
975
+ options = options || {};
976
+ const encoder = new MappingsEncoder();
977
+ const mappings = new Mappings(options.hires, encoder);
978
+ const names = this._generateMappings(mappings);
979
+ return new SourceMap({
980
+ ...this._mapProperties(options, names),
981
+ mappings: encoder.finish(mappings.rawSegments),
982
+ rangeMappings: mappings.rawRangeMappings
983
+ });
984
+ }
985
+ /** @internal */
986
+ _generateMappings(mappings) {
719
987
  const sourceIndex = 0;
720
988
  const names = Object.keys(this.storedNames);
721
- const mappings = new Mappings(options.hires);
722
989
  const locate = getLocator(this.original);
723
990
  if (this.intro) mappings.advance(this.intro);
724
991
  this.firstChunk.eachNext((chunk) => {
@@ -729,21 +996,18 @@ var MagicString = class MagicString {
729
996
  if (chunk.outro.length) mappings.advance(chunk.outro);
730
997
  });
731
998
  if (this.outro) mappings.advance(this.outro);
999
+ return names;
1000
+ }
1001
+ /** @internal */
1002
+ _mapProperties(options, names) {
732
1003
  return {
733
1004
  file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
734
1005
  sources: [options.source ? getRelativePath(options.file || "", options.source) : options.file || ""],
735
1006
  sourcesContent: options.includeContent ? [this.original] : void 0,
736
1007
  names,
737
- mappings: mappings.raw,
738
- x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
1008
+ x_google_ignoreList: this.ignoreList ? [0] : void 0
739
1009
  };
740
1010
  }
741
- /**
742
- * Generates a version 3 sourcemap.
743
- */
744
- generateMap(options) {
745
- return new SourceMap(this.generateDecodedMap(options));
746
- }
747
1011
  /** @internal */
748
1012
  _ensureindentStr() {
749
1013
  if (this.indentStr === void 0) this.indentStr = guessIndent(this.original);
@@ -775,17 +1039,18 @@ var MagicString = class MagicString {
775
1039
  for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded[i] = true;
776
1040
  });
777
1041
  let shouldIndentNextCharacter = options.indentStart !== false;
778
- const replacer = (match) => {
779
- if (shouldIndentNextCharacter) return `${resolvedIndentStr}${match}`;
780
- shouldIndentNextCharacter = true;
781
- return match;
1042
+ const indentPiece = (str) => {
1043
+ if (str === "") return str;
1044
+ const indented = str.replace(pattern, (match, offset) => offset > 0 || shouldIndentNextCharacter ? `${resolvedIndentStr}${match}` : match);
1045
+ shouldIndentNextCharacter = str[str.length - 1] === "\n";
1046
+ return indented;
782
1047
  };
783
- this.intro = this.intro.replace(pattern, replacer);
1048
+ this.intro = indentPiece(this.intro);
784
1049
  let charIndex = 0;
785
1050
  let chunk = this.firstChunk;
786
1051
  const indentAt = (index) => {
787
1052
  shouldIndentNextCharacter = false;
788
- if (index === chunk.start) chunk.prependRight(resolvedIndentStr);
1053
+ if (index === chunk.start) chunk.appendRight(resolvedIndentStr);
789
1054
  else {
790
1055
  this._splitChunk(chunk, index);
791
1056
  chunk = chunk.next;
@@ -794,11 +1059,9 @@ var MagicString = class MagicString {
794
1059
  };
795
1060
  while (chunk) {
796
1061
  const end = chunk.end;
1062
+ if (!isExcluded[chunk.start]) chunk.intro = indentPiece(chunk.intro);
797
1063
  if (chunk.edited) {
798
- if (!isExcluded[charIndex]) {
799
- chunk.content = chunk.content.replace(pattern, replacer);
800
- if (chunk.content.length) shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
801
- }
1064
+ if (!isExcluded[charIndex]) chunk.content = indentPiece(chunk.content);
802
1065
  } else if (options.exclude) {
803
1066
  charIndex = chunk.start;
804
1067
  while (charIndex < end) {
@@ -828,10 +1091,11 @@ var MagicString = class MagicString {
828
1091
  charIndex += 1;
829
1092
  }
830
1093
  }
1094
+ if (!isExcluded[chunk.end - 1]) chunk.outro = indentPiece(chunk.outro);
831
1095
  charIndex = chunk.end;
832
1096
  chunk = chunk.next;
833
1097
  }
834
- this.outro = this.outro.replace(pattern, replacer);
1098
+ this.outro = indentPiece(this.outro);
835
1099
  return this;
836
1100
  }
837
1101
  /** @internal */
@@ -856,8 +1120,14 @@ var MagicString = class MagicString {
856
1120
  }
857
1121
  /**
858
1122
  * Moves the characters from `start` and `end` to `index`.
1123
+ *
1124
+ * `affinity` controls where the range is anchored at `index`. With the
1125
+ * default `'right'`, it is inserted before the content that starts at `index`;
1126
+ * with `'left'`, it is inserted after the content that ends at `index`. The
1127
+ * two differ only when other content has already been moved to that boundary,
1128
+ * mirroring the `appendLeft`/`appendRight` distinction.
859
1129
  */
860
- move(start, end, index) {
1130
+ move(start, end, index, affinity = "right") {
861
1131
  start = start + this.offset;
862
1132
  end = end + this.offset;
863
1133
  index = index + this.offset;
@@ -877,9 +1147,27 @@ var MagicString = class MagicString {
877
1147
  }
878
1148
  const oldLeft = first.previous;
879
1149
  const oldRight = last.next;
880
- const newRight = this.byStart.get(index);
881
- if (!newRight && last === this.lastChunk) return this;
882
- const newLeft = newRight ? newRight.previous : this.lastChunk;
1150
+ let newLeft;
1151
+ let newRight;
1152
+ if (affinity === "left") {
1153
+ newLeft = this.byEnd.get(index) ?? null;
1154
+ if (!newLeft) {
1155
+ if (first === this.firstChunk) return this;
1156
+ newRight = this.firstChunk;
1157
+ } else {
1158
+ if (newLeft.next === first) return this;
1159
+ newRight = newLeft.next;
1160
+ }
1161
+ } else {
1162
+ newRight = this.byStart.get(index) ?? null;
1163
+ if (!newRight) {
1164
+ if (last === this.lastChunk) return this;
1165
+ newLeft = this.lastChunk;
1166
+ } else {
1167
+ if (newRight.previous === last) return this;
1168
+ newLeft = newRight.previous;
1169
+ }
1170
+ }
883
1171
  if (oldLeft) oldLeft.next = oldRight;
884
1172
  if (oldRight) oldRight.previous = oldLeft;
885
1173
  if (newLeft) newLeft.next = first;
@@ -954,6 +1242,7 @@ var MagicString = class MagicString {
954
1242
  }
955
1243
  const first = this.byStart.get(start);
956
1244
  const last = this.byEnd.get(end);
1245
+ /* v8 ignore else -- unreachable: a valid start/end always yields a `first` chunk */
957
1246
  if (first) {
958
1247
  let chunk = first;
959
1248
  while (chunk !== last) {
@@ -1003,6 +1292,9 @@ var MagicString = class MagicString {
1003
1292
  }
1004
1293
  /**
1005
1294
  * Removes the characters from `start` to `end` (of the original string, **not** the generated string).
1295
+ * Content appended or prepended at positions strictly inside the range is removed with it, while
1296
+ * content attached at `start` or `end` is preserved — use `s.overwrite(start, end, '')` to remove
1297
+ * the range including its edge inserts.
1006
1298
  * Removing the same content twice, or making removals that partially overlap, will cause an error.
1007
1299
  */
1008
1300
  remove(start, end) {
@@ -1019,9 +1311,9 @@ var MagicString = class MagicString {
1019
1311
  this._split(end);
1020
1312
  let chunk = this.byStart.get(start);
1021
1313
  while (chunk) {
1022
- chunk.intro = "";
1023
- chunk.outro = "";
1024
- chunk.edit("");
1314
+ if (chunk.start > start) chunk.intro = "";
1315
+ if (chunk.end < end) chunk.outro = "";
1316
+ chunk.edit("", false, true);
1025
1317
  chunk = end > chunk.end ? this.byStart.get(chunk.end) : null;
1026
1318
  }
1027
1319
  return this;
@@ -1101,12 +1393,13 @@ var MagicString = class MagicString {
1101
1393
  let result = "";
1102
1394
  let chunk = this.firstChunk;
1103
1395
  while (chunk && (chunk.start > start || chunk.end <= start)) {
1104
- if (chunk.start < end && chunk.end >= end) return result;
1396
+ if (chunk.start < end && chunk.end >= end || end === 0 && chunk.start === 0) return result;
1105
1397
  chunk = chunk.next;
1106
1398
  }
1107
1399
  if (chunk && chunk.edited && chunk.start !== start) throw new MagicStringError(`cannot use edited character ${start} as slice start anchor`);
1108
1400
  const startChunk = chunk;
1109
1401
  while (chunk) {
1402
+ if (end === 0 && chunk.start === 0) break;
1110
1403
  if (chunk.intro && (startChunk !== chunk || chunk.start === start)) result += chunk.intro;
1111
1404
  const containsEnd = chunk.start < end && chunk.end >= end;
1112
1405
  if (containsEnd && chunk.edited && chunk.end !== end) throw new MagicStringError(`cannot use edited character ${end} as slice end anchor`);
@@ -1171,11 +1464,13 @@ var MagicString = class MagicString {
1171
1464
  * Returns true if the resulting source is empty (disregarding white space).
1172
1465
  */
1173
1466
  isEmpty() {
1467
+ if (this.intro.length && this.intro.trim()) return false;
1174
1468
  let chunk = this.firstChunk;
1175
1469
  while (chunk) {
1176
1470
  if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim()) return false;
1177
1471
  chunk = chunk.next;
1178
1472
  }
1473
+ if (this.outro.length && this.outro.trim()) return false;
1179
1474
  return true;
1180
1475
  }
1181
1476
  length() {
@@ -1217,7 +1512,8 @@ var MagicString = class MagicString {
1217
1512
  if (aborted) return true;
1218
1513
  chunk = chunk.previous;
1219
1514
  } while (chunk);
1220
- return false;
1515
+ this.intro = this.intro.replace(rx, "");
1516
+ return this.intro.length > 0;
1221
1517
  }
1222
1518
  /**
1223
1519
  * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.
@@ -1244,7 +1540,8 @@ var MagicString = class MagicString {
1244
1540
  if (aborted) return true;
1245
1541
  chunk = chunk.next;
1246
1542
  } while (chunk);
1247
- return false;
1543
+ this.outro = this.outro.replace(rx, "");
1544
+ return this.outro.length > 0;
1248
1545
  }
1249
1546
  /**
1250
1547
  * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.
@@ -1271,41 +1568,66 @@ var MagicString = class MagicString {
1271
1568
  }
1272
1569
  return outputIndex !== this.original.length;
1273
1570
  }
1571
+ /**
1572
+ * Whether the original range [start, end) has had any of its characters
1573
+ * removed. `replace`/`replaceAll` search `original`, so a match can land on
1574
+ * text that is no longer in the output - overwriting it would resurrect the
1575
+ * removed characters, so such matches are skipped instead.
1576
+ *
1577
+ * @internal
1578
+ */
1579
+ _hasRemovedContent(start, end) {
1580
+ let chunk = this.firstChunk;
1581
+ while (chunk) {
1582
+ if (chunk.content === "" && chunk.start < end && chunk.end > start) return true;
1583
+ chunk = chunk.next;
1584
+ }
1585
+ return false;
1586
+ }
1274
1587
  /** @internal */
1275
1588
  _replaceRegexp(searchValue, replacement) {
1276
1589
  function getReplacement(match, str) {
1277
- if (typeof replacement === "string") return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
1278
- if (i === "$") return "$";
1279
- if (i === "&") return match[0];
1280
- if (+i < match.length) return match[+i];
1281
- return `$${i}`;
1282
- });
1283
- else return replacement(match[0], ...match.slice(1), match.index, str, match.groups);
1590
+ if (typeof replacement === "string") return expandReplacement(replacement, match[0], match.index, str, match.slice(1), match.groups);
1591
+ 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);
1284
1592
  }
1285
1593
  const replaceMatch = (match) => {
1286
- if (match.index == null) return;
1594
+ /* v8 ignore next 2 -- `match.index` is always defined for matches from `matchAll` */
1595
+ if (match.index == null) return false;
1596
+ if (this._hasRemovedContent(match.index, match.index + match[0].length)) return false;
1287
1597
  const replacement = getReplacement(match, this.original);
1288
- if (replacement === match[0]) return;
1598
+ if (replacement === match[0]) return true;
1289
1599
  if (match[0].length === 0) this.appendRight(match.index, replacement);
1290
1600
  else this.overwrite(match.index, match.index + match[0].length, replacement);
1601
+ return true;
1291
1602
  };
1292
1603
  if (searchValue.global) {
1293
1604
  searchValue.lastIndex = 0;
1294
1605
  for (const match of this.original.matchAll(searchValue)) replaceMatch(match);
1295
1606
  } else {
1296
1607
  const match = this.original.match(searchValue);
1297
- if (match) replaceMatch(match);
1608
+ if (match && !replaceMatch(match)) {
1609
+ const global = new RegExp(searchValue.source, `${searchValue.flags}g`);
1610
+ for (const next of this.original.matchAll(global)) if (replaceMatch(next)) break;
1611
+ }
1298
1612
  }
1299
1613
  return this;
1300
1614
  }
1301
1615
  /** @internal */
1302
1616
  _replaceString(string, replacement) {
1303
1617
  const { original } = this;
1304
- const index = original.indexOf(string);
1305
- if (index !== -1) {
1618
+ let index = original.indexOf(string);
1619
+ while (index !== -1) {
1620
+ if (this._hasRemovedContent(index, index + string.length)) {
1621
+ index = original.indexOf(string, index + string.length);
1622
+ continue;
1623
+ }
1306
1624
  if (typeof replacement === "function") replacement = replacement(string, index, original);
1307
- if (string !== replacement) if (string.length === 0) this.appendRight(index, replacement);
1308
- else this.overwrite(index, index + string.length, replacement);
1625
+ else replacement = expandReplacement(replacement, string, index, original, [], void 0);
1626
+ if (string !== replacement) {
1627
+ if (string.length === 0) this.appendRight(index, replacement);
1628
+ else this.overwrite(index, index + string.length, replacement);
1629
+ }
1630
+ break;
1309
1631
  }
1310
1632
  return this;
1311
1633
  }
@@ -1322,14 +1644,15 @@ var MagicString = class MagicString {
1322
1644
  const stringLength = string.length;
1323
1645
  if (stringLength === 0) {
1324
1646
  for (let index = 0; index <= original.length; index += 1) {
1325
- const _replacement = typeof replacement === "function" ? replacement("", index, original) : replacement;
1647
+ const _replacement = typeof replacement === "function" ? replacement("", index, original) : expandReplacement(replacement, "", index, original, [], void 0);
1326
1648
  if (_replacement !== "") this.appendRight(index, _replacement);
1327
1649
  }
1328
1650
  return this;
1329
1651
  }
1330
1652
  for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
1653
+ if (this._hasRemovedContent(index, index + stringLength)) continue;
1331
1654
  const previous = original.slice(index, index + stringLength);
1332
- const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : replacement;
1655
+ const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : expandReplacement(replacement, previous, index, original, [], void 0);
1333
1656
  if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
1334
1657
  }
1335
1658
  return this;
@@ -1380,15 +1703,17 @@ var Bundle$1 = class Bundle {
1380
1703
  if (!hasOwnProp.call(source, option)) source[option] = source.content[option];
1381
1704
  });
1382
1705
  if (source.separator === void 0) source.separator = this.separator;
1383
- if (source.filename) if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
1384
- this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
1385
- this.uniqueSources.push({
1386
- filename: source.filename,
1387
- content: source.content.original
1388
- });
1389
- } else {
1390
- const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
1391
- if (source.content.original !== uniqueSource.content) throw new MagicStringError(`duplicate filename "${source.filename}" with different content, use unique filenames`);
1706
+ if (source.filename) {
1707
+ if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
1708
+ this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
1709
+ this.uniqueSources.push({
1710
+ filename: source.filename,
1711
+ content: source.content.original
1712
+ });
1713
+ } else {
1714
+ const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
1715
+ if (source.content.original !== uniqueSource.content) throw new MagicStringError(`duplicate filename "${source.filename}" with different content, use unique filenames`);
1716
+ }
1392
1717
  }
1393
1718
  this.sources.push(source);
1394
1719
  return this;
@@ -1416,7 +1741,103 @@ var Bundle$1 = class Bundle {
1416
1741
  });
1417
1742
  return bundle;
1418
1743
  }
1744
+ /**
1745
+ * Flattens the bundle into a single `MagicString`, so the concatenated result can be
1746
+ * processed further with the full `MagicString` API. The returned string's `original`
1747
+ * is the concatenation of every source's `original`, and all existing edits, inserts,
1748
+ * intros, outros and separators are preserved as inserted content, so its `toString()`
1749
+ * equals the bundle's `toString()` and its sourcemap maps back to that combined original.
1750
+ *
1751
+ * Because a `MagicString` maps to a single source, per-source `filename`s are not carried
1752
+ * over; generate the bundle's map before flattening if you need the multi-source mapping.
1753
+ */
1754
+ toMagicString() {
1755
+ const combined = new MagicString(this.sources.map((source) => source.content.original).join(""));
1756
+ let offset = 0;
1757
+ let pending = this.intro;
1758
+ let first = null;
1759
+ let last = null;
1760
+ const byStart = /* @__PURE__ */ new Map();
1761
+ const byEnd = /* @__PURE__ */ new Map();
1762
+ let hasMovedChunks = false;
1763
+ this.sources.forEach((source, i) => {
1764
+ const magicString = source.content;
1765
+ const separator = i > 0 ? source.separator !== void 0 ? source.separator : this.separator : "";
1766
+ if (magicString.original.length === 0) {
1767
+ pending += separator + magicString.toString();
1768
+ return;
1769
+ }
1770
+ pending += separator + magicString.intro;
1771
+ let sourceFirst = null;
1772
+ let previous = null;
1773
+ let originalChunk = magicString.firstChunk;
1774
+ while (originalChunk) {
1775
+ const chunk = originalChunk.clone();
1776
+ chunk.start += offset;
1777
+ chunk.end += offset;
1778
+ chunk.previous = previous;
1779
+ chunk.next = null;
1780
+ if (previous) previous.next = chunk;
1781
+ byStart.set(chunk.start, chunk);
1782
+ byEnd.set(chunk.end, chunk);
1783
+ sourceFirst ??= chunk;
1784
+ previous = chunk;
1785
+ originalChunk = originalChunk.next;
1786
+ }
1787
+ const sourceLast = previous;
1788
+ sourceFirst.intro = pending + sourceFirst.intro;
1789
+ pending = "";
1790
+ sourceLast.outro += magicString.outro;
1791
+ if (last) {
1792
+ last.next = sourceFirst;
1793
+ sourceFirst.previous = last;
1794
+ } else first = sourceFirst;
1795
+ last = sourceLast;
1796
+ for (let index = 0; index < magicString.original.length; index += 1) if (magicString.sourcemapLocations.has(index)) combined.sourcemapLocations.add(index + offset);
1797
+ Object.keys(magicString.storedNames).forEach((name) => {
1798
+ Object.defineProperty(combined.storedNames, name, {
1799
+ writable: true,
1800
+ value: true,
1801
+ enumerable: true
1802
+ });
1803
+ });
1804
+ if (magicString.hasMovedChunks) hasMovedChunks = true;
1805
+ offset += magicString.original.length;
1806
+ });
1807
+ if (!first) {
1808
+ combined.intro = pending;
1809
+ return combined;
1810
+ }
1811
+ if (pending) last.outro += pending;
1812
+ combined.firstChunk = first;
1813
+ combined.lastChunk = last;
1814
+ combined.lastSearchedChunk = first;
1815
+ combined.byStart = byStart;
1816
+ combined.byEnd = byEnd;
1817
+ combined.hasMovedChunks = hasMovedChunks;
1818
+ return combined;
1819
+ }
1419
1820
  generateDecodedMap(options = {}) {
1821
+ const mappings = new Mappings(options.hires);
1822
+ const { names, x_google_ignoreList } = this._generateMappings(mappings);
1823
+ return {
1824
+ ...this._mapProperties(options, names, x_google_ignoreList),
1825
+ mappings: mappings.raw,
1826
+ rangeMappings: mappings.rawRangeMappings
1827
+ };
1828
+ }
1829
+ generateMap(options = {}) {
1830
+ const encoder = new MappingsEncoder();
1831
+ const mappings = new Mappings(options.hires, encoder);
1832
+ const { names, x_google_ignoreList } = this._generateMappings(mappings);
1833
+ return new SourceMap({
1834
+ ...this._mapProperties(options, names, x_google_ignoreList),
1835
+ mappings: encoder.finish(mappings.rawSegments),
1836
+ rangeMappings: mappings.rawRangeMappings
1837
+ });
1838
+ }
1839
+ /** @internal */
1840
+ _generateMappings(mappings) {
1420
1841
  const names = [];
1421
1842
  let x_google_ignoreList;
1422
1843
  this.sources.forEach((source) => {
@@ -1424,10 +1845,11 @@ var Bundle$1 = class Bundle {
1424
1845
  if (!names.includes(name)) names.push(name);
1425
1846
  });
1426
1847
  });
1427
- const mappings = new Mappings(options.hires);
1428
1848
  if (this.intro) mappings.advance(this.intro);
1429
1849
  this.sources.forEach((source, i) => {
1430
- if (i > 0) mappings.advance(source.separator !== void 0 ? source.separator : this.separator);
1850
+ if (i > 0)
1851
+ /* v8 ignore next -- addSource always normalizes source.separator */
1852
+ mappings.advance(source.separator !== void 0 ? source.separator : this.separator);
1431
1853
  const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
1432
1854
  const magicString = source.content;
1433
1855
  const locate = getLocator(magicString.original);
@@ -1435,9 +1857,10 @@ var Bundle$1 = class Bundle {
1435
1857
  magicString.firstChunk.eachNext((chunk) => {
1436
1858
  const loc = locate(chunk.start);
1437
1859
  if (chunk.intro.length) mappings.advance(chunk.intro);
1438
- if (source.filename) if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
1439
- else mappings.addUneditedChunk(sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations);
1440
- else mappings.advance(chunk.content);
1860
+ if (source.filename) {
1861
+ if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
1862
+ else mappings.addUneditedChunk(sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations);
1863
+ } else mappings.advance(chunk.content);
1441
1864
  if (chunk.outro.length) mappings.advance(chunk.outro);
1442
1865
  });
1443
1866
  if (magicString.outro) mappings.advance(magicString.outro);
@@ -1446,22 +1869,25 @@ var Bundle$1 = class Bundle {
1446
1869
  x_google_ignoreList.push(sourceIndex);
1447
1870
  }
1448
1871
  });
1872
+ return {
1873
+ names,
1874
+ x_google_ignoreList
1875
+ };
1876
+ }
1877
+ /** @internal */
1878
+ _mapProperties(options, names, x_google_ignoreList) {
1449
1879
  return {
1450
1880
  file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
1451
1881
  sources: this.uniqueSources.map((source) => {
1452
1882
  return options.file ? getRelativePath(options.file, source.filename) : source.filename;
1453
1883
  }),
1454
1884
  sourcesContent: this.uniqueSources.map((source) => {
1455
- return options.includeContent ? source.content : null;
1885
+ return (typeof options.includeContent === "function" ? options.includeContent(source) : options.includeContent) ? source.content : null;
1456
1886
  }),
1457
1887
  names,
1458
- mappings: mappings.raw,
1459
1888
  x_google_ignoreList
1460
1889
  };
1461
1890
  }
1462
- generateMap(options) {
1463
- return new SourceMap(this.generateDecodedMap(options));
1464
- }
1465
1891
  getIndentString() {
1466
1892
  const indentStringCounts = {};
1467
1893
  this.sources.forEach((source) => {
@@ -1479,6 +1905,7 @@ var Bundle$1 = class Bundle {
1479
1905
  if (indentStr === "") return this;
1480
1906
  let trailingNewline = !this.intro || this.intro.slice(-1) === "\n";
1481
1907
  this.sources.forEach((source, i) => {
1908
+ /* v8 ignore next -- addSource always normalizes source.separator */
1482
1909
  const separator = source.separator !== void 0 ? source.separator : this.separator;
1483
1910
  const indentStart = trailingNewline || i > 0 && /\r?\n$/.test(separator);
1484
1911
  source.content.indent(indentStr, {
@@ -1498,6 +1925,7 @@ var Bundle$1 = class Bundle {
1498
1925
  }
1499
1926
  toString() {
1500
1927
  const body = this.sources.map((source, i) => {
1928
+ /* v8 ignore next -- addSource always normalizes source.separator */
1501
1929
  const separator = source.separator !== void 0 ? source.separator : this.separator;
1502
1930
  return (i > 0 ? separator : "") + source.content.toString();
1503
1931
  }).join("");
@@ -1506,6 +1934,7 @@ var Bundle$1 = class Bundle {
1506
1934
  isEmpty() {
1507
1935
  if (this.intro.length && this.intro.trim()) return false;
1508
1936
  if (this.sources.some((source, i) => {
1937
+ /* v8 ignore next -- addSource always normalizes source.separator */
1509
1938
  const separator = source.separator !== void 0 ? source.separator : this.separator;
1510
1939
  return i > 0 && separator.trim() !== "" || !source.content.isEmpty();
1511
1940
  })) return false;
@@ -1513,8 +1942,9 @@ var Bundle$1 = class Bundle {
1513
1942
  }
1514
1943
  length() {
1515
1944
  return this.sources.reduce((length, source, i) => {
1945
+ /* v8 ignore next -- addSource always normalizes source.separator */
1516
1946
  const separator = source.separator !== void 0 ? source.separator : this.separator;
1517
- return length + (i > 0 ? separator.length : 0) + source.content.length();
1947
+ return length + (i > 0 ? separator.length : 0) + source.content.toString().length;
1518
1948
  }, this.intro.length);
1519
1949
  }
1520
1950
  trimLines() {
@@ -1597,6 +2027,14 @@ function findLastWhiteSpaceReverse(code, start, end) {
1597
2027
  }
1598
2028
  }
1599
2029
  }
2030
+ // A CRLF pair is one line break and must be removed as one. Removing only the
2031
+ // LF leaves the CR, which is still a line terminator, so ASI fires anyway and
2032
+ // the operand after a `return` or `throw` becomes dead code.
2033
+ function getLineBreakStart(code, lineBreakPos) {
2034
+ return lineBreakPos > 0 && code.charCodeAt(lineBreakPos - 1) === 13 /*"\r"*/
2035
+ ? lineBreakPos - 1
2036
+ : lineBreakPos;
2037
+ }
1600
2038
  // This assumes "code" only contains white-space and comments
1601
2039
  // Returns position of line-comment if applicable
1602
2040
  function findFirstLineBreakOutsideComment(code) {
@@ -1605,7 +2043,7 @@ function findFirstLineBreakOutsideComment(code) {
1605
2043
  while (true) {
1606
2044
  start = code.indexOf('/', start);
1607
2045
  if (start === -1 || start > lineBreakPos)
1608
- return [lineBreakPos, lineBreakPos + 1];
2046
+ return [getLineBreakStart(code, lineBreakPos), lineBreakPos + 1];
1609
2047
  // With our assumption, '/' always starts a comment. Determine comment type:
1610
2048
  charCodeAfterSlash = code.charCodeAt(start + 1);
1611
2049
  if (charCodeAfterSlash === 47 /*"/"*/)
@@ -7985,7 +8423,7 @@ function formatAttributes(attributes, { getObject }) {
7985
8423
  if (!attributes) {
7986
8424
  return null;
7987
8425
  }
7988
- const assertionEntries = Object.entries(attributes).map(([key, value]) => [key, `'${value}'`]);
8426
+ const assertionEntries = Object.entries(attributes).map(([key, value]) => [key, JSON.stringify(value)]);
7989
8427
  if (assertionEntries.length > 0) {
7990
8428
  return getObject(assertionEntries, { lineBreakIndent: null });
7991
8429
  }
@@ -17669,7 +18107,7 @@ class Module {
17669
18107
  }
17670
18108
  return null;
17671
18109
  }
17672
- updateOptions({ meta, moduleSideEffects, syntheticNamedExports }) {
18110
+ updateOptions({ meta, moduleSideEffects, syntheticNamedExports }, { replaceExistingMeta = false } = EMPTY_OBJECT) {
17673
18111
  if (moduleSideEffects != null) {
17674
18112
  this.info.moduleSideEffects = moduleSideEffects;
17675
18113
  }
@@ -17677,6 +18115,11 @@ class Module {
17677
18115
  this.info.syntheticNamedExports = syntheticNamedExports;
17678
18116
  }
17679
18117
  if (meta != null) {
18118
+ if (replaceExistingMeta) {
18119
+ for (const key of Object.keys(this.info.meta)) {
18120
+ delete this.info.meta[key];
18121
+ }
18122
+ }
17680
18123
  Object.assign(this.info.meta, meta);
17681
18124
  }
17682
18125
  }
@@ -21760,8 +22203,14 @@ class ModuleLoader {
21760
22203
  const cachedModule = this.graph.cachedModules.get(id);
21761
22204
  if (cachedModule &&
21762
22205
  !cachedModule.customTransformCache &&
21763
- cachedModule.originalCode === sourceDescription.code &&
21764
- !(await this.pluginDriver.hookFirst('shouldTransformCachedModule', [
22206
+ cachedModule.originalCode === sourceDescription.code) {
22207
+ const originalModuleOptions = {
22208
+ meta: { ...module.info.meta },
22209
+ moduleSideEffects: module.info.moduleSideEffects,
22210
+ syntheticNamedExports: module.info.syntheticNamedExports
22211
+ };
22212
+ module.updateOptions(cachedModule);
22213
+ if (await this.pluginDriver.hookFirst('shouldTransformCachedModule', [
21765
22214
  {
21766
22215
  ast: cachedModule.ast,
21767
22216
  attributes: cachedModule.attributes,
@@ -21772,17 +22221,20 @@ class ModuleLoader {
21772
22221
  resolvedSources: cachedModule.resolvedIds,
21773
22222
  syntheticNamedExports: cachedModule.syntheticNamedExports
21774
22223
  }
21775
- ]))) {
21776
- if (cachedModule.transformFiles) {
21777
- for (const emittedFile of cachedModule.transformFiles)
21778
- this.pluginDriver.emitFile(emittedFile);
22224
+ ])) {
22225
+ module.updateOptions(originalModuleOptions, { replaceExistingMeta: true });
22226
+ }
22227
+ else {
22228
+ if (cachedModule.transformFiles) {
22229
+ for (const emittedFile of cachedModule.transformFiles)
22230
+ this.pluginDriver.emitFile(emittedFile);
22231
+ }
22232
+ await module.setSource(cachedModule);
22233
+ return;
21779
22234
  }
21780
- await module.setSource(cachedModule);
21781
- }
21782
- else {
21783
- module.updateOptions(sourceDescription);
21784
- await module.setSource(await transform(sourceDescription, module, this.pluginDriver, this.options));
21785
22235
  }
22236
+ module.updateOptions(sourceDescription);
22237
+ await module.setSource(await transform(sourceDescription, module, this.pluginDriver, this.options));
21786
22238
  }
21787
22239
  async awaitLoadModulesPromise() {
21788
22240
  let startingPromise;
@@ -22893,7 +23345,7 @@ class PluginDriver {
22893
23345
  /**
22894
23346
  * Run a sync plugin hook and return the result.
22895
23347
  * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
22896
- * @param args Arguments passed to the plugin hook.
23348
+ * @param parameters Arguments passed to the plugin hook.
22897
23349
  * @param plugin The actual plugin
22898
23350
  * @param replaceContext When passed, the plugin context can be overridden.
22899
23351
  */