@rollup/wasm-node 4.63.3 → 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.3
4
- Mon, 14 Sep 2026 12:44:36 GMT - commit 250deca2945f8817350564f7d52bab0f79175d1b
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.3";
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) {
@@ -399,7 +399,7 @@ var SourceMap = class {
399
399
  this.sources = properties.sources;
400
400
  this.sourcesContent = properties.sourcesContent;
401
401
  this.names = properties.names;
402
- this.mappings = encode(properties.mappings);
402
+ this.mappings = typeof properties.mappings === "string" ? properties.mappings : encode(properties.mappings);
403
403
  if (typeof properties.x_google_ignoreList !== "undefined") this.x_google_ignoreList = properties.x_google_ignoreList;
404
404
  if (typeof properties.debugId !== "undefined") this.debugId = properties.debugId;
405
405
  if (typeof properties.rangeMappings !== "undefined") {
@@ -481,6 +481,94 @@ const toString = Object.prototype.toString;
481
481
  function isObject(thing) {
482
482
  return toString.call(thing) === "[object Object]";
483
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
+ };
484
572
  //#endregion
485
573
  //#region src/utils/Mappings.ts
486
574
  const NEWLINE_CHAR$1 = 10;
@@ -488,7 +576,7 @@ function isWordCode(code) {
488
576
  return code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57 || code === 95;
489
577
  }
490
578
  var Mappings = class {
491
- constructor(hires) {
579
+ constructor(hires, encoder = null) {
492
580
  this.hires = hires;
493
581
  this.generatedCodeLine = 0;
494
582
  this.generatedCodeColumn = 0;
@@ -496,10 +584,21 @@ var Mappings = class {
496
584
  this.rawSegments = this.raw[this.generatedCodeLine] = [];
497
585
  this.rawRangeMappings = [];
498
586
  this.rawRangeMappingsIndices = this.rawRangeMappings[this.generatedCodeLine] = [];
499
- this.pending = null;
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 = [];
500
600
  }
501
601
  addEdit(sourceIndex, content, loc, nameIndex) {
502
- /* v8 ignore else -- `pending` is never assigned a truthy value */
503
602
  if (content.length) {
504
603
  const contentLengthMinusOne = content.length - 1;
505
604
  let contentLineEnd = content.indexOf("\n", 0);
@@ -513,10 +612,7 @@ var Mappings = class {
513
612
  ];
514
613
  if (nameIndex >= 0) segment.push(nameIndex);
515
614
  this.rawSegments.push(segment);
516
- this.generatedCodeLine += 1;
517
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
518
- this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
519
- this.generatedCodeColumn = 0;
615
+ this.nextLine();
520
616
  previousContentLineEnd = contentLineEnd;
521
617
  contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
522
618
  }
@@ -529,11 +625,7 @@ var Mappings = class {
529
625
  if (nameIndex >= 0) segment.push(nameIndex);
530
626
  this.rawSegments.push(segment);
531
627
  this.advance(content.slice(previousContentLineEnd + 1));
532
- } else if (this.pending) {
533
- this.rawSegments.push(this.pending);
534
- this.advance(content);
535
628
  }
536
- this.pending = null;
537
629
  }
538
630
  addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
539
631
  const end = chunk.end;
@@ -541,8 +633,13 @@ var Mappings = class {
541
633
  if (this.hires) {
542
634
  const boundary = this.hires === "boundary";
543
635
  const experimentalRange = this.hires === "experimental-range";
636
+ const encoder = experimentalRange ? null : this.encoder;
544
637
  let charInHiresBoundary = false;
545
638
  while (i < end) {
639
+ if (encoder !== null && this.rawSegments.length >= 4096) {
640
+ encoder.segments(this.rawSegments);
641
+ this.rawSegments.length = 0;
642
+ }
546
643
  if (experimentalRange && i + 1 >= end) this.rawSegments.push([
547
644
  this.generatedCodeColumn,
548
645
  sourceIndex,
@@ -553,10 +650,7 @@ var Mappings = class {
553
650
  if (code === NEWLINE_CHAR$1) {
554
651
  loc.line += 1;
555
652
  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;
653
+ this.nextLine();
560
654
  charInHiresBoundary = false;
561
655
  } else {
562
656
  if (boundary) {
@@ -637,26 +731,15 @@ var Mappings = class {
637
731
  if (newline === end) break;
638
732
  loc.line += 1;
639
733
  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;
734
+ this.nextLine();
644
735
  i = newline + 1;
645
736
  }
646
737
  }
647
- this.pending = null;
648
738
  }
649
739
  advance(str) {
650
740
  if (!str) return;
651
741
  const lastNewline = str.lastIndexOf("\n");
652
- if (lastNewline !== -1) {
653
- for (let i = str.indexOf("\n"); i !== -1; i = str.indexOf("\n", i + 1)) {
654
- this.generatedCodeLine++;
655
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
656
- this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
657
- }
658
- this.generatedCodeColumn = 0;
659
- }
742
+ for (let i = str.indexOf("\n"); i !== -1; i = str.indexOf("\n", i + 1)) this.nextLine();
660
743
  this.generatedCodeColumn += str.length - lastNewline - 1;
661
744
  }
662
745
  };
@@ -877,9 +960,32 @@ var MagicString = class MagicString {
877
960
  */
878
961
  generateDecodedMap(options) {
879
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) {
880
987
  const sourceIndex = 0;
881
988
  const names = Object.keys(this.storedNames);
882
- const mappings = new Mappings(options.hires);
883
989
  const locate = getLocator(this.original);
884
990
  if (this.intro) mappings.advance(this.intro);
885
991
  this.firstChunk.eachNext((chunk) => {
@@ -890,22 +996,18 @@ var MagicString = class MagicString {
890
996
  if (chunk.outro.length) mappings.advance(chunk.outro);
891
997
  });
892
998
  if (this.outro) mappings.advance(this.outro);
999
+ return names;
1000
+ }
1001
+ /** @internal */
1002
+ _mapProperties(options, names) {
893
1003
  return {
894
1004
  file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
895
1005
  sources: [options.source ? getRelativePath(options.file || "", options.source) : options.file || ""],
896
1006
  sourcesContent: options.includeContent ? [this.original] : void 0,
897
1007
  names,
898
- mappings: mappings.raw,
899
- x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0,
900
- rangeMappings: mappings.rawRangeMappings
1008
+ x_google_ignoreList: this.ignoreList ? [0] : void 0
901
1009
  };
902
1010
  }
903
- /**
904
- * Generates a version 3 sourcemap.
905
- */
906
- generateMap(options) {
907
- return new SourceMap(this.generateDecodedMap(options));
908
- }
909
1011
  /** @internal */
910
1012
  _ensureindentStr() {
911
1013
  if (this.indentStr === void 0) this.indentStr = guessIndent(this.original);
@@ -1018,8 +1120,14 @@ var MagicString = class MagicString {
1018
1120
  }
1019
1121
  /**
1020
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.
1021
1129
  */
1022
- move(start, end, index) {
1130
+ move(start, end, index, affinity = "right") {
1023
1131
  start = start + this.offset;
1024
1132
  end = end + this.offset;
1025
1133
  index = index + this.offset;
@@ -1039,9 +1147,27 @@ var MagicString = class MagicString {
1039
1147
  }
1040
1148
  const oldLeft = first.previous;
1041
1149
  const oldRight = last.next;
1042
- const newRight = this.byStart.get(index);
1043
- if (!newRight && last === this.lastChunk) return this;
1044
- 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
+ }
1045
1171
  if (oldLeft) oldLeft.next = oldRight;
1046
1172
  if (oldRight) oldRight.previous = oldLeft;
1047
1173
  if (newLeft) newLeft.next = first;
@@ -1166,6 +1292,9 @@ var MagicString = class MagicString {
1166
1292
  }
1167
1293
  /**
1168
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.
1169
1298
  * Removing the same content twice, or making removals that partially overlap, will cause an error.
1170
1299
  */
1171
1300
  remove(start, end) {
@@ -1182,9 +1311,9 @@ var MagicString = class MagicString {
1182
1311
  this._split(end);
1183
1312
  let chunk = this.byStart.get(start);
1184
1313
  while (chunk) {
1185
- chunk.intro = "";
1186
- chunk.outro = "";
1187
- chunk.edit("");
1314
+ if (chunk.start > start) chunk.intro = "";
1315
+ if (chunk.end < end) chunk.outro = "";
1316
+ chunk.edit("", false, true);
1188
1317
  chunk = end > chunk.end ? this.byStart.get(chunk.end) : null;
1189
1318
  }
1190
1319
  return this;
@@ -1264,12 +1393,13 @@ var MagicString = class MagicString {
1264
1393
  let result = "";
1265
1394
  let chunk = this.firstChunk;
1266
1395
  while (chunk && (chunk.start > start || chunk.end <= start)) {
1267
- if (chunk.start < end && chunk.end >= end) return result;
1396
+ if (chunk.start < end && chunk.end >= end || end === 0 && chunk.start === 0) return result;
1268
1397
  chunk = chunk.next;
1269
1398
  }
1270
1399
  if (chunk && chunk.edited && chunk.start !== start) throw new MagicStringError(`cannot use edited character ${start} as slice start anchor`);
1271
1400
  const startChunk = chunk;
1272
1401
  while (chunk) {
1402
+ if (end === 0 && chunk.start === 0) break;
1273
1403
  if (chunk.intro && (startChunk !== chunk || chunk.start === start)) result += chunk.intro;
1274
1404
  const containsEnd = chunk.start < end && chunk.end >= end;
1275
1405
  if (containsEnd && chunk.edited && chunk.end !== end) throw new MagicStringError(`cannot use edited character ${end} as slice end anchor`);
@@ -1382,7 +1512,8 @@ var MagicString = class MagicString {
1382
1512
  if (aborted) return true;
1383
1513
  chunk = chunk.previous;
1384
1514
  } while (chunk);
1385
- return false;
1515
+ this.intro = this.intro.replace(rx, "");
1516
+ return this.intro.length > 0;
1386
1517
  }
1387
1518
  /**
1388
1519
  * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.
@@ -1409,7 +1540,8 @@ var MagicString = class MagicString {
1409
1540
  if (aborted) return true;
1410
1541
  chunk = chunk.next;
1411
1542
  } while (chunk);
1412
- return false;
1543
+ this.outro = this.outro.replace(rx, "");
1544
+ return this.outro.length > 0;
1413
1545
  }
1414
1546
  /**
1415
1547
  * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.
@@ -1436,6 +1568,22 @@ var MagicString = class MagicString {
1436
1568
  }
1437
1569
  return outputIndex !== this.original.length;
1438
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
+ }
1439
1587
  /** @internal */
1440
1588
  _replaceRegexp(searchValue, replacement) {
1441
1589
  function getReplacement(match, str) {
@@ -1444,32 +1592,42 @@ var MagicString = class MagicString {
1444
1592
  }
1445
1593
  const replaceMatch = (match) => {
1446
1594
  /* v8 ignore next 2 -- `match.index` is always defined for matches from `matchAll` */
1447
- if (match.index == null) return;
1595
+ if (match.index == null) return false;
1596
+ if (this._hasRemovedContent(match.index, match.index + match[0].length)) return false;
1448
1597
  const replacement = getReplacement(match, this.original);
1449
- if (replacement === match[0]) return;
1598
+ if (replacement === match[0]) return true;
1450
1599
  if (match[0].length === 0) this.appendRight(match.index, replacement);
1451
1600
  else this.overwrite(match.index, match.index + match[0].length, replacement);
1601
+ return true;
1452
1602
  };
1453
1603
  if (searchValue.global) {
1454
1604
  searchValue.lastIndex = 0;
1455
1605
  for (const match of this.original.matchAll(searchValue)) replaceMatch(match);
1456
1606
  } else {
1457
1607
  const match = this.original.match(searchValue);
1458
- 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
+ }
1459
1612
  }
1460
1613
  return this;
1461
1614
  }
1462
1615
  /** @internal */
1463
1616
  _replaceString(string, replacement) {
1464
1617
  const { original } = this;
1465
- const index = original.indexOf(string);
1466
- 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
+ }
1467
1624
  if (typeof replacement === "function") replacement = replacement(string, index, original);
1468
1625
  else replacement = expandReplacement(replacement, string, index, original, [], void 0);
1469
1626
  if (string !== replacement) {
1470
1627
  if (string.length === 0) this.appendRight(index, replacement);
1471
1628
  else this.overwrite(index, index + string.length, replacement);
1472
1629
  }
1630
+ break;
1473
1631
  }
1474
1632
  return this;
1475
1633
  }
@@ -1492,6 +1650,7 @@ var MagicString = class MagicString {
1492
1650
  return this;
1493
1651
  }
1494
1652
  for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
1653
+ if (this._hasRemovedContent(index, index + stringLength)) continue;
1495
1654
  const previous = original.slice(index, index + stringLength);
1496
1655
  const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : expandReplacement(replacement, previous, index, original, [], void 0);
1497
1656
  if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
@@ -1582,7 +1741,103 @@ var Bundle$1 = class Bundle {
1582
1741
  });
1583
1742
  return bundle;
1584
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
+ }
1585
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) {
1586
1841
  const names = [];
1587
1842
  let x_google_ignoreList;
1588
1843
  this.sources.forEach((source) => {
@@ -1590,7 +1845,6 @@ var Bundle$1 = class Bundle {
1590
1845
  if (!names.includes(name)) names.push(name);
1591
1846
  });
1592
1847
  });
1593
- const mappings = new Mappings(options.hires);
1594
1848
  if (this.intro) mappings.advance(this.intro);
1595
1849
  this.sources.forEach((source, i) => {
1596
1850
  if (i > 0)
@@ -1615,6 +1869,13 @@ var Bundle$1 = class Bundle {
1615
1869
  x_google_ignoreList.push(sourceIndex);
1616
1870
  }
1617
1871
  });
1872
+ return {
1873
+ names,
1874
+ x_google_ignoreList
1875
+ };
1876
+ }
1877
+ /** @internal */
1878
+ _mapProperties(options, names, x_google_ignoreList) {
1618
1879
  return {
1619
1880
  file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
1620
1881
  sources: this.uniqueSources.map((source) => {
@@ -1624,14 +1885,9 @@ var Bundle$1 = class Bundle {
1624
1885
  return (typeof options.includeContent === "function" ? options.includeContent(source) : options.includeContent) ? source.content : null;
1625
1886
  }),
1626
1887
  names,
1627
- mappings: mappings.raw,
1628
- x_google_ignoreList,
1629
- rangeMappings: mappings.rawRangeMappings
1888
+ x_google_ignoreList
1630
1889
  };
1631
1890
  }
1632
- generateMap(options) {
1633
- return new SourceMap(this.generateDecodedMap(options));
1634
- }
1635
1891
  getIndentString() {
1636
1892
  const indentStringCounts = {};
1637
1893
  this.sources.forEach((source) => {
@@ -8167,7 +8423,7 @@ function formatAttributes(attributes, { getObject }) {
8167
8423
  if (!attributes) {
8168
8424
  return null;
8169
8425
  }
8170
- const assertionEntries = Object.entries(attributes).map(([key, value]) => [key, `'${value}'`]);
8426
+ const assertionEntries = Object.entries(attributes).map(([key, value]) => [key, JSON.stringify(value)]);
8171
8427
  if (assertionEntries.length > 0) {
8172
8428
  return getObject(assertionEntries, { lineBreakIndent: null });
8173
8429
  }
@@ -17851,7 +18107,7 @@ class Module {
17851
18107
  }
17852
18108
  return null;
17853
18109
  }
17854
- updateOptions({ meta, moduleSideEffects, syntheticNamedExports }) {
18110
+ updateOptions({ meta, moduleSideEffects, syntheticNamedExports }, { replaceExistingMeta = false } = EMPTY_OBJECT) {
17855
18111
  if (moduleSideEffects != null) {
17856
18112
  this.info.moduleSideEffects = moduleSideEffects;
17857
18113
  }
@@ -17859,6 +18115,11 @@ class Module {
17859
18115
  this.info.syntheticNamedExports = syntheticNamedExports;
17860
18116
  }
17861
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
+ }
17862
18123
  Object.assign(this.info.meta, meta);
17863
18124
  }
17864
18125
  }
@@ -21942,8 +22203,14 @@ class ModuleLoader {
21942
22203
  const cachedModule = this.graph.cachedModules.get(id);
21943
22204
  if (cachedModule &&
21944
22205
  !cachedModule.customTransformCache &&
21945
- cachedModule.originalCode === sourceDescription.code &&
21946
- !(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', [
21947
22214
  {
21948
22215
  ast: cachedModule.ast,
21949
22216
  attributes: cachedModule.attributes,
@@ -21954,17 +22221,20 @@ class ModuleLoader {
21954
22221
  resolvedSources: cachedModule.resolvedIds,
21955
22222
  syntheticNamedExports: cachedModule.syntheticNamedExports
21956
22223
  }
21957
- ]))) {
21958
- if (cachedModule.transformFiles) {
21959
- for (const emittedFile of cachedModule.transformFiles)
21960
- 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;
21961
22234
  }
21962
- await module.setSource(cachedModule);
21963
- }
21964
- else {
21965
- module.updateOptions(sourceDescription);
21966
- await module.setSource(await transform(sourceDescription, module, this.pluginDriver, this.options));
21967
22235
  }
22236
+ module.updateOptions(sourceDescription);
22237
+ await module.setSource(await transform(sourceDescription, module, this.pluginDriver, this.options));
21968
22238
  }
21969
22239
  async awaitLoadModulesPromise() {
21970
22240
  let startingPromise;
@@ -23075,7 +23345,7 @@ class PluginDriver {
23075
23345
  /**
23076
23346
  * Run a sync plugin hook and return the result.
23077
23347
  * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
23078
- * @param args Arguments passed to the plugin hook.
23348
+ * @param parameters Arguments passed to the plugin hook.
23079
23349
  * @param plugin The actual plugin
23080
23350
  * @param replaceContext When passed, the plugin context can be overridden.
23081
23351
  */