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
 
@@ -42,7 +42,7 @@ function _mergeNamespaces(n, m) {
42
42
 
43
43
  const promises__namespace = /*#__PURE__*/_interopNamespaceDefault(promises);
44
44
 
45
- var version = "4.63.2";
45
+ var version = "4.63.4";
46
46
  const package_ = {
47
47
  version: version};
48
48
 
@@ -3805,7 +3805,7 @@ class PluginDriver {
3805
3805
  /**
3806
3806
  * Run a sync plugin hook and return the result.
3807
3807
  * @param hookName Name of the plugin hook. Must be in `PluginHooks`.
3808
- * @param args Arguments passed to the plugin hook.
3808
+ * @param parameters Arguments passed to the plugin hook.
3809
3809
  * @param plugin The actual plugin
3810
3810
  * @param replaceContext When passed, the plugin context can be overridden.
3811
3811
  */
@@ -4225,11 +4225,11 @@ function handleError(error, recover = false) {
4225
4225
  var comma = ",".charCodeAt(0);
4226
4226
  var semicolon = ";".charCodeAt(0);
4227
4227
  var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
4228
- var intToChar = new Uint8Array(64);
4228
+ var intToChar$1 = new Uint8Array(64);
4229
4229
  var charToInt = new Uint8Array(128);
4230
4230
  for (let i = 0; i < chars.length; i++) {
4231
4231
  const c = chars.charCodeAt(i);
4232
- intToChar[i] = c;
4232
+ intToChar$1[i] = c;
4233
4233
  charToInt[c] = i;
4234
4234
  }
4235
4235
  function decodeInteger(reader) {
@@ -4252,7 +4252,7 @@ function encodeInteger(builder, num) {
4252
4252
  let clamped = num & 31;
4253
4253
  num >>>= 5;
4254
4254
  if (num > 0) clamped |= 32;
4255
- builder.write(intToChar[clamped]);
4255
+ builder.write(intToChar$1[clamped]);
4256
4256
  } while (num > 0);
4257
4257
  }
4258
4258
  function encodeSign(num) {
@@ -4315,6 +4315,21 @@ var StringReader = class {
4315
4315
  return idx === -1 ? buffer.length : idx;
4316
4316
  }
4317
4317
  };
4318
+ function encodeRangeMappings(decoded) {
4319
+ if (decoded.length === 0) return "";
4320
+ const writer = new StringWriter();
4321
+ for (let i = 0; i < decoded.length; i++) {
4322
+ const indices = decoded[i];
4323
+ if (i > 0) writer.write(semicolon);
4324
+ let index = 0;
4325
+ for (let j = 0; j < indices.length; j++) {
4326
+ const offset = indices[j];
4327
+ encodeInteger(writer, offset - index);
4328
+ index = offset;
4329
+ }
4330
+ }
4331
+ return writer.flush();
4332
+ }
4318
4333
 
4319
4334
  // src/sourcemap-codec.ts
4320
4335
  function decode(mappings) {
@@ -4509,8 +4524,10 @@ var Chunk$1 = class Chunk {
4509
4524
  if (this.outro.length) return true;
4510
4525
  const trimmed = this.content.replace(rx, "");
4511
4526
  if (trimmed.length) {
4512
- if (trimmed !== this.content) if (this.edited) this.edit(trimmed, this.storeName, true);
4513
- else this.split(this.start + trimmed.length).edit("", void 0, true);
4527
+ if (trimmed !== this.content) {
4528
+ if (this.edited) this.edit(trimmed, this.storeName, true);
4529
+ else this.split(this.start + trimmed.length).edit("", void 0, true);
4530
+ }
4514
4531
  return true;
4515
4532
  } else {
4516
4533
  this.edit("", void 0, true);
@@ -4523,10 +4540,12 @@ var Chunk$1 = class Chunk {
4523
4540
  if (this.intro.length) return true;
4524
4541
  const trimmed = this.content.replace(rx, "");
4525
4542
  if (trimmed.length) {
4526
- if (trimmed !== this.content) if (this.edited) this.edit(trimmed, this.storeName, true);
4527
- else {
4528
- this.split(this.end - trimmed.length);
4529
- this.edit("", void 0, true);
4543
+ if (trimmed !== this.content) {
4544
+ if (this.edited) this.edit(trimmed, this.storeName, true);
4545
+ else {
4546
+ this.split(this.end - trimmed.length);
4547
+ this.edit("", void 0, true);
4548
+ }
4530
4549
  }
4531
4550
  return true;
4532
4551
  } else {
@@ -4553,12 +4572,14 @@ var MagicStringError = class extends Error {
4553
4572
  //#endregion
4554
4573
  //#region src/SourceMap.ts
4555
4574
  function getBtoa() {
4575
+ /* v8 ignore next -- environment fallback, unreachable when `btoa` is present */
4556
4576
  if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
4557
4577
  const buffer = globalThis["Buffer"];
4558
4578
  if (buffer) return (str) => buffer.from(str, "utf-8").toString("base64");
4559
4579
  return () => {
4560
4580
  throw new MagicStringError("unsupported environment: `btoa` or `Buffer` is required");
4561
4581
  };
4582
+ /* v8 ignore stop */
4562
4583
  }
4563
4584
  const btoa = /* #__PURE__ */ getBtoa();
4564
4585
  var SourceMap = class {
@@ -4568,9 +4589,17 @@ var SourceMap = class {
4568
4589
  this.sources = properties.sources;
4569
4590
  this.sourcesContent = properties.sourcesContent;
4570
4591
  this.names = properties.names;
4571
- this.mappings = encode(properties.mappings);
4592
+ this.mappings = typeof properties.mappings === "string" ? properties.mappings : encode(properties.mappings);
4572
4593
  if (typeof properties.x_google_ignoreList !== "undefined") this.x_google_ignoreList = properties.x_google_ignoreList;
4573
4594
  if (typeof properties.debugId !== "undefined") this.debugId = properties.debugId;
4595
+ if (typeof properties.rangeMappings !== "undefined") {
4596
+ let shouldOutputRangeMapping = false;
4597
+ for (const line of properties.rangeMappings) if (line.length !== 0) {
4598
+ shouldOutputRangeMapping = true;
4599
+ break;
4600
+ }
4601
+ if (shouldOutputRangeMapping) this.rangeMappings = encodeRangeMappings(properties.rangeMappings);
4602
+ }
4574
4603
  }
4575
4604
  /**
4576
4605
  * Returns the equivalent of `JSON.stringify(map)`
@@ -4589,12 +4618,8 @@ var SourceMap = class {
4589
4618
  //#endregion
4590
4619
  //#region src/utils/getLocator.ts
4591
4620
  function getLocator(source) {
4592
- const originalLines = source.split("\n");
4593
- const lineOffsets = [];
4594
- for (let i = 0, pos = 0; i < originalLines.length; i++) {
4595
- lineOffsets.push(pos);
4596
- pos += originalLines[i].length + 1;
4597
- }
4621
+ const lineOffsets = [0];
4622
+ for (let i = source.indexOf("\n"); i !== -1; i = source.indexOf("\n", i + 1)) lineOffsets.push(i + 1);
4598
4623
  return function locate(index) {
4599
4624
  let i = 0;
4600
4625
  let j = lineOffsets.length;
@@ -4646,17 +4671,122 @@ const toString = Object.prototype.toString;
4646
4671
  function isObject(thing) {
4647
4672
  return toString.call(thing) === "[object Object]";
4648
4673
  }
4674
+ const BASE64_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
4675
+ const intToChar = /* #__PURE__ */ (() => {
4676
+ const chars = /* @__PURE__ */ new Uint8Array(64);
4677
+ for (let i = 0; i < 64; i++) chars[i] = BASE64_CHARS.charCodeAt(i);
4678
+ return chars;
4679
+ })();
4680
+ const COMMA = 44;
4681
+ const SEMICOLON = 59;
4682
+ const BUFFER_SIZE = 16384;
4683
+ const FLUSH_THRESHOLD = 16348;
4684
+ const scratch = /* #__PURE__ */ new Uint8Array(BUFFER_SIZE);
4685
+ function writeVlq(pos, num) {
4686
+ num = num < 0 ? -num << 1 | 1 : num << 1;
4687
+ do {
4688
+ let clamped = num & 31;
4689
+ num >>>= 5;
4690
+ if (num > 0) clamped |= 32;
4691
+ scratch[pos++] = intToChar[clamped];
4692
+ } while (num > 0);
4693
+ return pos;
4694
+ }
4695
+ const decoder = /* #__PURE__ */ new TextDecoder();
4696
+ var MappingsEncoder = class {
4697
+ constructor() {
4698
+ this.out = "";
4699
+ this.pos = 0;
4700
+ this.lines = [];
4701
+ this.buffered = 0;
4702
+ this.needsComma = false;
4703
+ this.prevGenColumn = 0;
4704
+ this.prevSourceIndex = 0;
4705
+ this.prevSourceLine = 0;
4706
+ this.prevSourceColumn = 0;
4707
+ this.prevNameIndex = 0;
4708
+ }
4709
+ endLine(segments) {
4710
+ this.lines.push(segments);
4711
+ this.buffered += segments.length + 1;
4712
+ if (this.buffered >= 4096) this.drain(null);
4713
+ }
4714
+ segments(segments) {
4715
+ this.drain(segments);
4716
+ }
4717
+ finish(segments) {
4718
+ this.drain(segments);
4719
+ this.flush();
4720
+ return this.out;
4721
+ }
4722
+ drain(trailing) {
4723
+ const lines = this.lines;
4724
+ const lineCount = lines.length;
4725
+ for (let l = 0; l <= lineCount; l++) {
4726
+ const line = l < lineCount ? lines[l] : trailing;
4727
+ if (line === null) break;
4728
+ for (let i = 0; i < line.length; i++) {
4729
+ if (this.pos > FLUSH_THRESHOLD) this.flush();
4730
+ const segment = line[i];
4731
+ if (this.needsComma) scratch[this.pos++] = COMMA;
4732
+ this.needsComma = true;
4733
+ this.pos = writeVlq(this.pos, segment[0] - this.prevGenColumn);
4734
+ this.prevGenColumn = segment[0];
4735
+ this.pos = writeVlq(this.pos, segment[1] - this.prevSourceIndex);
4736
+ this.prevSourceIndex = segment[1];
4737
+ this.pos = writeVlq(this.pos, segment[2] - this.prevSourceLine);
4738
+ this.prevSourceLine = segment[2];
4739
+ this.pos = writeVlq(this.pos, segment[3] - this.prevSourceColumn);
4740
+ this.prevSourceColumn = segment[3];
4741
+ if (segment.length === 5) {
4742
+ this.pos = writeVlq(this.pos, segment[4] - this.prevNameIndex);
4743
+ this.prevNameIndex = segment[4];
4744
+ }
4745
+ }
4746
+ if (l < lineCount) {
4747
+ if (this.pos > FLUSH_THRESHOLD) this.flush();
4748
+ scratch[this.pos++] = SEMICOLON;
4749
+ this.needsComma = false;
4750
+ this.prevGenColumn = 0;
4751
+ }
4752
+ }
4753
+ lines.length = 0;
4754
+ this.buffered = 0;
4755
+ this.flush();
4756
+ }
4757
+ flush() {
4758
+ this.out += decoder.decode(scratch.subarray(0, this.pos));
4759
+ this.pos = 0;
4760
+ }
4761
+ };
4649
4762
  //#endregion
4650
4763
  //#region src/utils/Mappings.ts
4651
- const wordRegex = /\w/;
4764
+ const NEWLINE_CHAR$1 = 10;
4765
+ function isWordCode(code) {
4766
+ return code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57 || code === 95;
4767
+ }
4652
4768
  var Mappings = class {
4653
- constructor(hires) {
4769
+ constructor(hires, encoder = null) {
4654
4770
  this.hires = hires;
4655
4771
  this.generatedCodeLine = 0;
4656
4772
  this.generatedCodeColumn = 0;
4657
4773
  this.raw = [];
4658
4774
  this.rawSegments = this.raw[this.generatedCodeLine] = [];
4659
- this.pending = null;
4775
+ this.rawRangeMappings = [];
4776
+ this.rawRangeMappingsIndices = this.rawRangeMappings[this.generatedCodeLine] = [];
4777
+ this.encoder = encoder;
4778
+ }
4779
+ nextLine() {
4780
+ if (this.encoder === null) {
4781
+ this.generatedCodeLine += 1;
4782
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
4783
+ } else {
4784
+ this.encoder.endLine(this.rawSegments);
4785
+ this.rawSegments = [];
4786
+ this.generatedCodeLine += 1;
4787
+ }
4788
+ this.generatedCodeColumn = 0;
4789
+ this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
4660
4790
  }
4661
4791
  addEdit(sourceIndex, content, loc, nameIndex) {
4662
4792
  if (content.length) {
@@ -4672,9 +4802,7 @@ var Mappings = class {
4672
4802
  ];
4673
4803
  if (nameIndex >= 0) segment.push(nameIndex);
4674
4804
  this.rawSegments.push(segment);
4675
- this.generatedCodeLine += 1;
4676
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
4677
- this.generatedCodeColumn = 0;
4805
+ this.nextLine();
4678
4806
  previousContentLineEnd = contentLineEnd;
4679
4807
  contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
4680
4808
  }
@@ -4687,63 +4815,122 @@ var Mappings = class {
4687
4815
  if (nameIndex >= 0) segment.push(nameIndex);
4688
4816
  this.rawSegments.push(segment);
4689
4817
  this.advance(content.slice(previousContentLineEnd + 1));
4690
- } else if (this.pending) {
4691
- this.rawSegments.push(this.pending);
4692
- this.advance(content);
4693
4818
  }
4694
- this.pending = null;
4695
4819
  }
4696
4820
  addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
4697
- let originalCharIndex = chunk.start;
4698
- let first = true;
4699
- let charInHiresBoundary = false;
4700
- while (originalCharIndex < chunk.end) {
4701
- if (original[originalCharIndex] === "\n") {
4702
- loc.line += 1;
4703
- loc.column = 0;
4704
- this.generatedCodeLine += 1;
4705
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
4706
- this.generatedCodeColumn = 0;
4707
- first = true;
4708
- charInHiresBoundary = false;
4709
- } else {
4710
- if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
4711
- const segment = [
4821
+ const end = chunk.end;
4822
+ let i = chunk.start;
4823
+ if (this.hires) {
4824
+ const boundary = this.hires === "boundary";
4825
+ const experimentalRange = this.hires === "experimental-range";
4826
+ const encoder = experimentalRange ? null : this.encoder;
4827
+ let charInHiresBoundary = false;
4828
+ while (i < end) {
4829
+ if (encoder !== null && this.rawSegments.length >= 4096) {
4830
+ encoder.segments(this.rawSegments);
4831
+ this.rawSegments.length = 0;
4832
+ }
4833
+ if (experimentalRange && i + 1 >= end) this.rawSegments.push([
4834
+ this.generatedCodeColumn,
4835
+ sourceIndex,
4836
+ loc.line,
4837
+ loc.column
4838
+ ]);
4839
+ const code = original.charCodeAt(i);
4840
+ if (code === NEWLINE_CHAR$1) {
4841
+ loc.line += 1;
4842
+ loc.column = 0;
4843
+ this.nextLine();
4844
+ charInHiresBoundary = false;
4845
+ } else {
4846
+ if (boundary) {
4847
+ if (isWordCode(code)) {
4848
+ if (!charInHiresBoundary) {
4849
+ this.rawSegments.push([
4850
+ this.generatedCodeColumn,
4851
+ sourceIndex,
4852
+ loc.line,
4853
+ loc.column
4854
+ ]);
4855
+ charInHiresBoundary = true;
4856
+ }
4857
+ } else {
4858
+ this.rawSegments.push([
4859
+ this.generatedCodeColumn,
4860
+ sourceIndex,
4861
+ loc.line,
4862
+ loc.column
4863
+ ]);
4864
+ charInHiresBoundary = false;
4865
+ }
4866
+ } else if (experimentalRange) {
4867
+ if (i === chunk.start) {
4868
+ this.rawRangeMappingsIndices.push(this.rawSegments.length);
4869
+ this.rawSegments.push([
4870
+ this.generatedCodeColumn,
4871
+ sourceIndex,
4872
+ loc.line,
4873
+ loc.column
4874
+ ]);
4875
+ }
4876
+ } else this.rawSegments.push([
4877
+ this.generatedCodeColumn,
4878
+ sourceIndex,
4879
+ loc.line,
4880
+ loc.column
4881
+ ]);
4882
+ loc.column += 1;
4883
+ this.generatedCodeColumn += 1;
4884
+ }
4885
+ i += 1;
4886
+ }
4887
+ } else {
4888
+ const bits = sourcemapLocations.bits;
4889
+ while (i < end) {
4890
+ let newline = original.indexOf("\n", i);
4891
+ if (newline === -1 || newline > end) newline = end;
4892
+ if (newline > i) {
4893
+ this.rawSegments.push([
4712
4894
  this.generatedCodeColumn,
4713
4895
  sourceIndex,
4714
4896
  loc.line,
4715
4897
  loc.column
4716
- ];
4717
- if (this.hires === "boundary") if (wordRegex.test(original[originalCharIndex])) {
4718
- if (!charInHiresBoundary) {
4719
- this.rawSegments.push(segment);
4720
- charInHiresBoundary = true;
4898
+ ]);
4899
+ for (let w = i + 1 >> 5, last = newline - 1 >> 5; w <= last; w++) {
4900
+ let word = bits[w];
4901
+ if (!word) continue;
4902
+ const base = w << 5;
4903
+ while (word) {
4904
+ const lowest = word & -word;
4905
+ const index = base + 31 - Math.clz32(lowest);
4906
+ if (index > i && index < newline) {
4907
+ const offset = index - i;
4908
+ this.rawSegments.push([
4909
+ this.generatedCodeColumn + offset,
4910
+ sourceIndex,
4911
+ loc.line,
4912
+ loc.column + offset
4913
+ ]);
4914
+ }
4915
+ word ^= lowest;
4721
4916
  }
4722
- } else {
4723
- this.rawSegments.push(segment);
4724
- charInHiresBoundary = false;
4725
4917
  }
4726
- else this.rawSegments.push(segment);
4918
+ loc.column += newline - i;
4919
+ this.generatedCodeColumn += newline - i;
4727
4920
  }
4728
- loc.column += 1;
4729
- this.generatedCodeColumn += 1;
4730
- first = false;
4921
+ if (newline === end) break;
4922
+ loc.line += 1;
4923
+ loc.column = 0;
4924
+ this.nextLine();
4925
+ i = newline + 1;
4731
4926
  }
4732
- originalCharIndex += 1;
4733
4927
  }
4734
- this.pending = null;
4735
4928
  }
4736
4929
  advance(str) {
4737
4930
  if (!str) return;
4738
- const lines = str.split("\n");
4739
- if (lines.length > 1) {
4740
- for (let i = 0; i < lines.length - 1; i++) {
4741
- this.generatedCodeLine++;
4742
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
4743
- }
4744
- this.generatedCodeColumn = 0;
4745
- }
4746
- this.generatedCodeColumn += lines[lines.length - 1].length;
4931
+ const lastNewline = str.lastIndexOf("\n");
4932
+ for (let i = str.indexOf("\n"); i !== -1; i = str.indexOf("\n", i + 1)) this.nextLine();
4933
+ this.generatedCodeColumn += str.length - lastNewline - 1;
4747
4934
  }
4748
4935
  };
4749
4936
  //#endregion
@@ -4756,6 +4943,63 @@ const warned = {
4756
4943
  insertRight: false,
4757
4944
  storeName: false
4758
4945
  };
4946
+ /**
4947
+ * Expands the `$` substitution patterns that `String.prototype.replace` accepts
4948
+ * in a string replacement.
4949
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
4950
+ *
4951
+ * `captures` holds the capture groups in order, so `captures[0]` is `$1`.
4952
+ * `namedCaptures` is `undefined` when the pattern has no named groups, and
4953
+ * `$<name>` is then literal text - which is also the case for a string search
4954
+ * value, where there are no groups of either kind.
4955
+ */
4956
+ function expandReplacement(replacement, matched, position, str, captures, namedCaptures) {
4957
+ if (!replacement.includes("$")) return replacement;
4958
+ let result = "";
4959
+ let index = 0;
4960
+ while (index < replacement.length) {
4961
+ const dollar = replacement.indexOf("$", index);
4962
+ if (dollar === -1) {
4963
+ result += replacement.slice(index);
4964
+ break;
4965
+ }
4966
+ result += replacement.slice(index, dollar);
4967
+ const char = replacement[dollar + 1];
4968
+ let expansion = "$";
4969
+ let consumed = 1;
4970
+ if (char === "$") consumed = 2;
4971
+ else if (char === "&") {
4972
+ expansion = matched;
4973
+ consumed = 2;
4974
+ } else if (char === "`") {
4975
+ expansion = str.slice(0, position);
4976
+ consumed = 2;
4977
+ } else if (char === "'") {
4978
+ expansion = str.slice(position + matched.length);
4979
+ consumed = 2;
4980
+ } else if (char === "<" && namedCaptures !== void 0) {
4981
+ const close = replacement.indexOf(">", dollar + 2);
4982
+ if (close !== -1) {
4983
+ expansion = namedCaptures[replacement.slice(dollar + 2, close)] ?? "";
4984
+ consumed = close + 1 - dollar;
4985
+ }
4986
+ } else if (char >= "0" && char <= "9") {
4987
+ const second = replacement[dollar + 2];
4988
+ const double = second >= "0" && second <= "9" ? Number(char + second) : NaN;
4989
+ const single = Number(char);
4990
+ if (double >= 1 && double <= captures.length) {
4991
+ expansion = captures[double - 1] ?? "";
4992
+ consumed = 3;
4993
+ } else if (single >= 1 && single <= captures.length) {
4994
+ expansion = captures[single - 1] ?? "";
4995
+ consumed = 2;
4996
+ }
4997
+ }
4998
+ result += expansion;
4999
+ index = dollar + consumed;
5000
+ }
5001
+ return result;
5002
+ }
4759
5003
  var MagicString = class MagicString {
4760
5004
  constructor(string, options = {}) {
4761
5005
  const chunk = new Chunk$1(0, string.length, string);
@@ -4906,9 +5150,32 @@ var MagicString = class MagicString {
4906
5150
  */
4907
5151
  generateDecodedMap(options) {
4908
5152
  options = options || {};
5153
+ const mappings = new Mappings(options.hires);
5154
+ const names = this._generateMappings(mappings);
5155
+ return {
5156
+ ...this._mapProperties(options, names),
5157
+ mappings: mappings.raw,
5158
+ rangeMappings: mappings.rawRangeMappings
5159
+ };
5160
+ }
5161
+ /**
5162
+ * Generates a version 3 sourcemap.
5163
+ */
5164
+ generateMap(options) {
5165
+ options = options || {};
5166
+ const encoder = new MappingsEncoder();
5167
+ const mappings = new Mappings(options.hires, encoder);
5168
+ const names = this._generateMappings(mappings);
5169
+ return new SourceMap({
5170
+ ...this._mapProperties(options, names),
5171
+ mappings: encoder.finish(mappings.rawSegments),
5172
+ rangeMappings: mappings.rawRangeMappings
5173
+ });
5174
+ }
5175
+ /** @internal */
5176
+ _generateMappings(mappings) {
4909
5177
  const sourceIndex = 0;
4910
5178
  const names = Object.keys(this.storedNames);
4911
- const mappings = new Mappings(options.hires);
4912
5179
  const locate = getLocator(this.original);
4913
5180
  if (this.intro) mappings.advance(this.intro);
4914
5181
  this.firstChunk.eachNext((chunk) => {
@@ -4919,21 +5186,18 @@ var MagicString = class MagicString {
4919
5186
  if (chunk.outro.length) mappings.advance(chunk.outro);
4920
5187
  });
4921
5188
  if (this.outro) mappings.advance(this.outro);
5189
+ return names;
5190
+ }
5191
+ /** @internal */
5192
+ _mapProperties(options, names) {
4922
5193
  return {
4923
5194
  file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
4924
5195
  sources: [options.source ? getRelativePath(options.file || "", options.source) : options.file || ""],
4925
5196
  sourcesContent: options.includeContent ? [this.original] : void 0,
4926
5197
  names,
4927
- mappings: mappings.raw,
4928
- x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
5198
+ x_google_ignoreList: this.ignoreList ? [0] : void 0
4929
5199
  };
4930
5200
  }
4931
- /**
4932
- * Generates a version 3 sourcemap.
4933
- */
4934
- generateMap(options) {
4935
- return new SourceMap(this.generateDecodedMap(options));
4936
- }
4937
5201
  /** @internal */
4938
5202
  _ensureindentStr() {
4939
5203
  if (this.indentStr === void 0) this.indentStr = guessIndent(this.original);
@@ -4965,17 +5229,18 @@ var MagicString = class MagicString {
4965
5229
  for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded[i] = true;
4966
5230
  });
4967
5231
  let shouldIndentNextCharacter = options.indentStart !== false;
4968
- const replacer = (match) => {
4969
- if (shouldIndentNextCharacter) return `${resolvedIndentStr}${match}`;
4970
- shouldIndentNextCharacter = true;
4971
- return match;
5232
+ const indentPiece = (str) => {
5233
+ if (str === "") return str;
5234
+ const indented = str.replace(pattern, (match, offset) => offset > 0 || shouldIndentNextCharacter ? `${resolvedIndentStr}${match}` : match);
5235
+ shouldIndentNextCharacter = str[str.length - 1] === "\n";
5236
+ return indented;
4972
5237
  };
4973
- this.intro = this.intro.replace(pattern, replacer);
5238
+ this.intro = indentPiece(this.intro);
4974
5239
  let charIndex = 0;
4975
5240
  let chunk = this.firstChunk;
4976
5241
  const indentAt = (index) => {
4977
5242
  shouldIndentNextCharacter = false;
4978
- if (index === chunk.start) chunk.prependRight(resolvedIndentStr);
5243
+ if (index === chunk.start) chunk.appendRight(resolvedIndentStr);
4979
5244
  else {
4980
5245
  this._splitChunk(chunk, index);
4981
5246
  chunk = chunk.next;
@@ -4984,11 +5249,9 @@ var MagicString = class MagicString {
4984
5249
  };
4985
5250
  while (chunk) {
4986
5251
  const end = chunk.end;
5252
+ if (!isExcluded[chunk.start]) chunk.intro = indentPiece(chunk.intro);
4987
5253
  if (chunk.edited) {
4988
- if (!isExcluded[charIndex]) {
4989
- chunk.content = chunk.content.replace(pattern, replacer);
4990
- if (chunk.content.length) shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
4991
- }
5254
+ if (!isExcluded[charIndex]) chunk.content = indentPiece(chunk.content);
4992
5255
  } else if (options.exclude) {
4993
5256
  charIndex = chunk.start;
4994
5257
  while (charIndex < end) {
@@ -5018,10 +5281,11 @@ var MagicString = class MagicString {
5018
5281
  charIndex += 1;
5019
5282
  }
5020
5283
  }
5284
+ if (!isExcluded[chunk.end - 1]) chunk.outro = indentPiece(chunk.outro);
5021
5285
  charIndex = chunk.end;
5022
5286
  chunk = chunk.next;
5023
5287
  }
5024
- this.outro = this.outro.replace(pattern, replacer);
5288
+ this.outro = indentPiece(this.outro);
5025
5289
  return this;
5026
5290
  }
5027
5291
  /** @internal */
@@ -5046,8 +5310,14 @@ var MagicString = class MagicString {
5046
5310
  }
5047
5311
  /**
5048
5312
  * Moves the characters from `start` and `end` to `index`.
5313
+ *
5314
+ * `affinity` controls where the range is anchored at `index`. With the
5315
+ * default `'right'`, it is inserted before the content that starts at `index`;
5316
+ * with `'left'`, it is inserted after the content that ends at `index`. The
5317
+ * two differ only when other content has already been moved to that boundary,
5318
+ * mirroring the `appendLeft`/`appendRight` distinction.
5049
5319
  */
5050
- move(start, end, index) {
5320
+ move(start, end, index, affinity = "right") {
5051
5321
  start = start + this.offset;
5052
5322
  end = end + this.offset;
5053
5323
  index = index + this.offset;
@@ -5067,9 +5337,27 @@ var MagicString = class MagicString {
5067
5337
  }
5068
5338
  const oldLeft = first.previous;
5069
5339
  const oldRight = last.next;
5070
- const newRight = this.byStart.get(index);
5071
- if (!newRight && last === this.lastChunk) return this;
5072
- const newLeft = newRight ? newRight.previous : this.lastChunk;
5340
+ let newLeft;
5341
+ let newRight;
5342
+ if (affinity === "left") {
5343
+ newLeft = this.byEnd.get(index) ?? null;
5344
+ if (!newLeft) {
5345
+ if (first === this.firstChunk) return this;
5346
+ newRight = this.firstChunk;
5347
+ } else {
5348
+ if (newLeft.next === first) return this;
5349
+ newRight = newLeft.next;
5350
+ }
5351
+ } else {
5352
+ newRight = this.byStart.get(index) ?? null;
5353
+ if (!newRight) {
5354
+ if (last === this.lastChunk) return this;
5355
+ newLeft = this.lastChunk;
5356
+ } else {
5357
+ if (newRight.previous === last) return this;
5358
+ newLeft = newRight.previous;
5359
+ }
5360
+ }
5073
5361
  if (oldLeft) oldLeft.next = oldRight;
5074
5362
  if (oldRight) oldRight.previous = oldLeft;
5075
5363
  if (newLeft) newLeft.next = first;
@@ -5144,6 +5432,7 @@ var MagicString = class MagicString {
5144
5432
  }
5145
5433
  const first = this.byStart.get(start);
5146
5434
  const last = this.byEnd.get(end);
5435
+ /* v8 ignore else -- unreachable: a valid start/end always yields a `first` chunk */
5147
5436
  if (first) {
5148
5437
  let chunk = first;
5149
5438
  while (chunk !== last) {
@@ -5193,6 +5482,9 @@ var MagicString = class MagicString {
5193
5482
  }
5194
5483
  /**
5195
5484
  * Removes the characters from `start` to `end` (of the original string, **not** the generated string).
5485
+ * Content appended or prepended at positions strictly inside the range is removed with it, while
5486
+ * content attached at `start` or `end` is preserved — use `s.overwrite(start, end, '')` to remove
5487
+ * the range including its edge inserts.
5196
5488
  * Removing the same content twice, or making removals that partially overlap, will cause an error.
5197
5489
  */
5198
5490
  remove(start, end) {
@@ -5209,9 +5501,9 @@ var MagicString = class MagicString {
5209
5501
  this._split(end);
5210
5502
  let chunk = this.byStart.get(start);
5211
5503
  while (chunk) {
5212
- chunk.intro = "";
5213
- chunk.outro = "";
5214
- chunk.edit("");
5504
+ if (chunk.start > start) chunk.intro = "";
5505
+ if (chunk.end < end) chunk.outro = "";
5506
+ chunk.edit("", false, true);
5215
5507
  chunk = end > chunk.end ? this.byStart.get(chunk.end) : null;
5216
5508
  }
5217
5509
  return this;
@@ -5291,12 +5583,13 @@ var MagicString = class MagicString {
5291
5583
  let result = "";
5292
5584
  let chunk = this.firstChunk;
5293
5585
  while (chunk && (chunk.start > start || chunk.end <= start)) {
5294
- if (chunk.start < end && chunk.end >= end) return result;
5586
+ if (chunk.start < end && chunk.end >= end || end === 0 && chunk.start === 0) return result;
5295
5587
  chunk = chunk.next;
5296
5588
  }
5297
5589
  if (chunk && chunk.edited && chunk.start !== start) throw new MagicStringError(`cannot use edited character ${start} as slice start anchor`);
5298
5590
  const startChunk = chunk;
5299
5591
  while (chunk) {
5592
+ if (end === 0 && chunk.start === 0) break;
5300
5593
  if (chunk.intro && (startChunk !== chunk || chunk.start === start)) result += chunk.intro;
5301
5594
  const containsEnd = chunk.start < end && chunk.end >= end;
5302
5595
  if (containsEnd && chunk.edited && chunk.end !== end) throw new MagicStringError(`cannot use edited character ${end} as slice end anchor`);
@@ -5361,11 +5654,13 @@ var MagicString = class MagicString {
5361
5654
  * Returns true if the resulting source is empty (disregarding white space).
5362
5655
  */
5363
5656
  isEmpty() {
5657
+ if (this.intro.length && this.intro.trim()) return false;
5364
5658
  let chunk = this.firstChunk;
5365
5659
  while (chunk) {
5366
5660
  if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim()) return false;
5367
5661
  chunk = chunk.next;
5368
5662
  }
5663
+ if (this.outro.length && this.outro.trim()) return false;
5369
5664
  return true;
5370
5665
  }
5371
5666
  length() {
@@ -5407,7 +5702,8 @@ var MagicString = class MagicString {
5407
5702
  if (aborted) return true;
5408
5703
  chunk = chunk.previous;
5409
5704
  } while (chunk);
5410
- return false;
5705
+ this.intro = this.intro.replace(rx, "");
5706
+ return this.intro.length > 0;
5411
5707
  }
5412
5708
  /**
5413
5709
  * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.
@@ -5434,7 +5730,8 @@ var MagicString = class MagicString {
5434
5730
  if (aborted) return true;
5435
5731
  chunk = chunk.next;
5436
5732
  } while (chunk);
5437
- return false;
5733
+ this.outro = this.outro.replace(rx, "");
5734
+ return this.outro.length > 0;
5438
5735
  }
5439
5736
  /**
5440
5737
  * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.
@@ -5461,41 +5758,66 @@ var MagicString = class MagicString {
5461
5758
  }
5462
5759
  return outputIndex !== this.original.length;
5463
5760
  }
5761
+ /**
5762
+ * Whether the original range [start, end) has had any of its characters
5763
+ * removed. `replace`/`replaceAll` search `original`, so a match can land on
5764
+ * text that is no longer in the output - overwriting it would resurrect the
5765
+ * removed characters, so such matches are skipped instead.
5766
+ *
5767
+ * @internal
5768
+ */
5769
+ _hasRemovedContent(start, end) {
5770
+ let chunk = this.firstChunk;
5771
+ while (chunk) {
5772
+ if (chunk.content === "" && chunk.start < end && chunk.end > start) return true;
5773
+ chunk = chunk.next;
5774
+ }
5775
+ return false;
5776
+ }
5464
5777
  /** @internal */
5465
5778
  _replaceRegexp(searchValue, replacement) {
5466
5779
  function getReplacement(match, str) {
5467
- if (typeof replacement === "string") return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
5468
- if (i === "$") return "$";
5469
- if (i === "&") return match[0];
5470
- if (+i < match.length) return match[+i];
5471
- return `$${i}`;
5472
- });
5473
- else return replacement(match[0], ...match.slice(1), match.index, str, match.groups);
5780
+ if (typeof replacement === "string") return expandReplacement(replacement, match[0], match.index, str, match.slice(1), match.groups);
5781
+ 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);
5474
5782
  }
5475
5783
  const replaceMatch = (match) => {
5476
- if (match.index == null) return;
5784
+ /* v8 ignore next 2 -- `match.index` is always defined for matches from `matchAll` */
5785
+ if (match.index == null) return false;
5786
+ if (this._hasRemovedContent(match.index, match.index + match[0].length)) return false;
5477
5787
  const replacement = getReplacement(match, this.original);
5478
- if (replacement === match[0]) return;
5788
+ if (replacement === match[0]) return true;
5479
5789
  if (match[0].length === 0) this.appendRight(match.index, replacement);
5480
5790
  else this.overwrite(match.index, match.index + match[0].length, replacement);
5791
+ return true;
5481
5792
  };
5482
5793
  if (searchValue.global) {
5483
5794
  searchValue.lastIndex = 0;
5484
5795
  for (const match of this.original.matchAll(searchValue)) replaceMatch(match);
5485
5796
  } else {
5486
5797
  const match = this.original.match(searchValue);
5487
- if (match) replaceMatch(match);
5798
+ if (match && !replaceMatch(match)) {
5799
+ const global = new RegExp(searchValue.source, `${searchValue.flags}g`);
5800
+ for (const next of this.original.matchAll(global)) if (replaceMatch(next)) break;
5801
+ }
5488
5802
  }
5489
5803
  return this;
5490
5804
  }
5491
5805
  /** @internal */
5492
5806
  _replaceString(string, replacement) {
5493
5807
  const { original } = this;
5494
- const index = original.indexOf(string);
5495
- if (index !== -1) {
5808
+ let index = original.indexOf(string);
5809
+ while (index !== -1) {
5810
+ if (this._hasRemovedContent(index, index + string.length)) {
5811
+ index = original.indexOf(string, index + string.length);
5812
+ continue;
5813
+ }
5496
5814
  if (typeof replacement === "function") replacement = replacement(string, index, original);
5497
- if (string !== replacement) if (string.length === 0) this.appendRight(index, replacement);
5498
- else this.overwrite(index, index + string.length, replacement);
5815
+ else replacement = expandReplacement(replacement, string, index, original, [], void 0);
5816
+ if (string !== replacement) {
5817
+ if (string.length === 0) this.appendRight(index, replacement);
5818
+ else this.overwrite(index, index + string.length, replacement);
5819
+ }
5820
+ break;
5499
5821
  }
5500
5822
  return this;
5501
5823
  }
@@ -5512,14 +5834,15 @@ var MagicString = class MagicString {
5512
5834
  const stringLength = string.length;
5513
5835
  if (stringLength === 0) {
5514
5836
  for (let index = 0; index <= original.length; index += 1) {
5515
- const _replacement = typeof replacement === "function" ? replacement("", index, original) : replacement;
5837
+ const _replacement = typeof replacement === "function" ? replacement("", index, original) : expandReplacement(replacement, "", index, original, [], void 0);
5516
5838
  if (_replacement !== "") this.appendRight(index, _replacement);
5517
5839
  }
5518
5840
  return this;
5519
5841
  }
5520
5842
  for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
5843
+ if (this._hasRemovedContent(index, index + stringLength)) continue;
5521
5844
  const previous = original.slice(index, index + stringLength);
5522
- const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : replacement;
5845
+ const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : expandReplacement(replacement, previous, index, original, [], void 0);
5523
5846
  if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
5524
5847
  }
5525
5848
  return this;
@@ -5570,15 +5893,17 @@ var Bundle$1 = class Bundle {
5570
5893
  if (!hasOwnProp.call(source, option)) source[option] = source.content[option];
5571
5894
  });
5572
5895
  if (source.separator === void 0) source.separator = this.separator;
5573
- if (source.filename) if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
5574
- this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
5575
- this.uniqueSources.push({
5576
- filename: source.filename,
5577
- content: source.content.original
5578
- });
5579
- } else {
5580
- const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
5581
- if (source.content.original !== uniqueSource.content) throw new MagicStringError(`duplicate filename "${source.filename}" with different content, use unique filenames`);
5896
+ if (source.filename) {
5897
+ if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
5898
+ this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
5899
+ this.uniqueSources.push({
5900
+ filename: source.filename,
5901
+ content: source.content.original
5902
+ });
5903
+ } else {
5904
+ const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
5905
+ if (source.content.original !== uniqueSource.content) throw new MagicStringError(`duplicate filename "${source.filename}" with different content, use unique filenames`);
5906
+ }
5582
5907
  }
5583
5908
  this.sources.push(source);
5584
5909
  return this;
@@ -5606,7 +5931,103 @@ var Bundle$1 = class Bundle {
5606
5931
  });
5607
5932
  return bundle;
5608
5933
  }
5934
+ /**
5935
+ * Flattens the bundle into a single `MagicString`, so the concatenated result can be
5936
+ * processed further with the full `MagicString` API. The returned string's `original`
5937
+ * is the concatenation of every source's `original`, and all existing edits, inserts,
5938
+ * intros, outros and separators are preserved as inserted content, so its `toString()`
5939
+ * equals the bundle's `toString()` and its sourcemap maps back to that combined original.
5940
+ *
5941
+ * Because a `MagicString` maps to a single source, per-source `filename`s are not carried
5942
+ * over; generate the bundle's map before flattening if you need the multi-source mapping.
5943
+ */
5944
+ toMagicString() {
5945
+ const combined = new MagicString(this.sources.map((source) => source.content.original).join(""));
5946
+ let offset = 0;
5947
+ let pending = this.intro;
5948
+ let first = null;
5949
+ let last = null;
5950
+ const byStart = /* @__PURE__ */ new Map();
5951
+ const byEnd = /* @__PURE__ */ new Map();
5952
+ let hasMovedChunks = false;
5953
+ this.sources.forEach((source, i) => {
5954
+ const magicString = source.content;
5955
+ const separator = i > 0 ? source.separator !== void 0 ? source.separator : this.separator : "";
5956
+ if (magicString.original.length === 0) {
5957
+ pending += separator + magicString.toString();
5958
+ return;
5959
+ }
5960
+ pending += separator + magicString.intro;
5961
+ let sourceFirst = null;
5962
+ let previous = null;
5963
+ let originalChunk = magicString.firstChunk;
5964
+ while (originalChunk) {
5965
+ const chunk = originalChunk.clone();
5966
+ chunk.start += offset;
5967
+ chunk.end += offset;
5968
+ chunk.previous = previous;
5969
+ chunk.next = null;
5970
+ if (previous) previous.next = chunk;
5971
+ byStart.set(chunk.start, chunk);
5972
+ byEnd.set(chunk.end, chunk);
5973
+ sourceFirst ??= chunk;
5974
+ previous = chunk;
5975
+ originalChunk = originalChunk.next;
5976
+ }
5977
+ const sourceLast = previous;
5978
+ sourceFirst.intro = pending + sourceFirst.intro;
5979
+ pending = "";
5980
+ sourceLast.outro += magicString.outro;
5981
+ if (last) {
5982
+ last.next = sourceFirst;
5983
+ sourceFirst.previous = last;
5984
+ } else first = sourceFirst;
5985
+ last = sourceLast;
5986
+ for (let index = 0; index < magicString.original.length; index += 1) if (magicString.sourcemapLocations.has(index)) combined.sourcemapLocations.add(index + offset);
5987
+ Object.keys(magicString.storedNames).forEach((name) => {
5988
+ Object.defineProperty(combined.storedNames, name, {
5989
+ writable: true,
5990
+ value: true,
5991
+ enumerable: true
5992
+ });
5993
+ });
5994
+ if (magicString.hasMovedChunks) hasMovedChunks = true;
5995
+ offset += magicString.original.length;
5996
+ });
5997
+ if (!first) {
5998
+ combined.intro = pending;
5999
+ return combined;
6000
+ }
6001
+ if (pending) last.outro += pending;
6002
+ combined.firstChunk = first;
6003
+ combined.lastChunk = last;
6004
+ combined.lastSearchedChunk = first;
6005
+ combined.byStart = byStart;
6006
+ combined.byEnd = byEnd;
6007
+ combined.hasMovedChunks = hasMovedChunks;
6008
+ return combined;
6009
+ }
5609
6010
  generateDecodedMap(options = {}) {
6011
+ const mappings = new Mappings(options.hires);
6012
+ const { names, x_google_ignoreList } = this._generateMappings(mappings);
6013
+ return {
6014
+ ...this._mapProperties(options, names, x_google_ignoreList),
6015
+ mappings: mappings.raw,
6016
+ rangeMappings: mappings.rawRangeMappings
6017
+ };
6018
+ }
6019
+ generateMap(options = {}) {
6020
+ const encoder = new MappingsEncoder();
6021
+ const mappings = new Mappings(options.hires, encoder);
6022
+ const { names, x_google_ignoreList } = this._generateMappings(mappings);
6023
+ return new SourceMap({
6024
+ ...this._mapProperties(options, names, x_google_ignoreList),
6025
+ mappings: encoder.finish(mappings.rawSegments),
6026
+ rangeMappings: mappings.rawRangeMappings
6027
+ });
6028
+ }
6029
+ /** @internal */
6030
+ _generateMappings(mappings) {
5610
6031
  const names = [];
5611
6032
  let x_google_ignoreList;
5612
6033
  this.sources.forEach((source) => {
@@ -5614,10 +6035,11 @@ var Bundle$1 = class Bundle {
5614
6035
  if (!names.includes(name)) names.push(name);
5615
6036
  });
5616
6037
  });
5617
- const mappings = new Mappings(options.hires);
5618
6038
  if (this.intro) mappings.advance(this.intro);
5619
6039
  this.sources.forEach((source, i) => {
5620
- if (i > 0) mappings.advance(source.separator !== void 0 ? source.separator : this.separator);
6040
+ if (i > 0)
6041
+ /* v8 ignore next -- addSource always normalizes source.separator */
6042
+ mappings.advance(source.separator !== void 0 ? source.separator : this.separator);
5621
6043
  const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
5622
6044
  const magicString = source.content;
5623
6045
  const locate = getLocator(magicString.original);
@@ -5625,9 +6047,10 @@ var Bundle$1 = class Bundle {
5625
6047
  magicString.firstChunk.eachNext((chunk) => {
5626
6048
  const loc = locate(chunk.start);
5627
6049
  if (chunk.intro.length) mappings.advance(chunk.intro);
5628
- if (source.filename) if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
5629
- else mappings.addUneditedChunk(sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations);
5630
- else mappings.advance(chunk.content);
6050
+ if (source.filename) {
6051
+ if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
6052
+ else mappings.addUneditedChunk(sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations);
6053
+ } else mappings.advance(chunk.content);
5631
6054
  if (chunk.outro.length) mappings.advance(chunk.outro);
5632
6055
  });
5633
6056
  if (magicString.outro) mappings.advance(magicString.outro);
@@ -5636,22 +6059,25 @@ var Bundle$1 = class Bundle {
5636
6059
  x_google_ignoreList.push(sourceIndex);
5637
6060
  }
5638
6061
  });
6062
+ return {
6063
+ names,
6064
+ x_google_ignoreList
6065
+ };
6066
+ }
6067
+ /** @internal */
6068
+ _mapProperties(options, names, x_google_ignoreList) {
5639
6069
  return {
5640
6070
  file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
5641
6071
  sources: this.uniqueSources.map((source) => {
5642
6072
  return options.file ? getRelativePath(options.file, source.filename) : source.filename;
5643
6073
  }),
5644
6074
  sourcesContent: this.uniqueSources.map((source) => {
5645
- return options.includeContent ? source.content : null;
6075
+ return (typeof options.includeContent === "function" ? options.includeContent(source) : options.includeContent) ? source.content : null;
5646
6076
  }),
5647
6077
  names,
5648
- mappings: mappings.raw,
5649
6078
  x_google_ignoreList
5650
6079
  };
5651
6080
  }
5652
- generateMap(options) {
5653
- return new SourceMap(this.generateDecodedMap(options));
5654
- }
5655
6081
  getIndentString() {
5656
6082
  const indentStringCounts = {};
5657
6083
  this.sources.forEach((source) => {
@@ -5669,6 +6095,7 @@ var Bundle$1 = class Bundle {
5669
6095
  if (indentStr === "") return this;
5670
6096
  let trailingNewline = !this.intro || this.intro.slice(-1) === "\n";
5671
6097
  this.sources.forEach((source, i) => {
6098
+ /* v8 ignore next -- addSource always normalizes source.separator */
5672
6099
  const separator = source.separator !== void 0 ? source.separator : this.separator;
5673
6100
  const indentStart = trailingNewline || i > 0 && /\r?\n$/.test(separator);
5674
6101
  source.content.indent(indentStr, {
@@ -5688,6 +6115,7 @@ var Bundle$1 = class Bundle {
5688
6115
  }
5689
6116
  toString() {
5690
6117
  const body = this.sources.map((source, i) => {
6118
+ /* v8 ignore next -- addSource always normalizes source.separator */
5691
6119
  const separator = source.separator !== void 0 ? source.separator : this.separator;
5692
6120
  return (i > 0 ? separator : "") + source.content.toString();
5693
6121
  }).join("");
@@ -5696,6 +6124,7 @@ var Bundle$1 = class Bundle {
5696
6124
  isEmpty() {
5697
6125
  if (this.intro.length && this.intro.trim()) return false;
5698
6126
  if (this.sources.some((source, i) => {
6127
+ /* v8 ignore next -- addSource always normalizes source.separator */
5699
6128
  const separator = source.separator !== void 0 ? source.separator : this.separator;
5700
6129
  return i > 0 && separator.trim() !== "" || !source.content.isEmpty();
5701
6130
  })) return false;
@@ -5703,8 +6132,9 @@ var Bundle$1 = class Bundle {
5703
6132
  }
5704
6133
  length() {
5705
6134
  return this.sources.reduce((length, source, i) => {
6135
+ /* v8 ignore next -- addSource always normalizes source.separator */
5706
6136
  const separator = source.separator !== void 0 ? source.separator : this.separator;
5707
- return length + (i > 0 ? separator.length : 0) + source.content.length();
6137
+ return length + (i > 0 ? separator.length : 0) + source.content.toString().length;
5708
6138
  }, this.intro.length);
5709
6139
  }
5710
6140
  trimLines() {
@@ -5787,6 +6217,14 @@ function findLastWhiteSpaceReverse(code, start, end) {
5787
6217
  }
5788
6218
  }
5789
6219
  }
6220
+ // A CRLF pair is one line break and must be removed as one. Removing only the
6221
+ // LF leaves the CR, which is still a line terminator, so ASI fires anyway and
6222
+ // the operand after a `return` or `throw` becomes dead code.
6223
+ function getLineBreakStart(code, lineBreakPos) {
6224
+ return lineBreakPos > 0 && code.charCodeAt(lineBreakPos - 1) === 13 /*"\r"*/
6225
+ ? lineBreakPos - 1
6226
+ : lineBreakPos;
6227
+ }
5790
6228
  // This assumes "code" only contains white-space and comments
5791
6229
  // Returns position of line-comment if applicable
5792
6230
  function findFirstLineBreakOutsideComment(code) {
@@ -5795,7 +6233,7 @@ function findFirstLineBreakOutsideComment(code) {
5795
6233
  while (true) {
5796
6234
  start = code.indexOf('/', start);
5797
6235
  if (start === -1 || start > lineBreakPos)
5798
- return [lineBreakPos, lineBreakPos + 1];
6236
+ return [getLineBreakStart(code, lineBreakPos), lineBreakPos + 1];
5799
6237
  // With our assumption, '/' always starts a comment. Determine comment type:
5800
6238
  charCodeAfterSlash = code.charCodeAt(start + 1);
5801
6239
  if (charCodeAfterSlash === 47 /*"/"*/)
@@ -12145,7 +12583,7 @@ function formatAttributes(attributes, { getObject }) {
12145
12583
  if (!attributes) {
12146
12584
  return null;
12147
12585
  }
12148
- const assertionEntries = Object.entries(attributes).map(([key, value]) => [key, `'${value}'`]);
12586
+ const assertionEntries = Object.entries(attributes).map(([key, value]) => [key, JSON.stringify(value)]);
12149
12587
  if (assertionEntries.length > 0) {
12150
12588
  return getObject(assertionEntries, { lineBreakIndent: null });
12151
12589
  }
@@ -19279,7 +19717,7 @@ class Module {
19279
19717
  }
19280
19718
  return null;
19281
19719
  }
19282
- updateOptions({ meta, moduleSideEffects, syntheticNamedExports }) {
19720
+ updateOptions({ meta, moduleSideEffects, syntheticNamedExports }, { replaceExistingMeta = false } = parseAst_js.EMPTY_OBJECT) {
19283
19721
  if (moduleSideEffects != null) {
19284
19722
  this.info.moduleSideEffects = moduleSideEffects;
19285
19723
  }
@@ -19287,6 +19725,11 @@ class Module {
19287
19725
  this.info.syntheticNamedExports = syntheticNamedExports;
19288
19726
  }
19289
19727
  if (meta != null) {
19728
+ if (replaceExistingMeta) {
19729
+ for (const key of Object.keys(this.info.meta)) {
19730
+ delete this.info.meta[key];
19731
+ }
19732
+ }
19290
19733
  Object.assign(this.info.meta, meta);
19291
19734
  }
19292
19735
  }
@@ -22991,8 +23434,14 @@ class ModuleLoader {
22991
23434
  const cachedModule = this.graph.cachedModules.get(id);
22992
23435
  if (cachedModule &&
22993
23436
  !cachedModule.customTransformCache &&
22994
- cachedModule.originalCode === sourceDescription.code &&
22995
- !(await this.pluginDriver.hookFirst('shouldTransformCachedModule', [
23437
+ cachedModule.originalCode === sourceDescription.code) {
23438
+ const originalModuleOptions = {
23439
+ meta: { ...module.info.meta },
23440
+ moduleSideEffects: module.info.moduleSideEffects,
23441
+ syntheticNamedExports: module.info.syntheticNamedExports
23442
+ };
23443
+ module.updateOptions(cachedModule);
23444
+ if (await this.pluginDriver.hookFirst('shouldTransformCachedModule', [
22996
23445
  {
22997
23446
  ast: cachedModule.ast,
22998
23447
  attributes: cachedModule.attributes,
@@ -23003,17 +23452,20 @@ class ModuleLoader {
23003
23452
  resolvedSources: cachedModule.resolvedIds,
23004
23453
  syntheticNamedExports: cachedModule.syntheticNamedExports
23005
23454
  }
23006
- ]))) {
23007
- if (cachedModule.transformFiles) {
23008
- for (const emittedFile of cachedModule.transformFiles)
23009
- this.pluginDriver.emitFile(emittedFile);
23455
+ ])) {
23456
+ module.updateOptions(originalModuleOptions, { replaceExistingMeta: true });
23457
+ }
23458
+ else {
23459
+ if (cachedModule.transformFiles) {
23460
+ for (const emittedFile of cachedModule.transformFiles)
23461
+ this.pluginDriver.emitFile(emittedFile);
23462
+ }
23463
+ await module.setSource(cachedModule);
23464
+ return;
23010
23465
  }
23011
- await module.setSource(cachedModule);
23012
- }
23013
- else {
23014
- module.updateOptions(sourceDescription);
23015
- await module.setSource(await transform(sourceDescription, module, this.pluginDriver, this.options));
23016
23466
  }
23467
+ module.updateOptions(sourceDescription);
23468
+ await module.setSource(await transform(sourceDescription, module, this.pluginDriver, this.options));
23017
23469
  }
23018
23470
  async awaitLoadModulesPromise() {
23019
23471
  let startingPromise;