@rollup/wasm-node 4.66.0 → 4.67.1

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.66.0
4
- Wed, 28 Oct 2026 13:27:47 GMT - commit 4de8104f55fe5c0df06aab54c1f9f2967dbe66ac
3
+ Rollup.js v4.67.1
4
+ Fri, 30 Oct 2026 16:27:29 GMT - commit 6ec9d9b1f7d09978bdcc0df9f0275ce79c018ada
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.66.0";
45
+ var version = "4.67.1";
46
46
  const package_ = {
47
47
  version: version};
48
48
 
@@ -4422,6 +4422,17 @@ var BitSet = class BitSet {
4422
4422
  has(n) {
4423
4423
  return !!(this.bits[n >> 5] & 1 << (n & 31));
4424
4424
  }
4425
+ forEach(fn) {
4426
+ const bits = this.bits;
4427
+ for (let w = 0; w < bits.length; w++) {
4428
+ let word = bits[w];
4429
+ while (word) {
4430
+ const lowest = word & -word;
4431
+ fn((w << 5) + 31 - Math.clz32(lowest));
4432
+ word ^= lowest;
4433
+ }
4434
+ }
4435
+ }
4425
4436
  };
4426
4437
  //#endregion
4427
4438
  //#region src/Chunk.ts
@@ -4435,6 +4446,8 @@ var Chunk$1 = class Chunk {
4435
4446
  this.content = content;
4436
4447
  this.storeName = false;
4437
4448
  this.edited = false;
4449
+ this.replacesUntil = -1;
4450
+ this.replacedFrom = -1;
4438
4451
  this.previous = null;
4439
4452
  this.next = null;
4440
4453
  }
@@ -4451,6 +4464,8 @@ var Chunk$1 = class Chunk {
4451
4464
  chunk.content = this.content;
4452
4465
  chunk.storeName = this.storeName;
4453
4466
  chunk.edited = this.edited;
4467
+ chunk.replacesUntil = this.replacesUntil;
4468
+ chunk.replacedFrom = this.replacedFrom;
4454
4469
  return chunk;
4455
4470
  }
4456
4471
  contains(index) {
@@ -4491,6 +4506,8 @@ var Chunk$1 = class Chunk {
4491
4506
  reset() {
4492
4507
  this.intro = "";
4493
4508
  this.outro = "";
4509
+ this.replacesUntil = -1;
4510
+ this.replacedFrom = -1;
4494
4511
  if (this.edited) {
4495
4512
  this.content = this.original;
4496
4513
  this.storeName = false;
@@ -4508,7 +4525,7 @@ var Chunk$1 = class Chunk {
4508
4525
  this.end = index;
4509
4526
  if (this.edited) {
4510
4527
  newChunk.edit("", false, true);
4511
- this.content = "";
4528
+ newChunk.replacedFrom = this.replacedFrom;
4512
4529
  } else this.content = originalBefore;
4513
4530
  newChunk.next = this.next;
4514
4531
  if (newChunk.next) newChunk.next.previous = newChunk;
@@ -4772,8 +4789,8 @@ var Mappings = class {
4772
4789
  this.generatedCodeColumn = 0;
4773
4790
  this.raw = [];
4774
4791
  this.rawSegments = this.raw[this.generatedCodeLine] = [];
4775
- this.rawRangeMappings = [];
4776
- this.rawRangeMappingsIndices = this.rawRangeMappings[this.generatedCodeLine] = [];
4792
+ this.rawRangeMappingsIndices = [];
4793
+ this.rawRangeMappings = hires === "experimental-range" ? [this.rawRangeMappingsIndices] : void 0;
4777
4794
  this.encoder = encoder;
4778
4795
  }
4779
4796
  nextLine() {
@@ -4786,7 +4803,28 @@ var Mappings = class {
4786
4803
  this.generatedCodeLine += 1;
4787
4804
  }
4788
4805
  this.generatedCodeColumn = 0;
4789
- this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
4806
+ if (this.rawRangeMappings) this.rawRangeMappings[this.generatedCodeLine] = this.rawRangeMappingsIndices = [];
4807
+ }
4808
+ /**
4809
+ * Emits the mappings for one MagicString: its intro, every chunk (with the
4810
+ * chunk's own intro/outro) and its outro. `sourceIndex === -1` means the
4811
+ * string has no source of its own, so its content only advances the
4812
+ * generated position without mapping anything.
4813
+ */
4814
+ addMagicString(magicString, sourceIndex, nameIndex) {
4815
+ const { original } = magicString;
4816
+ const locate = getLocator(original);
4817
+ if (magicString.intro) this.advance(magicString.intro);
4818
+ magicString.firstChunk.eachNext((chunk) => {
4819
+ if (chunk.intro.length) this.advance(chunk.intro);
4820
+ if (sourceIndex === -1) this.advance(chunk.content);
4821
+ else if (chunk.edited) {
4822
+ const name = chunk.storeName ? nameIndex.get(original.slice(chunk.start, chunk.replacesUntil)) : void 0;
4823
+ this.addEdit(sourceIndex, chunk.content, locate(chunk.start), name ?? -1);
4824
+ } else this.addUneditedChunk(sourceIndex, chunk, original, locate(chunk.start), magicString.sourcemapLocations);
4825
+ if (chunk.outro.length) this.advance(chunk.outro);
4826
+ });
4827
+ if (magicString.outro) this.advance(magicString.outro);
4790
4828
  }
4791
4829
  addEdit(sourceIndex, content, loc, nameIndex) {
4792
4830
  if (content.length) {
@@ -5001,6 +5039,9 @@ function expandReplacement(replacement, matched, position, str, captures, namedC
5001
5039
  return result;
5002
5040
  }
5003
5041
  var MagicString = class MagicString {
5042
+ /**
5043
+ * Wraps `string` for editing; every index passed to the editing methods refers to this original string.
5044
+ */
5004
5045
  constructor(string, options = {}) {
5005
5046
  const chunk = new Chunk$1(0, string.length, string);
5006
5047
  Object.defineProperties(this, {
@@ -5050,7 +5091,7 @@ var MagicString = class MagicString {
5050
5091
  },
5051
5092
  storedNames: {
5052
5093
  writable: true,
5053
- value: {}
5094
+ value: /* @__PURE__ */ new Set()
5054
5095
  },
5055
5096
  indentStr: {
5056
5097
  writable: true,
@@ -5090,7 +5131,8 @@ var MagicString = class MagicString {
5090
5131
  * See also `s.prependLeft(...)`.
5091
5132
  */
5092
5133
  appendLeft(index, content) {
5093
- index = index + this.offset;
5134
+ index = this._resolveIndex(index);
5135
+ if (index < 0 || index > this.original.length) throw new MagicStringError(`index ${index} is out of bounds`);
5094
5136
  if (typeof content !== "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
5095
5137
  this._split(index);
5096
5138
  const chunk = this.byEnd.get(index);
@@ -5104,7 +5146,8 @@ var MagicString = class MagicString {
5104
5146
  * See also `s.prependRight(...)`.
5105
5147
  */
5106
5148
  appendRight(index, content) {
5107
- index = index + this.offset;
5149
+ index = this._resolveIndex(index);
5150
+ if (index < 0 || index > this.original.length) throw new MagicStringError(`index ${index} is out of bounds`);
5108
5151
  if (typeof content !== "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
5109
5152
  this._split(index);
5110
5153
  const chunk = this.byStart.get(index);
@@ -5113,7 +5156,10 @@ var MagicString = class MagicString {
5113
5156
  return this;
5114
5157
  }
5115
5158
  /**
5116
- * Does what you'd expect.
5159
+ * Returns an independent copy: the chunk list, string-level intro/outro,
5160
+ * sourcemap locations, stored names, indent exclusion ranges, `offset`,
5161
+ * `filename` and `ignoreList` are all copied; later edits to either string
5162
+ * do not affect the other.
5117
5163
  */
5118
5164
  clone() {
5119
5165
  const cloned = new MagicString(this.original, {
@@ -5138,7 +5184,7 @@ var MagicString = class MagicString {
5138
5184
  cloned.lastChunk = clonedChunk;
5139
5185
  if (this.indentExclusionRanges) cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
5140
5186
  cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
5141
- cloned.storedNames = { ...this.storedNames };
5187
+ cloned.storedNames = new Set(this.storedNames);
5142
5188
  cloned.intro = this.intro;
5143
5189
  cloned.outro = this.outro;
5144
5190
  cloned.hasMovedChunks = this.hasMovedChunks;
@@ -5174,18 +5220,8 @@ var MagicString = class MagicString {
5174
5220
  }
5175
5221
  /** @internal */
5176
5222
  _generateMappings(mappings) {
5177
- const sourceIndex = 0;
5178
- const names = Object.keys(this.storedNames);
5179
- const locate = getLocator(this.original);
5180
- if (this.intro) mappings.advance(this.intro);
5181
- this.firstChunk.eachNext((chunk) => {
5182
- const loc = locate(chunk.start);
5183
- if (chunk.intro.length) mappings.advance(chunk.intro);
5184
- if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
5185
- else mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
5186
- if (chunk.outro.length) mappings.advance(chunk.outro);
5187
- });
5188
- if (this.outro) mappings.advance(this.outro);
5223
+ const names = [...this.storedNames];
5224
+ mappings.addMagicString(this, 0, new Map(names.map((name, i) => [name, i])));
5189
5225
  return names;
5190
5226
  }
5191
5227
  /** @internal */
@@ -5207,9 +5243,13 @@ var MagicString = class MagicString {
5207
5243
  this._ensureindentStr();
5208
5244
  return this.indentStr;
5209
5245
  }
5246
+ /**
5247
+ * Returns the indentation string guessed from the original content, falling back to a single tab character.
5248
+ * This is the value `s.indent()` uses when no prefix is supplied.
5249
+ */
5210
5250
  getIndentString() {
5211
5251
  this._ensureindentStr();
5212
- return this.indentStr === null ? " " : this.indentStr;
5252
+ return this.indentStr ?? " ";
5213
5253
  }
5214
5254
  indent(indentStr, options) {
5215
5255
  const pattern = /^[^\r\n]/gm;
@@ -5224,9 +5264,9 @@ var MagicString = class MagicString {
5224
5264
  if (indentStr === "") return this;
5225
5265
  const resolvedIndentStr = indentStr;
5226
5266
  options = options || {};
5227
- const isExcluded = {};
5267
+ const isExcluded = new BitSet();
5228
5268
  if (options.exclude) (typeof options.exclude[0] === "number" ? [options.exclude] : options.exclude).forEach((exclusion) => {
5229
- for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded[i] = true;
5269
+ for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded.add(i);
5230
5270
  });
5231
5271
  let shouldIndentNextCharacter = options.indentStart !== false;
5232
5272
  const indentPiece = (str) => {
@@ -5249,13 +5289,14 @@ var MagicString = class MagicString {
5249
5289
  };
5250
5290
  while (chunk) {
5251
5291
  const end = chunk.end;
5252
- if (!isExcluded[chunk.start]) chunk.intro = indentPiece(chunk.intro);
5292
+ if (!isExcluded.has(chunk.start)) chunk.intro = indentPiece(chunk.intro);
5253
5293
  if (chunk.edited) {
5254
- if (!isExcluded[charIndex]) chunk.content = indentPiece(chunk.content);
5294
+ if (!isExcluded.has(chunk.start)) chunk.content = indentPiece(chunk.content);
5295
+ else if (chunk.content) shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
5255
5296
  } else if (options.exclude) {
5256
5297
  charIndex = chunk.start;
5257
5298
  while (charIndex < end) {
5258
- if (!isExcluded[charIndex]) {
5299
+ if (!isExcluded.has(charIndex)) {
5259
5300
  const char = this.original.charCodeAt(charIndex);
5260
5301
  if (char === NEWLINE_CHAR) shouldIndentNextCharacter = true;
5261
5302
  else if (char !== CR_CHAR && shouldIndentNextCharacter) indentAt(charIndex);
@@ -5281,7 +5322,7 @@ var MagicString = class MagicString {
5281
5322
  charIndex += 1;
5282
5323
  }
5283
5324
  }
5284
- if (!isExcluded[chunk.end - 1]) chunk.outro = indentPiece(chunk.outro);
5325
+ if (!isExcluded.has(chunk.end - 1)) chunk.outro = indentPiece(chunk.outro);
5285
5326
  charIndex = chunk.end;
5286
5327
  chunk = chunk.next;
5287
5328
  }
@@ -5318,16 +5359,19 @@ var MagicString = class MagicString {
5318
5359
  * mirroring the `appendLeft`/`appendRight` distinction.
5319
5360
  */
5320
5361
  move(start, end, index, affinity = "right") {
5321
- start = start + this.offset;
5322
- end = end + this.offset;
5323
- index = index + this.offset;
5362
+ start = this._resolveIndex(start);
5363
+ end = this._resolveIndex(end);
5364
+ index = this._resolveIndex(index);
5324
5365
  if (start === end) return this;
5366
+ if (start < 0 || end > this.original.length || index < 0 || index > this.original.length) throw new MagicStringError(`range ${start}–${end} is out of bounds`);
5367
+ if (start > end) throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`);
5325
5368
  if (index >= start && index <= end) throw new MagicStringError("cannot move a selection inside itself");
5326
5369
  this._split(start);
5327
5370
  this._split(end);
5328
5371
  this._split(index);
5329
5372
  const first = this.byStart.get(start);
5330
5373
  const last = this.byEnd.get(end);
5374
+ if (!first || !last) throw new MagicStringError(`range ${start}–${end} is out of bounds`);
5331
5375
  if (this.hasMovedChunks) {
5332
5376
  let cursor = first;
5333
5377
  while (cursor !== last) {
@@ -5362,9 +5406,9 @@ var MagicString = class MagicString {
5362
5406
  if (oldRight) oldRight.previous = oldLeft;
5363
5407
  if (newLeft) newLeft.next = first;
5364
5408
  if (newRight) newRight.previous = last;
5365
- if (!first.previous) this.firstChunk = last.next;
5366
- if (!last.next) {
5367
- this.lastChunk = first.previous;
5409
+ if (!oldLeft) this.firstChunk = oldRight;
5410
+ if (!oldRight) {
5411
+ this.lastChunk = oldLeft;
5368
5412
  this.lastChunk.next = null;
5369
5413
  }
5370
5414
  first.previous = newLeft;
@@ -5385,6 +5429,16 @@ var MagicString = class MagicString {
5385
5429
  * It may be preferred to use `s.update(...)` instead if you wish to avoid overwriting the appended/prepended content.
5386
5430
  */
5387
5431
  overwrite(start, end, content, options) {
5432
+ if (options === true) {
5433
+ if (!warned.storeName) {
5434
+ console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string");
5435
+ warned.storeName = true;
5436
+ }
5437
+ return this.update(start, end, content, {
5438
+ storeName: true,
5439
+ overwrite: true
5440
+ });
5441
+ }
5388
5442
  const optionObject = typeof options === "object" && options ? options : {};
5389
5443
  return this.update(start, end, content, {
5390
5444
  ...optionObject,
@@ -5399,13 +5453,9 @@ var MagicString = class MagicString {
5399
5453
  * the content is overwritten, or anything that was appended/prepended to the range as well.
5400
5454
  */
5401
5455
  update(start, end, content, options) {
5402
- start = start + this.offset;
5403
- end = end + this.offset;
5456
+ start = this._resolveIndex(start);
5457
+ end = this._resolveIndex(end);
5404
5458
  if (typeof content !== "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
5405
- if (this.original.length !== 0) {
5406
- if (start < 0) start = Math.max(0, start + this.original.length);
5407
- if (end < 0) end = Math.max(0, end + this.original.length);
5408
- }
5409
5459
  if (start < 0) throw new MagicStringError(`start ${start} is out of bounds`);
5410
5460
  if (end > this.original.length) throw new MagicStringError(`end ${end} is out of bounds`);
5411
5461
  if (start === end) throw new MagicStringError(`cannot overwrite a zero-length range at ${start}, use appendLeft() or prependRight()`);
@@ -5422,30 +5472,21 @@ var MagicString = class MagicString {
5422
5472
  const optionObject = typeof options === "object" && options ? options : {};
5423
5473
  const storeName = optionObject.storeName || false;
5424
5474
  const overwrite = optionObject.overwrite || false;
5425
- if (storeName) {
5426
- const original = this.original.slice(start, end);
5427
- Object.defineProperty(this.storedNames, original, {
5428
- writable: true,
5429
- value: true,
5430
- enumerable: true
5431
- });
5432
- }
5475
+ if (storeName) this.storedNames.add(this.original.slice(start, end));
5433
5476
  const first = this.byStart.get(start);
5434
- const last = this.byEnd.get(end);
5435
- /* v8 ignore else -- unreachable: a valid start/end always yields a `first` chunk */
5436
- if (first) {
5437
- let chunk = first;
5438
- while (chunk !== last) {
5439
- if (chunk.next !== this.byStart.get(chunk.end)) throw new MagicStringError("cannot overwrite across a split point");
5440
- chunk = chunk.next;
5441
- chunk.edit("", false, !overwrite);
5442
- }
5443
- first.edit(content, storeName, !overwrite);
5444
- } else {
5445
- const newChunk = new Chunk$1(start, end, "").edit(content, storeName);
5446
- last.next = newChunk;
5447
- newChunk.previous = last;
5477
+ for (let chunk = first; chunk.end < end;) {
5478
+ const next = chunk.next;
5479
+ if (next === null || next !== this.byStart.get(chunk.end)) throw new MagicStringError("cannot overwrite across a split point");
5480
+ chunk = next;
5481
+ }
5482
+ for (let chunk = first.next; chunk !== null && chunk.start < end; chunk = chunk.next) {
5483
+ chunk.edit("", false, !overwrite);
5484
+ chunk.replacesUntil = -1;
5485
+ chunk.replacedFrom = start;
5448
5486
  }
5487
+ first.edit(content, storeName, !overwrite);
5488
+ first.replacesUntil = end;
5489
+ first.replacedFrom = -1;
5449
5490
  return this;
5450
5491
  }
5451
5492
  /**
@@ -5460,7 +5501,8 @@ var MagicString = class MagicString {
5460
5501
  * Same as `s.appendLeft(...)`, except that the inserted content will go *before* any previous appends or prepends at index
5461
5502
  */
5462
5503
  prependLeft(index, content) {
5463
- index = index + this.offset;
5504
+ index = this._resolveIndex(index);
5505
+ if (index < 0 || index > this.original.length) throw new MagicStringError(`index ${index} is out of bounds`);
5464
5506
  if (typeof content !== "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
5465
5507
  this._split(index);
5466
5508
  const chunk = this.byEnd.get(index);
@@ -5472,7 +5514,8 @@ var MagicString = class MagicString {
5472
5514
  * Same as `s.appendRight(...)`, except that the inserted content will go *before* any previous appends or prepends at `index`
5473
5515
  */
5474
5516
  prependRight(index, content) {
5475
- index = index + this.offset;
5517
+ index = this._resolveIndex(index);
5518
+ if (index < 0 || index > this.original.length) throw new MagicStringError(`index ${index} is out of bounds`);
5476
5519
  if (typeof content !== "string") throw new MagicStringError(`content must be a string, got ${typeof content}`);
5477
5520
  this._split(index);
5478
5521
  const chunk = this.byStart.get(index);
@@ -5488,12 +5531,8 @@ var MagicString = class MagicString {
5488
5531
  * Repeated removals and removals with partially overlapping ranges are allowed.
5489
5532
  */
5490
5533
  remove(start, end) {
5491
- start = start + this.offset;
5492
- end = end + this.offset;
5493
- if (this.original.length !== 0) {
5494
- if (start < 0) start = Math.max(0, start + this.original.length);
5495
- if (end < 0) end = Math.max(0, end + this.original.length);
5496
- }
5534
+ start = this._resolveIndex(start);
5535
+ end = this._resolveIndex(end);
5497
5536
  if (start === end) return this;
5498
5537
  if (start < 0 || end > this.original.length) throw new MagicStringError(`range ${start}–${end} is out of bounds`);
5499
5538
  if (start > end) throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`);
@@ -5504,7 +5543,9 @@ var MagicString = class MagicString {
5504
5543
  if (chunk.start > start) chunk.intro = "";
5505
5544
  if (chunk.end < end) chunk.outro = "";
5506
5545
  chunk.edit("", false, true);
5507
- chunk = end > chunk.end ? this.byStart.get(chunk.end) : null;
5546
+ chunk.replacesUntil = -1;
5547
+ chunk.replacedFrom = -1;
5548
+ chunk = end > chunk.end ? this.byStart.get(chunk.end) : void 0;
5508
5549
  }
5509
5550
  return this;
5510
5551
  }
@@ -5512,12 +5553,8 @@ var MagicString = class MagicString {
5512
5553
  * Reset the modified characters from `start` to `end` (of the original string, **not** the generated string).
5513
5554
  */
5514
5555
  reset(start, end) {
5515
- start = start + this.offset;
5516
- end = end + this.offset;
5517
- if (this.original.length !== 0) {
5518
- if (start < 0) start = Math.max(0, start + this.original.length);
5519
- if (end < 0) end = Math.max(0, end + this.original.length);
5520
- }
5556
+ start = this._resolveIndex(start);
5557
+ end = this._resolveIndex(end);
5521
5558
  if (start === end) return this;
5522
5559
  if (start < 0 || end > this.original.length) throw new MagicStringError(`range ${start}–${end} is out of bounds`);
5523
5560
  if (start > end) throw new MagicStringError(`end must be greater than start (start: ${start}, end: ${end})`);
@@ -5526,10 +5563,13 @@ var MagicString = class MagicString {
5526
5563
  let chunk = this.byStart.get(start);
5527
5564
  while (chunk) {
5528
5565
  chunk.reset();
5529
- chunk = end > chunk.end ? this.byStart.get(chunk.end) : null;
5566
+ chunk = end > chunk.end ? this.byStart.get(chunk.end) : void 0;
5530
5567
  }
5531
5568
  return this;
5532
5569
  }
5570
+ /**
5571
+ * Returns the last character of the generated string, or `''` if it is empty.
5572
+ */
5533
5573
  lastChar() {
5534
5574
  if (this.outro.length) return this.outro[this.outro.length - 1];
5535
5575
  let chunk = this.lastChunk;
@@ -5542,49 +5582,57 @@ var MagicString = class MagicString {
5542
5582
  if (this.intro.length) return this.intro[this.intro.length - 1];
5543
5583
  return "";
5544
5584
  }
5585
+ /**
5586
+ * Returns everything after the last newline in the generated string, or the whole string if there is no newline.
5587
+ */
5545
5588
  lastLine() {
5546
5589
  let lineIndex = this.outro.lastIndexOf(n);
5547
- if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
5590
+ if (lineIndex !== -1) return this.outro.slice(lineIndex + 1);
5548
5591
  let lineStr = this.outro;
5549
5592
  let chunk = this.lastChunk;
5550
5593
  while (chunk) {
5551
5594
  if (chunk.outro.length > 0) {
5552
5595
  lineIndex = chunk.outro.lastIndexOf(n);
5553
- if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
5596
+ if (lineIndex !== -1) return chunk.outro.slice(lineIndex + 1) + lineStr;
5554
5597
  lineStr = chunk.outro + lineStr;
5555
5598
  }
5556
5599
  if (chunk.content.length > 0) {
5557
5600
  lineIndex = chunk.content.lastIndexOf(n);
5558
- if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
5601
+ if (lineIndex !== -1) return chunk.content.slice(lineIndex + 1) + lineStr;
5559
5602
  lineStr = chunk.content + lineStr;
5560
5603
  }
5561
5604
  if (chunk.intro.length > 0) {
5562
5605
  lineIndex = chunk.intro.lastIndexOf(n);
5563
- if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
5606
+ if (lineIndex !== -1) return chunk.intro.slice(lineIndex + 1) + lineStr;
5564
5607
  lineStr = chunk.intro + lineStr;
5565
5608
  }
5566
5609
  chunk = chunk.previous;
5567
5610
  }
5568
5611
  lineIndex = this.intro.lastIndexOf(n);
5569
- if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
5612
+ if (lineIndex !== -1) return this.intro.slice(lineIndex + 1) + lineStr;
5570
5613
  return this.intro + lineStr;
5571
5614
  }
5572
5615
  /**
5573
- * Returns the content of the generated string that corresponds to the slice between `start` and `end` of the original string.
5574
- * Throws error if the indices are for characters that were already removed.
5616
+ * Returns the content of the generated string that corresponds to the slice
5617
+ * between `start` and `end` of the original string, walking the generated
5618
+ * string from the chunk holding `start` to the chunk holding `end`. Throws
5619
+ * if either index falls inside replaced content. After `move()`, a range
5620
+ * whose end now comes before its start in the output yields `''`.
5575
5621
  */
5576
5622
  slice(start = 0, end = this.original.length - this.offset) {
5577
- start = start + this.offset;
5578
- end = end + this.offset;
5579
- if (this.original.length !== 0) {
5580
- if (start < 0) start = Math.max(0, start + this.original.length);
5581
- if (end < 0) end = Math.max(0, end + this.original.length);
5582
- }
5623
+ start = this._resolveIndex(start);
5624
+ end = this._resolveIndex(end);
5583
5625
  let result = "";
5584
- let chunk = this.firstChunk;
5585
- while (chunk && (chunk.start > start || chunk.end <= start)) {
5586
- if (chunk.start < end && chunk.end >= end || end === 0 && chunk.start === 0) return result;
5587
- chunk = chunk.next;
5626
+ let chunk;
5627
+ if (this.hasMovedChunks) {
5628
+ chunk = this.firstChunk;
5629
+ while (chunk && (chunk.start > start || chunk.end <= start)) {
5630
+ if (chunk.start < end && chunk.end >= end || end === 0 && chunk.start === 0) return result;
5631
+ chunk = chunk.next;
5632
+ }
5633
+ } else {
5634
+ if (start >= end) return result;
5635
+ chunk = this._chunkAt(start);
5588
5636
  }
5589
5637
  if (chunk && chunk.edited && chunk.start !== start) throw new MagicStringError(`cannot use edited character ${start} as slice start anchor`);
5590
5638
  const startChunk = chunk;
@@ -5607,10 +5655,39 @@ var MagicString = class MagicString {
5607
5655
  */
5608
5656
  snip(start, end) {
5609
5657
  const clone = this.clone();
5610
- clone.remove(0, start);
5611
- clone.remove(end, clone.original.length);
5658
+ clone.remove(-clone.offset, start);
5659
+ clone.remove(end, clone.original.length - clone.offset);
5612
5660
  return clone;
5613
5661
  }
5662
+ /**
5663
+ * Applies `offset`, resolves a negative index from the end of `original` as
5664
+ * `update`/`remove` always have, and rejects anything that is not an integer.
5665
+ * Bounds are checked by the caller, because the methods report them differently.
5666
+ *
5667
+ * @internal
5668
+ */
5669
+ _resolveIndex(index) {
5670
+ const resolved = index + this.offset;
5671
+ if (!Number.isInteger(resolved)) throw new MagicStringError(`index must be an integer, got ${index}`);
5672
+ if (resolved < 0 && this.original.length !== 0) return Math.max(0, resolved + this.original.length);
5673
+ return resolved;
5674
+ }
5675
+ /**
5676
+ * The chunk whose original range holds `index` (`chunk.start <= index < chunk.end`),
5677
+ * or `undefined` when `index` is at or past the end. Searches from the last
5678
+ * visited chunk so that scans over nearby indices stay cheap.
5679
+ *
5680
+ * @internal
5681
+ */
5682
+ _chunkAt(index) {
5683
+ let chunk = this.byStart.get(index);
5684
+ if (chunk) return chunk;
5685
+ chunk = this.lastSearchedChunk;
5686
+ const searchForward = index >= chunk.end;
5687
+ while (chunk && !chunk.contains(index)) chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start);
5688
+ if (chunk) this.lastSearchedChunk = chunk;
5689
+ return chunk;
5690
+ }
5614
5691
  /** @internal */
5615
5692
  _split(index) {
5616
5693
  if (this.byStart.get(index) || this.byEnd.get(index)) return;
@@ -5663,6 +5740,11 @@ var MagicString = class MagicString {
5663
5740
  if (this.outro.length && this.outro.trim()) return false;
5664
5741
  return true;
5665
5742
  }
5743
+ /**
5744
+ * Returns the length of the generated string, counting only content attached to the original characters.
5745
+ * Content outside the string body (`s.prepend()`/`s.append()`, and inserts before the first or after the last
5746
+ * character) is not counted, so this can differ from `s.toString().length`.
5747
+ */
5666
5748
  length() {
5667
5749
  let chunk = this.firstChunk;
5668
5750
  let length = 0;
@@ -5694,10 +5776,11 @@ var MagicString = class MagicString {
5694
5776
  const end = chunk.end;
5695
5777
  const aborted = chunk.trimEnd(rx);
5696
5778
  if (chunk.end !== end) {
5697
- if (this.lastChunk === chunk) this.lastChunk = chunk.next;
5779
+ const next = chunk.next;
5780
+ if (this.lastChunk === chunk) this.lastChunk = next;
5698
5781
  this.byEnd.set(chunk.end, chunk);
5699
- this.byStart.set(chunk.next.start, chunk.next);
5700
- this.byEnd.set(chunk.next.end, chunk.next);
5782
+ this.byStart.set(next.start, next);
5783
+ this.byEnd.set(next.end, next);
5701
5784
  }
5702
5785
  if (aborted) return true;
5703
5786
  chunk = chunk.previous;
@@ -5722,10 +5805,11 @@ var MagicString = class MagicString {
5722
5805
  const end = chunk.end;
5723
5806
  const aborted = chunk.trimStart(rx);
5724
5807
  if (chunk.end !== end) {
5725
- if (chunk === this.lastChunk) this.lastChunk = chunk.next;
5808
+ const next = chunk.next;
5809
+ if (chunk === this.lastChunk) this.lastChunk = next;
5726
5810
  this.byEnd.set(chunk.end, chunk);
5727
- this.byStart.set(chunk.next.start, chunk.next);
5728
- this.byEnd.set(chunk.next.end, chunk.next);
5811
+ this.byStart.set(next.start, next);
5812
+ this.byEnd.set(next.end, next);
5729
5813
  }
5730
5814
  if (aborted) return true;
5731
5815
  chunk = chunk.next;
@@ -5767,30 +5851,29 @@ var MagicString = class MagicString {
5767
5851
  * @internal
5768
5852
  */
5769
5853
  _hasRemovedContent(start, end) {
5770
- let chunk = this.byStart.get(start);
5771
- if (!chunk) {
5772
- chunk = this.lastSearchedChunk;
5773
- const searchForward = start >= chunk.end;
5774
- while (chunk && !chunk.contains(start)) chunk = searchForward ? this.byStart.get(chunk.end) : this.byEnd.get(chunk.start);
5775
- if (chunk) this.lastSearchedChunk = chunk;
5854
+ const atBoundary = this.byStart.get(start);
5855
+ if (atBoundary && start === end) {
5856
+ const previous = this.byEnd.get(start);
5857
+ return !!previous && previous.content === "" && atBoundary.content === "";
5776
5858
  }
5859
+ let chunk = this._chunkAt(start);
5777
5860
  while (chunk && chunk.start < end) {
5778
- if (chunk.content === "") return true;
5861
+ if (chunk.content === "" && (chunk.replacedFrom < start || this.byStart.get(chunk.replacedFrom).replacesUntil < chunk.end)) return true;
5779
5862
  chunk = this.byStart.get(chunk.end);
5780
5863
  }
5781
5864
  return false;
5782
5865
  }
5783
5866
  /** @internal */
5784
5867
  _replaceRegexp(searchValue, replacement) {
5785
- function getReplacement(match, str) {
5786
- if (typeof replacement === "string") return expandReplacement(replacement, match[0], match.index, str, match.slice(1), match.groups);
5787
- 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);
5868
+ function getReplacement(match, index, str) {
5869
+ if (typeof replacement === "string") return expandReplacement(replacement, match[0], index, str, match.slice(1), match.groups);
5870
+ else return match.groups === void 0 ? replacement(match[0], ...match.slice(1), index, str) : replacement(match[0], ...match.slice(1), index, str, match.groups);
5788
5871
  }
5789
5872
  const replaceMatch = (match) => {
5790
5873
  /* v8 ignore next 2 -- `match.index` is always defined for matches from `matchAll` */
5791
5874
  if (match.index == null) return false;
5792
5875
  if (this._hasRemovedContent(match.index, match.index + match[0].length)) return false;
5793
- const replacement = getReplacement(match, this.original);
5876
+ const replacement = getReplacement(match, match.index, this.original);
5794
5877
  if (replacement === match[0]) return true;
5795
5878
  if (match[0].length === 0) this.appendRight(match.index - this.offset, replacement);
5796
5879
  else this.overwrite(match.index - this.offset, match.index + match[0].length - this.offset, replacement);
@@ -5872,7 +5955,7 @@ var Bundle$1 = class Bundle {
5872
5955
  this.separator = options.separator !== void 0 ? options.separator : "\n";
5873
5956
  this.sources = [];
5874
5957
  this.uniqueSources = [];
5875
- this.uniqueSourceIndexByFilename = {};
5958
+ this.uniqueSourceIndexByFilename = /* @__PURE__ */ new Map();
5876
5959
  }
5877
5960
  /**
5878
5961
  * Adds the specified source to the bundle, which can either be a `MagicString` object directly,
@@ -5891,30 +5974,31 @@ var Bundle$1 = class Bundle {
5891
5974
  separator: this.separator
5892
5975
  });
5893
5976
  if (!isObject(source) || !source.content) throw new MagicStringError("addSource() requires a `content` property that is a MagicString");
5894
- [
5895
- "filename",
5896
- "ignoreList",
5897
- "indentExclusionRanges",
5898
- "separator"
5899
- ].forEach((option) => {
5900
- if (!hasOwnProp.call(source, option)) source[option] = source.content[option];
5901
- });
5902
- if (source.separator === void 0) source.separator = this.separator;
5903
- if (source.filename) {
5904
- if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
5905
- this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
5977
+ const content = source.content;
5978
+ const record = {
5979
+ content,
5980
+ filename: hasOwnProp.call(source, "filename") ? source.filename : content.filename,
5981
+ ignoreList: hasOwnProp.call(source, "ignoreList") ? source.ignoreList : content.ignoreList,
5982
+ indentExclusionRanges: hasOwnProp.call(source, "indentExclusionRanges") ? source.indentExclusionRanges : content.indentExclusionRanges,
5983
+ separator: source.separator ?? this.separator
5984
+ };
5985
+ if (record.filename) {
5986
+ const index = this.uniqueSourceIndexByFilename.get(record.filename);
5987
+ if (index === void 0) {
5988
+ this.uniqueSourceIndexByFilename.set(record.filename, this.uniqueSources.length);
5906
5989
  this.uniqueSources.push({
5907
- filename: source.filename,
5908
- content: source.content.original
5990
+ filename: record.filename,
5991
+ content: content.original
5909
5992
  });
5910
- } else {
5911
- const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
5912
- if (source.content.original !== uniqueSource.content) throw new MagicStringError(`duplicate filename "${source.filename}" with different content, use unique filenames`);
5913
- }
5993
+ } else if (content.original !== this.uniqueSources[index].content) throw new MagicStringError(`duplicate filename "${record.filename}" with different content, use unique filenames`);
5914
5994
  }
5915
- this.sources.push(source);
5995
+ this.sources.push(record);
5916
5996
  return this;
5917
5997
  }
5998
+ /**
5999
+ * Appends `str` as a new source without a filename. Only `options.separator` is read, and it defaults to `''`
6000
+ * rather than to the bundle separator.
6001
+ */
5918
6002
  append(str, options) {
5919
6003
  this.addSource({
5920
6004
  content: new MagicString(str),
@@ -5922,6 +6006,10 @@ var Bundle$1 = class Bundle {
5922
6006
  });
5923
6007
  return this;
5924
6008
  }
6009
+ /**
6010
+ * Returns an independent copy of the bundle: every source's `MagicString` is cloned, so later edits to either
6011
+ * bundle do not affect the other.
6012
+ */
5925
6013
  clone() {
5926
6014
  const bundle = new Bundle({
5927
6015
  intro: this.intro,
@@ -5957,12 +6045,12 @@ var Bundle$1 = class Bundle {
5957
6045
  const byStart = /* @__PURE__ */ new Map();
5958
6046
  const byEnd = /* @__PURE__ */ new Map();
5959
6047
  let hasMovedChunks = false;
5960
- this.sources.forEach((source, i) => {
6048
+ for (const [i, source] of this.sources.entries()) {
5961
6049
  const magicString = source.content;
5962
- const separator = i > 0 ? source.separator !== void 0 ? source.separator : this.separator : "";
6050
+ const separator = i > 0 ? source.separator : "";
5963
6051
  if (magicString.original.length === 0) {
5964
6052
  pending += separator + magicString.toString();
5965
- return;
6053
+ continue;
5966
6054
  }
5967
6055
  pending += separator + magicString.intro;
5968
6056
  let sourceFirst = null;
@@ -5972,6 +6060,8 @@ var Bundle$1 = class Bundle {
5972
6060
  const chunk = originalChunk.clone();
5973
6061
  chunk.start += offset;
5974
6062
  chunk.end += offset;
6063
+ if (chunk.replacesUntil !== -1) chunk.replacesUntil += offset;
6064
+ if (chunk.replacedFrom !== -1) chunk.replacedFrom += offset;
5975
6065
  chunk.previous = previous;
5976
6066
  chunk.next = null;
5977
6067
  if (previous) previous.next = chunk;
@@ -5990,18 +6080,14 @@ var Bundle$1 = class Bundle {
5990
6080
  sourceFirst.previous = last;
5991
6081
  } else first = sourceFirst;
5992
6082
  last = sourceLast;
5993
- for (let index = 0; index < magicString.original.length; index += 1) if (magicString.sourcemapLocations.has(index)) combined.sourcemapLocations.add(index + offset);
5994
- Object.keys(magicString.storedNames).forEach((name) => {
5995
- Object.defineProperty(combined.storedNames, name, {
5996
- writable: true,
5997
- value: true,
5998
- enumerable: true
5999
- });
6083
+ magicString.sourcemapLocations.forEach((index) => {
6084
+ if (index < magicString.original.length) combined.sourcemapLocations.add(index + offset);
6000
6085
  });
6086
+ magicString.storedNames.forEach((name) => combined.storedNames.add(name));
6001
6087
  if (magicString.hasMovedChunks) hasMovedChunks = true;
6002
6088
  offset += magicString.original.length;
6003
- });
6004
- if (!first) {
6089
+ }
6090
+ if (!first || !last) {
6005
6091
  combined.intro = pending;
6006
6092
  return combined;
6007
6093
  }
@@ -6014,6 +6100,10 @@ var Bundle$1 = class Bundle {
6014
6100
  combined.hasMovedChunks = hasMovedChunks;
6015
6101
  return combined;
6016
6102
  }
6103
+ /**
6104
+ * Generates a sourcemap object with raw mappings in array form, rather than encoded as a string.
6105
+ * Takes the same options as `generateMap`.
6106
+ */
6017
6107
  generateDecodedMap(options = {}) {
6018
6108
  const mappings = new Mappings(options.hires);
6019
6109
  const { names, x_google_ignoreList } = this._generateMappings(mappings);
@@ -6023,6 +6113,10 @@ var Bundle$1 = class Bundle {
6023
6113
  rangeMappings: mappings.rawRangeMappings
6024
6114
  };
6025
6115
  }
6116
+ /**
6117
+ * Generates a version 3 sourcemap covering every source that has a `filename`.
6118
+ * Options are as per `MagicString#generateMap`, except that `includeContent` can also be a per-source function.
6119
+ */
6026
6120
  generateMap(options = {}) {
6027
6121
  const encoder = new MappingsEncoder();
6028
6122
  const mappings = new Mappings(options.hires, encoder);
@@ -6035,32 +6129,16 @@ var Bundle$1 = class Bundle {
6035
6129
  }
6036
6130
  /** @internal */
6037
6131
  _generateMappings(mappings) {
6038
- const names = [];
6039
6132
  let x_google_ignoreList;
6040
- this.sources.forEach((source) => {
6041
- Object.keys(source.content.storedNames).forEach((name) => {
6042
- if (!names.includes(name)) names.push(name);
6043
- });
6044
- });
6133
+ const storedNames = /* @__PURE__ */ new Set();
6134
+ this.sources.forEach((source) => source.content.storedNames.forEach((name) => storedNames.add(name)));
6135
+ const names = [...storedNames];
6136
+ const nameIndex = new Map(names.map((name, i) => [name, i]));
6045
6137
  if (this.intro) mappings.advance(this.intro);
6046
6138
  this.sources.forEach((source, i) => {
6047
- if (i > 0)
6048
- /* v8 ignore next -- addSource always normalizes source.separator */
6049
- mappings.advance(source.separator !== void 0 ? source.separator : this.separator);
6050
- const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
6051
- const magicString = source.content;
6052
- const locate = getLocator(magicString.original);
6053
- if (magicString.intro) mappings.advance(magicString.intro);
6054
- magicString.firstChunk.eachNext((chunk) => {
6055
- const loc = locate(chunk.start);
6056
- if (chunk.intro.length) mappings.advance(chunk.intro);
6057
- if (source.filename) {
6058
- if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
6059
- else mappings.addUneditedChunk(sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations);
6060
- } else mappings.advance(chunk.content);
6061
- if (chunk.outro.length) mappings.advance(chunk.outro);
6062
- });
6063
- if (magicString.outro) mappings.advance(magicString.outro);
6139
+ if (i > 0) mappings.advance(source.separator);
6140
+ const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename.get(source.filename) ?? -1 : -1;
6141
+ mappings.addMagicString(source.content, sourceIndex, nameIndex);
6064
6142
  if (source.ignoreList && sourceIndex !== -1) {
6065
6143
  if (x_google_ignoreList === void 0) x_google_ignoreList = [];
6066
6144
  x_google_ignoreList.push(sourceIndex);
@@ -6085,91 +6163,111 @@ var Bundle$1 = class Bundle {
6085
6163
  x_google_ignoreList
6086
6164
  };
6087
6165
  }
6166
+ /**
6167
+ * Returns the most common indent string among the sources, falling back to a tab.
6168
+ */
6088
6169
  getIndentString() {
6089
- const indentStringCounts = {};
6170
+ const indentStringCounts = /* @__PURE__ */ new Map();
6090
6171
  this.sources.forEach((source) => {
6091
6172
  const indentStr = source.content._getRawIndentString();
6092
- if (indentStr === null) return;
6093
- if (!indentStringCounts[indentStr]) indentStringCounts[indentStr] = 0;
6094
- indentStringCounts[indentStr] += 1;
6173
+ if (indentStr == null) return;
6174
+ indentStringCounts.set(indentStr, (indentStringCounts.get(indentStr) ?? 0) + 1);
6095
6175
  });
6096
- return Object.keys(indentStringCounts).sort((a, b) => {
6097
- return indentStringCounts[b] - indentStringCounts[a];
6098
- })[0] || " ";
6176
+ return [...indentStringCounts.entries()].sort(([, a], [, b]) => b - a)[0]?.[0] ?? " ";
6099
6177
  }
6178
+ /**
6179
+ * Prefixes each line of every source and of the intro with `indentStr`, guessed with `getIndentString()`
6180
+ * when not supplied. Each source's `indentExclusionRanges` are left unindented.
6181
+ */
6100
6182
  indent(indentStr) {
6101
6183
  if (!arguments.length) indentStr = this.getIndentString();
6102
6184
  if (indentStr === "") return this;
6103
6185
  let trailingNewline = !this.intro || this.intro.slice(-1) === "\n";
6104
6186
  this.sources.forEach((source, i) => {
6105
- /* v8 ignore next -- addSource always normalizes source.separator */
6106
- const separator = source.separator !== void 0 ? source.separator : this.separator;
6107
- const indentStart = trailingNewline || i > 0 && /\r?\n$/.test(separator);
6187
+ const indentStart = trailingNewline || i > 0 && /\r?\n$/.test(source.separator);
6108
6188
  source.content.indent(indentStr, {
6109
6189
  exclude: source.indentExclusionRanges,
6110
6190
  indentStart
6111
6191
  });
6112
6192
  trailingNewline = source.content.lastChar() === "\n";
6113
6193
  });
6114
- if (this.intro) this.intro = indentStr + this.intro.replace(/^[^\n]/gm, (match, index) => {
6194
+ if (this.intro) this.intro = indentStr + this.intro.replace(/^[^\r\n]/gm, (match, index) => {
6115
6195
  return index > 0 ? indentStr + match : match;
6116
6196
  });
6117
6197
  return this;
6118
6198
  }
6199
+ /**
6200
+ * Prepends `str` to the bundle's intro.
6201
+ */
6119
6202
  prepend(str) {
6120
6203
  this.intro = str + this.intro;
6121
6204
  return this;
6122
6205
  }
6206
+ /**
6207
+ * Returns the intro followed by every source's generated string, joined by their separators.
6208
+ */
6123
6209
  toString() {
6124
6210
  const body = this.sources.map((source, i) => {
6125
- /* v8 ignore next -- addSource always normalizes source.separator */
6126
- const separator = source.separator !== void 0 ? source.separator : this.separator;
6127
- return (i > 0 ? separator : "") + source.content.toString();
6211
+ return (i > 0 ? source.separator : "") + source.content.toString();
6128
6212
  }).join("");
6129
6213
  return this.intro + body;
6130
6214
  }
6215
+ /**
6216
+ * Returns true if the bundle's output is empty (disregarding white space).
6217
+ */
6131
6218
  isEmpty() {
6132
6219
  if (this.intro.length && this.intro.trim()) return false;
6133
6220
  if (this.sources.some((source, i) => {
6134
- /* v8 ignore next -- addSource always normalizes source.separator */
6135
- const separator = source.separator !== void 0 ? source.separator : this.separator;
6136
- return i > 0 && separator.trim() !== "" || !source.content.isEmpty();
6221
+ return i > 0 && source.separator.trim() !== "" || !source.content.isEmpty();
6137
6222
  })) return false;
6138
6223
  return true;
6139
6224
  }
6225
+ /**
6226
+ * Returns the length of the bundle's output; unlike `MagicString#length`, this equals `bundle.toString().length`.
6227
+ */
6140
6228
  length() {
6141
6229
  return this.sources.reduce((length, source, i) => {
6142
- /* v8 ignore next -- addSource always normalizes source.separator */
6143
- const separator = source.separator !== void 0 ? source.separator : this.separator;
6144
- return length + (i > 0 ? separator.length : 0) + source.content.toString().length;
6230
+ return length + (i > 0 ? source.separator.length : 0) + source.content.length() + source.content.intro.length + source.content.outro.length;
6145
6231
  }, this.intro.length);
6146
6232
  }
6233
+ /**
6234
+ * Removes empty lines from the start and end.
6235
+ */
6147
6236
  trimLines() {
6148
6237
  return this.trim("[\\r\\n]");
6149
6238
  }
6239
+ /**
6240
+ * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start and end.
6241
+ */
6150
6242
  trim(charType) {
6151
6243
  return this.trimStart(charType).trimEnd(charType);
6152
6244
  }
6245
+ /**
6246
+ * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the start.
6247
+ */
6153
6248
  trimStart(charType) {
6154
6249
  const rx = new RegExp(`^${charType || "\\s"}+`);
6155
6250
  this.intro = this.intro.replace(rx, "");
6156
6251
  if (!this.intro) for (let i = 0; i < this.sources.length; i += 1) {
6157
6252
  const source = this.sources[i];
6158
6253
  if (i > 0) {
6159
- source.separator = (source.separator !== void 0 ? source.separator : this.separator).replace(rx, "");
6254
+ source.separator = source.separator.replace(rx, "");
6160
6255
  if (source.separator) break;
6161
6256
  }
6162
6257
  if (source.content.trimStartAborted(charType)) break;
6163
6258
  }
6164
6259
  return this;
6165
6260
  }
6261
+ /**
6262
+ * Trims content matching `charType` (defaults to `\s`, i.e. whitespace) from the end.
6263
+ */
6166
6264
  trimEnd(charType) {
6167
6265
  const rx = new RegExp(`${charType || "\\s"}+$`);
6168
6266
  for (let i = this.sources.length - 1; i >= 0; i -= 1) {
6169
6267
  const source = this.sources[i];
6170
6268
  if (source.content.trimEndAborted(charType)) return this;
6171
6269
  if (i > 0) {
6172
- source.separator = (source.separator !== void 0 ? source.separator : this.separator).replace(rx, "");
6270
+ source.separator = source.separator.replace(rx, "");
6173
6271
  if (source.separator) return this;
6174
6272
  }
6175
6273
  }
@@ -13936,17 +14034,29 @@ function getMatcherString(id, resolutionBase) {
13936
14034
  }
13937
14035
  const createFilter = function createFilter(include, exclude, options) {
13938
14036
  const resolutionBase = options && options.resolve;
13939
- const getMatcher = (id) => id instanceof RegExp
13940
- ? id
13941
- : {
14037
+ const getMatcher = (id) => {
14038
+ if (id instanceof RegExp) {
14039
+ return id;
14040
+ }
14041
+ // Compiling a pattern costs far more than matching against it, so only recompile when the cwd it resolves against changes
14042
+ const compile = () => pm(getMatcherString(id, resolutionBase), { dot: true });
14043
+ // These patterns never resolve against the cwd, so there is no need to read or track it
14044
+ if (resolutionBase === false || require$$0.isAbsolute(id) || id.startsWith('**')) {
14045
+ return { test: compile() };
14046
+ }
14047
+ let compiledCwd = process.cwd();
14048
+ let fn = compile();
14049
+ return {
13942
14050
  test: (what) => {
13943
- // this refactor is a tad overly verbose but makes for easy debugging
13944
- const pattern = getMatcherString(id, resolutionBase);
13945
- const fn = pm(pattern, { dot: true });
13946
- const result = fn(what);
13947
- return result;
14051
+ const cwd = process.cwd();
14052
+ if (cwd !== compiledCwd) {
14053
+ compiledCwd = cwd;
14054
+ fn = compile();
14055
+ }
14056
+ return fn(what);
13948
14057
  }
13949
14058
  };
14059
+ };
13950
14060
  const includeMatchers = ensureArray(include).map(getMatcher);
13951
14061
  const excludeMatchers = ensureArray(exclude).map(getMatcher);
13952
14062
  if (!includeMatchers.length && !excludeMatchers.length)