@rollup/wasm-node 4.63.1 → 4.63.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v4.63.1
4
- Fri, 28 Aug 2026 05:58:50 GMT - commit 78bfef0cb94479566f81012fafa372c84b90bd34
3
+ Rollup.js v4.63.3
4
+ Mon, 14 Sep 2026 12:44:36 GMT - commit 250deca2945f8817350564f7d52bab0f79175d1b
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -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.1";
45
+ var version = "4.63.3";
46
46
  const package_ = {
47
47
  version: version};
48
48
 
@@ -4232,7 +4232,7 @@ for (let i = 0; i < chars.length; i++) {
4232
4232
  intToChar[i] = c;
4233
4233
  charToInt[c] = i;
4234
4234
  }
4235
- function decodeInteger(reader, relative) {
4235
+ function decodeInteger(reader) {
4236
4236
  let value = 0;
4237
4237
  let shift = 0;
4238
4238
  let integer = 0;
@@ -4242,23 +4242,21 @@ function decodeInteger(reader, relative) {
4242
4242
  value |= (integer & 31) << shift;
4243
4243
  shift += 5;
4244
4244
  } while (integer & 32);
4245
- const shouldNegate = value & 1;
4246
- value >>>= 1;
4247
- if (shouldNegate) {
4248
- value = -2147483648 | -value;
4249
- }
4250
- return relative + value;
4245
+ return value;
4246
+ }
4247
+ function decodeSign(num) {
4248
+ return num & 1 ? -2147483648 | -(num >>> 1) : num >>> 1;
4251
4249
  }
4252
- function encodeInteger(builder, num, relative) {
4253
- let delta = num - relative;
4254
- delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
4250
+ function encodeInteger(builder, num) {
4255
4251
  do {
4256
- let clamped = delta & 31;
4257
- delta >>>= 5;
4258
- if (delta > 0) clamped |= 32;
4252
+ let clamped = num & 31;
4253
+ num >>>= 5;
4254
+ if (num > 0) clamped |= 32;
4259
4255
  builder.write(intToChar[clamped]);
4260
- } while (delta > 0);
4261
- return num;
4256
+ } while (num > 0);
4257
+ }
4258
+ function encodeSign(num) {
4259
+ return num < 0 ? -num << 1 | 1 : num << 1;
4262
4260
  }
4263
4261
  function hasMoreVlq(reader, max) {
4264
4262
  if (reader.pos >= max) return false;
@@ -4317,6 +4315,21 @@ var StringReader = class {
4317
4315
  return idx === -1 ? buffer.length : idx;
4318
4316
  }
4319
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
+ }
4320
4333
 
4321
4334
  // src/sourcemap-codec.ts
4322
4335
  function decode(mappings) {
@@ -4336,15 +4349,15 @@ function decode(mappings) {
4336
4349
  genColumn = 0;
4337
4350
  while (reader.pos < semi) {
4338
4351
  let seg;
4339
- genColumn = decodeInteger(reader, genColumn);
4352
+ genColumn += decodeSign(decodeInteger(reader));
4340
4353
  if (genColumn < lastCol) sorted = false;
4341
4354
  lastCol = genColumn;
4342
4355
  if (hasMoreVlq(reader, semi)) {
4343
- sourcesIndex = decodeInteger(reader, sourcesIndex);
4344
- sourceLine = decodeInteger(reader, sourceLine);
4345
- sourceColumn = decodeInteger(reader, sourceColumn);
4356
+ sourcesIndex += decodeSign(decodeInteger(reader));
4357
+ sourceLine += decodeSign(decodeInteger(reader));
4358
+ sourceColumn += decodeSign(decodeInteger(reader));
4346
4359
  if (hasMoreVlq(reader, semi)) {
4347
- namesIndex = decodeInteger(reader, namesIndex);
4360
+ namesIndex += decodeSign(decodeInteger(reader));
4348
4361
  seg = [genColumn, sourcesIndex, sourceLine, sourceColumn, namesIndex];
4349
4362
  } else {
4350
4363
  seg = [genColumn, sourcesIndex, sourceLine, sourceColumn];
@@ -4381,13 +4394,18 @@ function encode(decoded) {
4381
4394
  for (let j = 0; j < line.length; j++) {
4382
4395
  const segment = line[j];
4383
4396
  if (j > 0) writer.write(comma);
4384
- genColumn = encodeInteger(writer, segment[0], genColumn);
4397
+ encodeInteger(writer, encodeSign(segment[0] - genColumn));
4398
+ genColumn = segment[0];
4385
4399
  if (segment.length === 1) continue;
4386
- sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
4387
- sourceLine = encodeInteger(writer, segment[2], sourceLine);
4388
- sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
4400
+ encodeInteger(writer, encodeSign(segment[1] - sourcesIndex));
4401
+ encodeInteger(writer, encodeSign(segment[2] - sourceLine));
4402
+ encodeInteger(writer, encodeSign(segment[3] - sourceColumn));
4403
+ sourcesIndex = segment[1];
4404
+ sourceLine = segment[2];
4405
+ sourceColumn = segment[3];
4389
4406
  if (segment.length === 4) continue;
4390
- namesIndex = encodeInteger(writer, segment[4], namesIndex);
4407
+ encodeInteger(writer, encodeSign(segment[4] - namesIndex));
4408
+ namesIndex = segment[4];
4391
4409
  }
4392
4410
  }
4393
4411
  return writer.flush();
@@ -4506,8 +4524,10 @@ var Chunk$1 = class Chunk {
4506
4524
  if (this.outro.length) return true;
4507
4525
  const trimmed = this.content.replace(rx, "");
4508
4526
  if (trimmed.length) {
4509
- if (trimmed !== this.content) if (this.edited) this.edit(trimmed, this.storeName, true);
4510
- 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
+ }
4511
4531
  return true;
4512
4532
  } else {
4513
4533
  this.edit("", void 0, true);
@@ -4520,10 +4540,12 @@ var Chunk$1 = class Chunk {
4520
4540
  if (this.intro.length) return true;
4521
4541
  const trimmed = this.content.replace(rx, "");
4522
4542
  if (trimmed.length) {
4523
- if (trimmed !== this.content) if (this.edited) this.edit(trimmed, this.storeName, true);
4524
- else {
4525
- this.split(this.end - trimmed.length);
4526
- 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
+ }
4527
4549
  }
4528
4550
  return true;
4529
4551
  } else {
@@ -4550,12 +4572,14 @@ var MagicStringError = class extends Error {
4550
4572
  //#endregion
4551
4573
  //#region src/SourceMap.ts
4552
4574
  function getBtoa() {
4575
+ /* v8 ignore next -- environment fallback, unreachable when `btoa` is present */
4553
4576
  if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
4554
4577
  const buffer = globalThis["Buffer"];
4555
4578
  if (buffer) return (str) => buffer.from(str, "utf-8").toString("base64");
4556
4579
  return () => {
4557
4580
  throw new MagicStringError("unsupported environment: `btoa` or `Buffer` is required");
4558
4581
  };
4582
+ /* v8 ignore stop */
4559
4583
  }
4560
4584
  const btoa = /* #__PURE__ */ getBtoa();
4561
4585
  var SourceMap = class {
@@ -4568,6 +4592,14 @@ var SourceMap = class {
4568
4592
  this.mappings = encode(properties.mappings);
4569
4593
  if (typeof properties.x_google_ignoreList !== "undefined") this.x_google_ignoreList = properties.x_google_ignoreList;
4570
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
+ }
4571
4603
  }
4572
4604
  /**
4573
4605
  * Returns the equivalent of `JSON.stringify(map)`
@@ -4586,12 +4618,8 @@ var SourceMap = class {
4586
4618
  //#endregion
4587
4619
  //#region src/utils/getLocator.ts
4588
4620
  function getLocator(source) {
4589
- const originalLines = source.split("\n");
4590
- const lineOffsets = [];
4591
- for (let i = 0, pos = 0; i < originalLines.length; i++) {
4592
- lineOffsets.push(pos);
4593
- pos += originalLines[i].length + 1;
4594
- }
4621
+ const lineOffsets = [0];
4622
+ for (let i = source.indexOf("\n"); i !== -1; i = source.indexOf("\n", i + 1)) lineOffsets.push(i + 1);
4595
4623
  return function locate(index) {
4596
4624
  let i = 0;
4597
4625
  let j = lineOffsets.length;
@@ -4645,7 +4673,10 @@ function isObject(thing) {
4645
4673
  }
4646
4674
  //#endregion
4647
4675
  //#region src/utils/Mappings.ts
4648
- const wordRegex = /\w/;
4676
+ const NEWLINE_CHAR$1 = 10;
4677
+ function isWordCode(code) {
4678
+ return code >= 97 && code <= 122 || code >= 65 && code <= 90 || code >= 48 && code <= 57 || code === 95;
4679
+ }
4649
4680
  var Mappings = class {
4650
4681
  constructor(hires) {
4651
4682
  this.hires = hires;
@@ -4653,9 +4684,12 @@ var Mappings = class {
4653
4684
  this.generatedCodeColumn = 0;
4654
4685
  this.raw = [];
4655
4686
  this.rawSegments = this.raw[this.generatedCodeLine] = [];
4687
+ this.rawRangeMappings = [];
4688
+ this.rawRangeMappingsIndices = this.rawRangeMappings[this.generatedCodeLine] = [];
4656
4689
  this.pending = null;
4657
4690
  }
4658
4691
  addEdit(sourceIndex, content, loc, nameIndex) {
4692
+ /* v8 ignore else -- `pending` is never assigned a truthy value */
4659
4693
  if (content.length) {
4660
4694
  const contentLengthMinusOne = content.length - 1;
4661
4695
  let contentLineEnd = content.indexOf("\n", 0);
@@ -4671,6 +4705,7 @@ var Mappings = class {
4671
4705
  this.rawSegments.push(segment);
4672
4706
  this.generatedCodeLine += 1;
4673
4707
  this.raw[this.generatedCodeLine] = this.rawSegments = [];
4708
+ this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
4674
4709
  this.generatedCodeColumn = 0;
4675
4710
  previousContentLineEnd = contentLineEnd;
4676
4711
  contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
@@ -4691,56 +4726,128 @@ var Mappings = class {
4691
4726
  this.pending = null;
4692
4727
  }
4693
4728
  addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
4694
- let originalCharIndex = chunk.start;
4695
- let first = true;
4696
- let charInHiresBoundary = false;
4697
- while (originalCharIndex < chunk.end) {
4698
- if (original[originalCharIndex] === "\n") {
4699
- loc.line += 1;
4700
- loc.column = 0;
4701
- this.generatedCodeLine += 1;
4702
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
4703
- this.generatedCodeColumn = 0;
4704
- first = true;
4705
- charInHiresBoundary = false;
4706
- } else {
4707
- if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
4708
- const segment = [
4729
+ const end = chunk.end;
4730
+ let i = chunk.start;
4731
+ if (this.hires) {
4732
+ const boundary = this.hires === "boundary";
4733
+ const experimentalRange = this.hires === "experimental-range";
4734
+ let charInHiresBoundary = false;
4735
+ while (i < end) {
4736
+ if (experimentalRange && i + 1 >= end) this.rawSegments.push([
4737
+ this.generatedCodeColumn,
4738
+ sourceIndex,
4739
+ loc.line,
4740
+ loc.column
4741
+ ]);
4742
+ const code = original.charCodeAt(i);
4743
+ if (code === NEWLINE_CHAR$1) {
4744
+ loc.line += 1;
4745
+ loc.column = 0;
4746
+ this.generatedCodeLine += 1;
4747
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
4748
+ this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
4749
+ this.generatedCodeColumn = 0;
4750
+ charInHiresBoundary = false;
4751
+ } else {
4752
+ if (boundary) {
4753
+ if (isWordCode(code)) {
4754
+ if (!charInHiresBoundary) {
4755
+ this.rawSegments.push([
4756
+ this.generatedCodeColumn,
4757
+ sourceIndex,
4758
+ loc.line,
4759
+ loc.column
4760
+ ]);
4761
+ charInHiresBoundary = true;
4762
+ }
4763
+ } else {
4764
+ this.rawSegments.push([
4765
+ this.generatedCodeColumn,
4766
+ sourceIndex,
4767
+ loc.line,
4768
+ loc.column
4769
+ ]);
4770
+ charInHiresBoundary = false;
4771
+ }
4772
+ } else if (experimentalRange) {
4773
+ if (i === chunk.start) {
4774
+ this.rawRangeMappingsIndices.push(this.rawSegments.length);
4775
+ this.rawSegments.push([
4776
+ this.generatedCodeColumn,
4777
+ sourceIndex,
4778
+ loc.line,
4779
+ loc.column
4780
+ ]);
4781
+ }
4782
+ } else this.rawSegments.push([
4783
+ this.generatedCodeColumn,
4784
+ sourceIndex,
4785
+ loc.line,
4786
+ loc.column
4787
+ ]);
4788
+ loc.column += 1;
4789
+ this.generatedCodeColumn += 1;
4790
+ }
4791
+ i += 1;
4792
+ }
4793
+ } else {
4794
+ const bits = sourcemapLocations.bits;
4795
+ while (i < end) {
4796
+ let newline = original.indexOf("\n", i);
4797
+ if (newline === -1 || newline > end) newline = end;
4798
+ if (newline > i) {
4799
+ this.rawSegments.push([
4709
4800
  this.generatedCodeColumn,
4710
4801
  sourceIndex,
4711
4802
  loc.line,
4712
4803
  loc.column
4713
- ];
4714
- if (this.hires === "boundary") if (wordRegex.test(original[originalCharIndex])) {
4715
- if (!charInHiresBoundary) {
4716
- this.rawSegments.push(segment);
4717
- charInHiresBoundary = true;
4804
+ ]);
4805
+ for (let w = i + 1 >> 5, last = newline - 1 >> 5; w <= last; w++) {
4806
+ let word = bits[w];
4807
+ if (!word) continue;
4808
+ const base = w << 5;
4809
+ while (word) {
4810
+ const lowest = word & -word;
4811
+ const index = base + 31 - Math.clz32(lowest);
4812
+ if (index > i && index < newline) {
4813
+ const offset = index - i;
4814
+ this.rawSegments.push([
4815
+ this.generatedCodeColumn + offset,
4816
+ sourceIndex,
4817
+ loc.line,
4818
+ loc.column + offset
4819
+ ]);
4820
+ }
4821
+ word ^= lowest;
4718
4822
  }
4719
- } else {
4720
- this.rawSegments.push(segment);
4721
- charInHiresBoundary = false;
4722
4823
  }
4723
- else this.rawSegments.push(segment);
4824
+ loc.column += newline - i;
4825
+ this.generatedCodeColumn += newline - i;
4724
4826
  }
4725
- loc.column += 1;
4726
- this.generatedCodeColumn += 1;
4727
- first = false;
4827
+ if (newline === end) break;
4828
+ loc.line += 1;
4829
+ loc.column = 0;
4830
+ this.generatedCodeLine += 1;
4831
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
4832
+ this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
4833
+ this.generatedCodeColumn = 0;
4834
+ i = newline + 1;
4728
4835
  }
4729
- originalCharIndex += 1;
4730
4836
  }
4731
4837
  this.pending = null;
4732
4838
  }
4733
4839
  advance(str) {
4734
4840
  if (!str) return;
4735
- const lines = str.split("\n");
4736
- if (lines.length > 1) {
4737
- for (let i = 0; i < lines.length - 1; i++) {
4841
+ const lastNewline = str.lastIndexOf("\n");
4842
+ if (lastNewline !== -1) {
4843
+ for (let i = str.indexOf("\n"); i !== -1; i = str.indexOf("\n", i + 1)) {
4738
4844
  this.generatedCodeLine++;
4739
4845
  this.raw[this.generatedCodeLine] = this.rawSegments = [];
4846
+ this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
4740
4847
  }
4741
4848
  this.generatedCodeColumn = 0;
4742
4849
  }
4743
- this.generatedCodeColumn += lines[lines.length - 1].length;
4850
+ this.generatedCodeColumn += str.length - lastNewline - 1;
4744
4851
  }
4745
4852
  };
4746
4853
  //#endregion
@@ -4753,6 +4860,63 @@ const warned = {
4753
4860
  insertRight: false,
4754
4861
  storeName: false
4755
4862
  };
4863
+ /**
4864
+ * Expands the `$` substitution patterns that `String.prototype.replace` accepts
4865
+ * in a string replacement.
4866
+ * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
4867
+ *
4868
+ * `captures` holds the capture groups in order, so `captures[0]` is `$1`.
4869
+ * `namedCaptures` is `undefined` when the pattern has no named groups, and
4870
+ * `$<name>` is then literal text - which is also the case for a string search
4871
+ * value, where there are no groups of either kind.
4872
+ */
4873
+ function expandReplacement(replacement, matched, position, str, captures, namedCaptures) {
4874
+ if (!replacement.includes("$")) return replacement;
4875
+ let result = "";
4876
+ let index = 0;
4877
+ while (index < replacement.length) {
4878
+ const dollar = replacement.indexOf("$", index);
4879
+ if (dollar === -1) {
4880
+ result += replacement.slice(index);
4881
+ break;
4882
+ }
4883
+ result += replacement.slice(index, dollar);
4884
+ const char = replacement[dollar + 1];
4885
+ let expansion = "$";
4886
+ let consumed = 1;
4887
+ if (char === "$") consumed = 2;
4888
+ else if (char === "&") {
4889
+ expansion = matched;
4890
+ consumed = 2;
4891
+ } else if (char === "`") {
4892
+ expansion = str.slice(0, position);
4893
+ consumed = 2;
4894
+ } else if (char === "'") {
4895
+ expansion = str.slice(position + matched.length);
4896
+ consumed = 2;
4897
+ } else if (char === "<" && namedCaptures !== void 0) {
4898
+ const close = replacement.indexOf(">", dollar + 2);
4899
+ if (close !== -1) {
4900
+ expansion = namedCaptures[replacement.slice(dollar + 2, close)] ?? "";
4901
+ consumed = close + 1 - dollar;
4902
+ }
4903
+ } else if (char >= "0" && char <= "9") {
4904
+ const second = replacement[dollar + 2];
4905
+ const double = second >= "0" && second <= "9" ? Number(char + second) : NaN;
4906
+ const single = Number(char);
4907
+ if (double >= 1 && double <= captures.length) {
4908
+ expansion = captures[double - 1] ?? "";
4909
+ consumed = 3;
4910
+ } else if (single >= 1 && single <= captures.length) {
4911
+ expansion = captures[single - 1] ?? "";
4912
+ consumed = 2;
4913
+ }
4914
+ }
4915
+ result += expansion;
4916
+ index = dollar + consumed;
4917
+ }
4918
+ return result;
4919
+ }
4756
4920
  var MagicString = class MagicString {
4757
4921
  constructor(string, options = {}) {
4758
4922
  const chunk = new Chunk$1(0, string.length, string);
@@ -4922,7 +5086,8 @@ var MagicString = class MagicString {
4922
5086
  sourcesContent: options.includeContent ? [this.original] : void 0,
4923
5087
  names,
4924
5088
  mappings: mappings.raw,
4925
- x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
5089
+ x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0,
5090
+ rangeMappings: mappings.rawRangeMappings
4926
5091
  };
4927
5092
  }
4928
5093
  /**
@@ -4962,17 +5127,18 @@ var MagicString = class MagicString {
4962
5127
  for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded[i] = true;
4963
5128
  });
4964
5129
  let shouldIndentNextCharacter = options.indentStart !== false;
4965
- const replacer = (match) => {
4966
- if (shouldIndentNextCharacter) return `${resolvedIndentStr}${match}`;
4967
- shouldIndentNextCharacter = true;
4968
- return match;
5130
+ const indentPiece = (str) => {
5131
+ if (str === "") return str;
5132
+ const indented = str.replace(pattern, (match, offset) => offset > 0 || shouldIndentNextCharacter ? `${resolvedIndentStr}${match}` : match);
5133
+ shouldIndentNextCharacter = str[str.length - 1] === "\n";
5134
+ return indented;
4969
5135
  };
4970
- this.intro = this.intro.replace(pattern, replacer);
5136
+ this.intro = indentPiece(this.intro);
4971
5137
  let charIndex = 0;
4972
5138
  let chunk = this.firstChunk;
4973
5139
  const indentAt = (index) => {
4974
5140
  shouldIndentNextCharacter = false;
4975
- if (index === chunk.start) chunk.prependRight(resolvedIndentStr);
5141
+ if (index === chunk.start) chunk.appendRight(resolvedIndentStr);
4976
5142
  else {
4977
5143
  this._splitChunk(chunk, index);
4978
5144
  chunk = chunk.next;
@@ -4981,11 +5147,9 @@ var MagicString = class MagicString {
4981
5147
  };
4982
5148
  while (chunk) {
4983
5149
  const end = chunk.end;
5150
+ if (!isExcluded[chunk.start]) chunk.intro = indentPiece(chunk.intro);
4984
5151
  if (chunk.edited) {
4985
- if (!isExcluded[charIndex]) {
4986
- chunk.content = chunk.content.replace(pattern, replacer);
4987
- if (chunk.content.length) shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
4988
- }
5152
+ if (!isExcluded[charIndex]) chunk.content = indentPiece(chunk.content);
4989
5153
  } else if (options.exclude) {
4990
5154
  charIndex = chunk.start;
4991
5155
  while (charIndex < end) {
@@ -5015,10 +5179,11 @@ var MagicString = class MagicString {
5015
5179
  charIndex += 1;
5016
5180
  }
5017
5181
  }
5182
+ if (!isExcluded[chunk.end - 1]) chunk.outro = indentPiece(chunk.outro);
5018
5183
  charIndex = chunk.end;
5019
5184
  chunk = chunk.next;
5020
5185
  }
5021
- this.outro = this.outro.replace(pattern, replacer);
5186
+ this.outro = indentPiece(this.outro);
5022
5187
  return this;
5023
5188
  }
5024
5189
  /** @internal */
@@ -5112,8 +5277,8 @@ var MagicString = class MagicString {
5112
5277
  end = end + this.offset;
5113
5278
  if (typeof content !== "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
5114
5279
  if (this.original.length !== 0) {
5115
- while (start < 0) start += this.original.length;
5116
- while (end < 0) end += this.original.length;
5280
+ if (start < 0) start = Math.max(0, start + this.original.length);
5281
+ if (end < 0) end = Math.max(0, end + this.original.length);
5117
5282
  }
5118
5283
  if (start < 0) throw new MagicStringError(`start ${start} is out of bounds`);
5119
5284
  if (end > this.original.length) throw new MagicStringError(`end ${end} is out of bounds`);
@@ -5141,6 +5306,7 @@ var MagicString = class MagicString {
5141
5306
  }
5142
5307
  const first = this.byStart.get(start);
5143
5308
  const last = this.byEnd.get(end);
5309
+ /* v8 ignore else -- unreachable: a valid start/end always yields a `first` chunk */
5144
5310
  if (first) {
5145
5311
  let chunk = first;
5146
5312
  while (chunk !== last) {
@@ -5196,8 +5362,8 @@ var MagicString = class MagicString {
5196
5362
  start = start + this.offset;
5197
5363
  end = end + this.offset;
5198
5364
  if (this.original.length !== 0) {
5199
- while (start < 0) start += this.original.length;
5200
- while (end < 0) end += this.original.length;
5365
+ if (start < 0) start = Math.max(0, start + this.original.length);
5366
+ if (end < 0) end = Math.max(0, end + this.original.length);
5201
5367
  }
5202
5368
  if (start === end) return this;
5203
5369
  if (start < 0 || end > this.original.length) throw new MagicStringError(`range ${start}–${end} is out of bounds`);
@@ -5220,8 +5386,8 @@ var MagicString = class MagicString {
5220
5386
  start = start + this.offset;
5221
5387
  end = end + this.offset;
5222
5388
  if (this.original.length !== 0) {
5223
- while (start < 0) start += this.original.length;
5224
- while (end < 0) end += this.original.length;
5389
+ if (start < 0) start = Math.max(0, start + this.original.length);
5390
+ if (end < 0) end = Math.max(0, end + this.original.length);
5225
5391
  }
5226
5392
  if (start === end) return this;
5227
5393
  if (start < 0 || end > this.original.length) throw new MagicStringError(`range ${start}–${end} is out of bounds`);
@@ -5282,8 +5448,8 @@ var MagicString = class MagicString {
5282
5448
  start = start + this.offset;
5283
5449
  end = end + this.offset;
5284
5450
  if (this.original.length !== 0) {
5285
- while (start < 0) start += this.original.length;
5286
- while (end < 0) end += this.original.length;
5451
+ if (start < 0) start = Math.max(0, start + this.original.length);
5452
+ if (end < 0) end = Math.max(0, end + this.original.length);
5287
5453
  }
5288
5454
  let result = "";
5289
5455
  let chunk = this.firstChunk;
@@ -5358,11 +5524,13 @@ var MagicString = class MagicString {
5358
5524
  * Returns true if the resulting source is empty (disregarding white space).
5359
5525
  */
5360
5526
  isEmpty() {
5527
+ if (this.intro.length && this.intro.trim()) return false;
5361
5528
  let chunk = this.firstChunk;
5362
5529
  while (chunk) {
5363
5530
  if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim()) return false;
5364
5531
  chunk = chunk.next;
5365
5532
  }
5533
+ if (this.outro.length && this.outro.trim()) return false;
5366
5534
  return true;
5367
5535
  }
5368
5536
  length() {
@@ -5461,35 +5629,23 @@ var MagicString = class MagicString {
5461
5629
  /** @internal */
5462
5630
  _replaceRegexp(searchValue, replacement) {
5463
5631
  function getReplacement(match, str) {
5464
- if (typeof replacement === "string") return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
5465
- if (i === "$") return "$";
5466
- if (i === "&") return match[0];
5467
- if (+i < match.length) return match[+i];
5468
- return `$${i}`;
5469
- });
5470
- else return replacement(match[0], ...match.slice(1), match.index, str, match.groups);
5471
- }
5472
- function matchAll(re, str) {
5473
- const matches = [];
5474
- while (true) {
5475
- const match = re.exec(str);
5476
- if (!match) break;
5477
- matches.push(match);
5478
- }
5479
- return matches;
5632
+ if (typeof replacement === "string") return expandReplacement(replacement, match[0], match.index, str, match.slice(1), match.groups);
5633
+ 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);
5480
5634
  }
5481
- if (searchValue.global) matchAll(searchValue, this.original).forEach((match) => {
5482
- if (match.index != null) {
5483
- const replacement = getReplacement(match, this.original);
5484
- if (replacement !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement);
5485
- }
5486
- });
5487
- else {
5635
+ const replaceMatch = (match) => {
5636
+ /* v8 ignore next 2 -- `match.index` is always defined for matches from `matchAll` */
5637
+ if (match.index == null) return;
5638
+ const replacement = getReplacement(match, this.original);
5639
+ if (replacement === match[0]) return;
5640
+ if (match[0].length === 0) this.appendRight(match.index, replacement);
5641
+ else this.overwrite(match.index, match.index + match[0].length, replacement);
5642
+ };
5643
+ if (searchValue.global) {
5644
+ searchValue.lastIndex = 0;
5645
+ for (const match of this.original.matchAll(searchValue)) replaceMatch(match);
5646
+ } else {
5488
5647
  const match = this.original.match(searchValue);
5489
- if (match && match.index != null) {
5490
- const replacement = getReplacement(match, this.original);
5491
- if (replacement !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement);
5492
- }
5648
+ if (match) replaceMatch(match);
5493
5649
  }
5494
5650
  return this;
5495
5651
  }
@@ -5499,7 +5655,11 @@ var MagicString = class MagicString {
5499
5655
  const index = original.indexOf(string);
5500
5656
  if (index !== -1) {
5501
5657
  if (typeof replacement === "function") replacement = replacement(string, index, original);
5502
- if (string !== replacement) this.overwrite(index, index + string.length, replacement);
5658
+ else replacement = expandReplacement(replacement, string, index, original, [], void 0);
5659
+ if (string !== replacement) {
5660
+ if (string.length === 0) this.appendRight(index, replacement);
5661
+ else this.overwrite(index, index + string.length, replacement);
5662
+ }
5503
5663
  }
5504
5664
  return this;
5505
5665
  }
@@ -5514,9 +5674,16 @@ var MagicString = class MagicString {
5514
5674
  _replaceAllString(string, replacement) {
5515
5675
  const { original } = this;
5516
5676
  const stringLength = string.length;
5677
+ if (stringLength === 0) {
5678
+ for (let index = 0; index <= original.length; index += 1) {
5679
+ const _replacement = typeof replacement === "function" ? replacement("", index, original) : expandReplacement(replacement, "", index, original, [], void 0);
5680
+ if (_replacement !== "") this.appendRight(index, _replacement);
5681
+ }
5682
+ return this;
5683
+ }
5517
5684
  for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
5518
5685
  const previous = original.slice(index, index + stringLength);
5519
- const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : replacement;
5686
+ const _replacement = typeof replacement === "function" ? replacement(previous, index, original) : expandReplacement(replacement, previous, index, original, [], void 0);
5520
5687
  if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
5521
5688
  }
5522
5689
  return this;
@@ -5567,15 +5734,17 @@ var Bundle$1 = class Bundle {
5567
5734
  if (!hasOwnProp.call(source, option)) source[option] = source.content[option];
5568
5735
  });
5569
5736
  if (source.separator === void 0) source.separator = this.separator;
5570
- if (source.filename) if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
5571
- this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
5572
- this.uniqueSources.push({
5573
- filename: source.filename,
5574
- content: source.content.original
5575
- });
5576
- } else {
5577
- const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
5578
- if (source.content.original !== uniqueSource.content) throw new MagicStringError(`duplicate filename "${source.filename}" with different content, use unique filenames`);
5737
+ if (source.filename) {
5738
+ if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
5739
+ this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
5740
+ this.uniqueSources.push({
5741
+ filename: source.filename,
5742
+ content: source.content.original
5743
+ });
5744
+ } else {
5745
+ const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
5746
+ if (source.content.original !== uniqueSource.content) throw new MagicStringError(`duplicate filename "${source.filename}" with different content, use unique filenames`);
5747
+ }
5579
5748
  }
5580
5749
  this.sources.push(source);
5581
5750
  return this;
@@ -5614,7 +5783,9 @@ var Bundle$1 = class Bundle {
5614
5783
  const mappings = new Mappings(options.hires);
5615
5784
  if (this.intro) mappings.advance(this.intro);
5616
5785
  this.sources.forEach((source, i) => {
5617
- if (i > 0) mappings.advance(source.separator !== void 0 ? source.separator : this.separator);
5786
+ if (i > 0)
5787
+ /* v8 ignore next -- addSource always normalizes source.separator */
5788
+ mappings.advance(source.separator !== void 0 ? source.separator : this.separator);
5618
5789
  const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
5619
5790
  const magicString = source.content;
5620
5791
  const locate = getLocator(magicString.original);
@@ -5622,9 +5793,10 @@ var Bundle$1 = class Bundle {
5622
5793
  magicString.firstChunk.eachNext((chunk) => {
5623
5794
  const loc = locate(chunk.start);
5624
5795
  if (chunk.intro.length) mappings.advance(chunk.intro);
5625
- if (source.filename) if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
5626
- else mappings.addUneditedChunk(sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations);
5627
- else mappings.advance(chunk.content);
5796
+ if (source.filename) {
5797
+ if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
5798
+ else mappings.addUneditedChunk(sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations);
5799
+ } else mappings.advance(chunk.content);
5628
5800
  if (chunk.outro.length) mappings.advance(chunk.outro);
5629
5801
  });
5630
5802
  if (magicString.outro) mappings.advance(magicString.outro);
@@ -5639,11 +5811,12 @@ var Bundle$1 = class Bundle {
5639
5811
  return options.file ? getRelativePath(options.file, source.filename) : source.filename;
5640
5812
  }),
5641
5813
  sourcesContent: this.uniqueSources.map((source) => {
5642
- return options.includeContent ? source.content : null;
5814
+ return (typeof options.includeContent === "function" ? options.includeContent(source) : options.includeContent) ? source.content : null;
5643
5815
  }),
5644
5816
  names,
5645
5817
  mappings: mappings.raw,
5646
- x_google_ignoreList
5818
+ x_google_ignoreList,
5819
+ rangeMappings: mappings.rawRangeMappings
5647
5820
  };
5648
5821
  }
5649
5822
  generateMap(options) {
@@ -5658,7 +5831,7 @@ var Bundle$1 = class Bundle {
5658
5831
  indentStringCounts[indentStr] += 1;
5659
5832
  });
5660
5833
  return Object.keys(indentStringCounts).sort((a, b) => {
5661
- return indentStringCounts[a] - indentStringCounts[b];
5834
+ return indentStringCounts[b] - indentStringCounts[a];
5662
5835
  })[0] || " ";
5663
5836
  }
5664
5837
  indent(indentStr) {
@@ -5666,6 +5839,7 @@ var Bundle$1 = class Bundle {
5666
5839
  if (indentStr === "") return this;
5667
5840
  let trailingNewline = !this.intro || this.intro.slice(-1) === "\n";
5668
5841
  this.sources.forEach((source, i) => {
5842
+ /* v8 ignore next -- addSource always normalizes source.separator */
5669
5843
  const separator = source.separator !== void 0 ? source.separator : this.separator;
5670
5844
  const indentStart = trailingNewline || i > 0 && /\r?\n$/.test(separator);
5671
5845
  source.content.indent(indentStr, {
@@ -5685,6 +5859,7 @@ var Bundle$1 = class Bundle {
5685
5859
  }
5686
5860
  toString() {
5687
5861
  const body = this.sources.map((source, i) => {
5862
+ /* v8 ignore next -- addSource always normalizes source.separator */
5688
5863
  const separator = source.separator !== void 0 ? source.separator : this.separator;
5689
5864
  return (i > 0 ? separator : "") + source.content.toString();
5690
5865
  }).join("");
@@ -5693,6 +5868,7 @@ var Bundle$1 = class Bundle {
5693
5868
  isEmpty() {
5694
5869
  if (this.intro.length && this.intro.trim()) return false;
5695
5870
  if (this.sources.some((source, i) => {
5871
+ /* v8 ignore next -- addSource always normalizes source.separator */
5696
5872
  const separator = source.separator !== void 0 ? source.separator : this.separator;
5697
5873
  return i > 0 && separator.trim() !== "" || !source.content.isEmpty();
5698
5874
  })) return false;
@@ -5700,8 +5876,9 @@ var Bundle$1 = class Bundle {
5700
5876
  }
5701
5877
  length() {
5702
5878
  return this.sources.reduce((length, source, i) => {
5879
+ /* v8 ignore next -- addSource always normalizes source.separator */
5703
5880
  const separator = source.separator !== void 0 ? source.separator : this.separator;
5704
- return length + (i > 0 ? separator.length : 0) + source.content.length();
5881
+ return length + (i > 0 ? separator.length : 0) + source.content.toString().length;
5705
5882
  }, this.intro.length);
5706
5883
  }
5707
5884
  trimLines() {
@@ -5713,27 +5890,27 @@ var Bundle$1 = class Bundle {
5713
5890
  trimStart(charType) {
5714
5891
  const rx = new RegExp(`^${charType || "\\s"}+`);
5715
5892
  this.intro = this.intro.replace(rx, "");
5716
- if (!this.intro) {
5717
- let source;
5718
- let i = 0;
5719
- do {
5720
- source = this.sources[i++];
5721
- if (!source) break;
5722
- } while (!source.content.trimStartAborted(charType));
5893
+ if (!this.intro) for (let i = 0; i < this.sources.length; i += 1) {
5894
+ const source = this.sources[i];
5895
+ if (i > 0) {
5896
+ source.separator = (source.separator !== void 0 ? source.separator : this.separator).replace(rx, "");
5897
+ if (source.separator) break;
5898
+ }
5899
+ if (source.content.trimStartAborted(charType)) break;
5723
5900
  }
5724
5901
  return this;
5725
5902
  }
5726
5903
  trimEnd(charType) {
5727
5904
  const rx = new RegExp(`${charType || "\\s"}+$`);
5728
- let source;
5729
- let i = this.sources.length - 1;
5730
- do {
5731
- source = this.sources[i--];
5732
- if (!source) {
5733
- this.intro = this.intro.replace(rx, "");
5734
- break;
5905
+ for (let i = this.sources.length - 1; i >= 0; i -= 1) {
5906
+ const source = this.sources[i];
5907
+ if (source.content.trimEndAborted(charType)) return this;
5908
+ if (i > 0) {
5909
+ source.separator = (source.separator !== void 0 ? source.separator : this.separator).replace(rx, "");
5910
+ if (source.separator) return this;
5735
5911
  }
5736
- } while (!source.content.trimEndAborted(charType));
5912
+ }
5913
+ this.intro = this.intro.replace(rx, "");
5737
5914
  return this;
5738
5915
  }
5739
5916
  };
@@ -5784,6 +5961,14 @@ function findLastWhiteSpaceReverse(code, start, end) {
5784
5961
  }
5785
5962
  }
5786
5963
  }
5964
+ // A CRLF pair is one line break and must be removed as one. Removing only the
5965
+ // LF leaves the CR, which is still a line terminator, so ASI fires anyway and
5966
+ // the operand after a `return` or `throw` becomes dead code.
5967
+ function getLineBreakStart(code, lineBreakPos) {
5968
+ return lineBreakPos > 0 && code.charCodeAt(lineBreakPos - 1) === 13 /*"\r"*/
5969
+ ? lineBreakPos - 1
5970
+ : lineBreakPos;
5971
+ }
5787
5972
  // This assumes "code" only contains white-space and comments
5788
5973
  // Returns position of line-comment if applicable
5789
5974
  function findFirstLineBreakOutsideComment(code) {
@@ -5792,7 +5977,7 @@ function findFirstLineBreakOutsideComment(code) {
5792
5977
  while (true) {
5793
5978
  start = code.indexOf('/', start);
5794
5979
  if (start === -1 || start > lineBreakPos)
5795
- return [lineBreakPos, lineBreakPos + 1];
5980
+ return [getLineBreakStart(code, lineBreakPos), lineBreakPos + 1];
5796
5981
  // With our assumption, '/' always starts a comment. Determine comment type:
5797
5982
  charCodeAfterSlash = code.charCodeAt(start + 1);
5798
5983
  if (charCodeAfterSlash === 47 /*"/"*/)