@m2c2kit/build-helpers 0.3.28 → 0.3.30

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.
Files changed (2) hide show
  1. package/dist/index.js +1467 -150
  2. package/package.json +13 -13
package/dist/index.js CHANGED
@@ -5589,100 +5589,91 @@ const selectAll = getSelectorFunc((query, elems, options) => query === boolbaseE
5589
5589
  ? []
5590
5590
  : findAll(query, elems, options));
5591
5591
 
5592
- const comma = ','.charCodeAt(0);
5593
- const semicolon = ';'.charCodeAt(0);
5594
- const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
5595
- const intToChar = new Uint8Array(64); // 64 possible chars.
5596
- const charToInt = new Uint8Array(128); // z is 122 in ASCII
5592
+ // src/vlq.ts
5593
+ var comma = ",".charCodeAt(0);
5594
+ var semicolon = ";".charCodeAt(0);
5595
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
5596
+ var intToChar = new Uint8Array(64);
5597
+ var charToInt = new Uint8Array(128);
5597
5598
  for (let i = 0; i < chars.length; i++) {
5598
- const c = chars.charCodeAt(i);
5599
- intToChar[i] = c;
5600
- charToInt[c] = i;
5599
+ const c = chars.charCodeAt(i);
5600
+ intToChar[i] = c;
5601
+ charToInt[c] = i;
5601
5602
  }
5602
5603
  function encodeInteger(builder, num, relative) {
5603
- let delta = num - relative;
5604
- delta = delta < 0 ? (-delta << 1) | 1 : delta << 1;
5605
- do {
5606
- let clamped = delta & 0b011111;
5607
- delta >>>= 5;
5608
- if (delta > 0)
5609
- clamped |= 0b100000;
5610
- builder.write(intToChar[clamped]);
5611
- } while (delta > 0);
5612
- return num;
5613
- }
5614
-
5615
- const bufLength = 1024 * 16;
5616
- // Provide a fallback for older environments.
5617
- const td = typeof TextDecoder !== 'undefined'
5618
- ? /* #__PURE__ */ new TextDecoder()
5619
- : typeof Buffer !== 'undefined'
5620
- ? {
5621
- decode(buf) {
5622
- const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
5623
- return out.toString();
5624
- },
5625
- }
5626
- : {
5627
- decode(buf) {
5628
- let out = '';
5629
- for (let i = 0; i < buf.length; i++) {
5630
- out += String.fromCharCode(buf[i]);
5631
- }
5632
- return out;
5633
- },
5634
- };
5635
- class StringWriter {
5636
- constructor() {
5637
- this.pos = 0;
5638
- this.out = '';
5639
- this.buffer = new Uint8Array(bufLength);
5640
- }
5641
- write(v) {
5642
- const { buffer } = this;
5643
- buffer[this.pos++] = v;
5644
- if (this.pos === bufLength) {
5645
- this.out += td.decode(buffer);
5646
- this.pos = 0;
5647
- }
5604
+ let delta = num - relative;
5605
+ delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
5606
+ do {
5607
+ let clamped = delta & 31;
5608
+ delta >>>= 5;
5609
+ if (delta > 0) clamped |= 32;
5610
+ builder.write(intToChar[clamped]);
5611
+ } while (delta > 0);
5612
+ return num;
5613
+ }
5614
+
5615
+ // src/strings.ts
5616
+ var bufLength = 1024 * 16;
5617
+ var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? {
5618
+ decode(buf) {
5619
+ const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
5620
+ return out.toString();
5621
+ }
5622
+ } : {
5623
+ decode(buf) {
5624
+ let out = "";
5625
+ for (let i = 0; i < buf.length; i++) {
5626
+ out += String.fromCharCode(buf[i]);
5648
5627
  }
5649
- flush() {
5650
- const { buffer, out, pos } = this;
5651
- return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
5628
+ return out;
5629
+ }
5630
+ };
5631
+ var StringWriter = class {
5632
+ constructor() {
5633
+ this.pos = 0;
5634
+ this.out = "";
5635
+ this.buffer = new Uint8Array(bufLength);
5636
+ }
5637
+ write(v) {
5638
+ const { buffer } = this;
5639
+ buffer[this.pos++] = v;
5640
+ if (this.pos === bufLength) {
5641
+ this.out += td.decode(buffer);
5642
+ this.pos = 0;
5652
5643
  }
5653
- }
5644
+ }
5645
+ flush() {
5646
+ const { buffer, out, pos } = this;
5647
+ return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
5648
+ }
5649
+ };
5654
5650
  function encode(decoded) {
5655
- const writer = new StringWriter();
5656
- let sourcesIndex = 0;
5657
- let sourceLine = 0;
5658
- let sourceColumn = 0;
5659
- let namesIndex = 0;
5660
- for (let i = 0; i < decoded.length; i++) {
5661
- const line = decoded[i];
5662
- if (i > 0)
5663
- writer.write(semicolon);
5664
- if (line.length === 0)
5665
- continue;
5666
- let genColumn = 0;
5667
- for (let j = 0; j < line.length; j++) {
5668
- const segment = line[j];
5669
- if (j > 0)
5670
- writer.write(comma);
5671
- genColumn = encodeInteger(writer, segment[0], genColumn);
5672
- if (segment.length === 1)
5673
- continue;
5674
- sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
5675
- sourceLine = encodeInteger(writer, segment[2], sourceLine);
5676
- sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
5677
- if (segment.length === 4)
5678
- continue;
5679
- namesIndex = encodeInteger(writer, segment[4], namesIndex);
5680
- }
5651
+ const writer = new StringWriter();
5652
+ let sourcesIndex = 0;
5653
+ let sourceLine = 0;
5654
+ let sourceColumn = 0;
5655
+ let namesIndex = 0;
5656
+ for (let i = 0; i < decoded.length; i++) {
5657
+ const line = decoded[i];
5658
+ if (i > 0) writer.write(semicolon);
5659
+ if (line.length === 0) continue;
5660
+ let genColumn = 0;
5661
+ for (let j = 0; j < line.length; j++) {
5662
+ const segment = line[j];
5663
+ if (j > 0) writer.write(comma);
5664
+ genColumn = encodeInteger(writer, segment[0], genColumn);
5665
+ if (segment.length === 1) continue;
5666
+ sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
5667
+ sourceLine = encodeInteger(writer, segment[2], sourceLine);
5668
+ sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
5669
+ if (segment.length === 4) continue;
5670
+ namesIndex = encodeInteger(writer, segment[4], namesIndex);
5681
5671
  }
5682
- return writer.flush();
5672
+ }
5673
+ return writer.flush();
5683
5674
  }
5684
5675
 
5685
- class BitSet {
5676
+ let BitSet$1 = class BitSet {
5686
5677
  constructor(arg) {
5687
5678
  this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
5688
5679
  }
@@ -5694,9 +5685,9 @@ class BitSet {
5694
5685
  has(n) {
5695
5686
  return !!(this.bits[n >> 5] & (1 << (n & 31)));
5696
5687
  }
5697
- }
5688
+ };
5698
5689
 
5699
- class Chunk {
5690
+ let Chunk$1 = class Chunk {
5700
5691
  constructor(start, end, content) {
5701
5692
  this.start = start;
5702
5693
  this.end = end;
@@ -5873,9 +5864,9 @@ class Chunk {
5873
5864
  if (this.outro.length) return true;
5874
5865
  }
5875
5866
  }
5876
- }
5867
+ };
5877
5868
 
5878
- function getBtoa() {
5869
+ function getBtoa$1() {
5879
5870
  if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
5880
5871
  return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
5881
5872
  } else if (typeof Buffer === 'function') {
@@ -5887,9 +5878,9 @@ function getBtoa() {
5887
5878
  }
5888
5879
  }
5889
5880
 
5890
- const btoa = /*#__PURE__*/ getBtoa();
5881
+ const btoa$1 = /*#__PURE__*/ getBtoa$1();
5891
5882
 
5892
- class SourceMap {
5883
+ let SourceMap$1 = class SourceMap {
5893
5884
  constructor(properties) {
5894
5885
  this.version = 3;
5895
5886
  this.file = properties.file;
@@ -5910,11 +5901,11 @@ class SourceMap {
5910
5901
  }
5911
5902
 
5912
5903
  toUrl() {
5913
- return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
5904
+ return 'data:application/json;charset=utf-8;base64,' + btoa$1(this.toString());
5914
5905
  }
5915
- }
5906
+ };
5916
5907
 
5917
- function guessIndent(code) {
5908
+ function guessIndent$1(code) {
5918
5909
  const lines = code.split('\n');
5919
5910
 
5920
5911
  const tabbed = lines.filter((line) => /^\t+/.test(line));
@@ -5940,7 +5931,7 @@ function guessIndent(code) {
5940
5931
  return new Array(min + 1).join(' ');
5941
5932
  }
5942
5933
 
5943
- function getRelativePath(from, to) {
5934
+ function getRelativePath$1(from, to) {
5944
5935
  const fromParts = from.split(/[/\\]/);
5945
5936
  const toParts = to.split(/[/\\]/);
5946
5937
 
@@ -5959,13 +5950,13 @@ function getRelativePath(from, to) {
5959
5950
  return fromParts.concat(toParts).join('/');
5960
5951
  }
5961
5952
 
5962
- const toString = Object.prototype.toString;
5953
+ const toString$1 = Object.prototype.toString;
5963
5954
 
5964
- function isObject(thing) {
5965
- return toString.call(thing) === '[object Object]';
5955
+ function isObject$1(thing) {
5956
+ return toString$1.call(thing) === '[object Object]';
5966
5957
  }
5967
5958
 
5968
- function getLocator(source) {
5959
+ function getLocator$1(source) {
5969
5960
  const originalLines = source.split('\n');
5970
5961
  const lineOffsets = [];
5971
5962
 
@@ -5991,9 +5982,9 @@ function getLocator(source) {
5991
5982
  };
5992
5983
  }
5993
5984
 
5994
- const wordRegex = /\w/;
5985
+ const wordRegex$1 = /\w/;
5995
5986
 
5996
- class Mappings {
5987
+ let Mappings$1 = class Mappings {
5997
5988
  constructor(hires) {
5998
5989
  this.hires = hires;
5999
5990
  this.generatedCodeLine = 0;
@@ -6061,7 +6052,7 @@ class Mappings {
6061
6052
 
6062
6053
  if (this.hires === 'boundary') {
6063
6054
  // in hires "boundary", group segments per word boundary than per char
6064
- if (wordRegex.test(original[originalCharIndex])) {
6055
+ if (wordRegex$1.test(original[originalCharIndex])) {
6065
6056
  // for first char in the boundary found, start the boundary by pushing a segment
6066
6057
  if (!charInHiresBoundary) {
6067
6058
  this.rawSegments.push(segment);
@@ -6103,19 +6094,19 @@ class Mappings {
6103
6094
 
6104
6095
  this.generatedCodeColumn += lines[lines.length - 1].length;
6105
6096
  }
6106
- }
6097
+ };
6107
6098
 
6108
- const n = '\n';
6099
+ const n$1 = '\n';
6109
6100
 
6110
- const warned = {
6101
+ const warned$1 = {
6111
6102
  insertLeft: false,
6112
6103
  insertRight: false,
6113
6104
  storeName: false,
6114
6105
  };
6115
6106
 
6116
- class MagicString {
6107
+ let MagicString$1 = class MagicString {
6117
6108
  constructor(string, options = {}) {
6118
- const chunk = new Chunk(0, string.length, string);
6109
+ const chunk = new Chunk$1(0, string.length, string);
6119
6110
 
6120
6111
  Object.defineProperties(this, {
6121
6112
  original: { writable: true, value: string },
@@ -6128,7 +6119,7 @@ class MagicString {
6128
6119
  byEnd: { writable: true, value: {} },
6129
6120
  filename: { writable: true, value: options.filename },
6130
6121
  indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
6131
- sourcemapLocations: { writable: true, value: new BitSet() },
6122
+ sourcemapLocations: { writable: true, value: new BitSet$1() },
6132
6123
  storedNames: { writable: true, value: {} },
6133
6124
  indentStr: { writable: true, value: undefined },
6134
6125
  ignoreList: { writable: true, value: options.ignoreList },
@@ -6213,7 +6204,7 @@ class MagicString {
6213
6204
  cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
6214
6205
  }
6215
6206
 
6216
- cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
6207
+ cloned.sourcemapLocations = new BitSet$1(this.sourcemapLocations);
6217
6208
 
6218
6209
  cloned.intro = this.intro;
6219
6210
  cloned.outro = this.outro;
@@ -6226,9 +6217,9 @@ class MagicString {
6226
6217
 
6227
6218
  const sourceIndex = 0;
6228
6219
  const names = Object.keys(this.storedNames);
6229
- const mappings = new Mappings(options.hires);
6220
+ const mappings = new Mappings$1(options.hires);
6230
6221
 
6231
- const locate = getLocator(this.original);
6222
+ const locate = getLocator$1(this.original);
6232
6223
 
6233
6224
  if (this.intro) {
6234
6225
  mappings.advance(this.intro);
@@ -6253,10 +6244,14 @@ class MagicString {
6253
6244
  if (chunk.outro.length) mappings.advance(chunk.outro);
6254
6245
  });
6255
6246
 
6247
+ if (this.outro) {
6248
+ mappings.advance(this.outro);
6249
+ }
6250
+
6256
6251
  return {
6257
6252
  file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
6258
6253
  sources: [
6259
- options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
6254
+ options.source ? getRelativePath$1(options.file || '', options.source) : options.file || '',
6260
6255
  ],
6261
6256
  sourcesContent: options.includeContent ? [this.original] : undefined,
6262
6257
  names,
@@ -6266,12 +6261,12 @@ class MagicString {
6266
6261
  }
6267
6262
 
6268
6263
  generateMap(options) {
6269
- return new SourceMap(this.generateDecodedMap(options));
6264
+ return new SourceMap$1(this.generateDecodedMap(options));
6270
6265
  }
6271
6266
 
6272
6267
  _ensureindentStr() {
6273
6268
  if (this.indentStr === undefined) {
6274
- this.indentStr = guessIndent(this.original);
6269
+ this.indentStr = guessIndent$1(this.original);
6275
6270
  }
6276
6271
  }
6277
6272
 
@@ -6288,7 +6283,7 @@ class MagicString {
6288
6283
  indent(indentStr, options) {
6289
6284
  const pattern = /^[^\r\n]/gm;
6290
6285
 
6291
- if (isObject(indentStr)) {
6286
+ if (isObject$1(indentStr)) {
6292
6287
  options = indentStr;
6293
6288
  indentStr = undefined;
6294
6289
  }
@@ -6380,22 +6375,22 @@ class MagicString {
6380
6375
  }
6381
6376
 
6382
6377
  insertLeft(index, content) {
6383
- if (!warned.insertLeft) {
6378
+ if (!warned$1.insertLeft) {
6384
6379
  console.warn(
6385
6380
  'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
6386
6381
  );
6387
- warned.insertLeft = true;
6382
+ warned$1.insertLeft = true;
6388
6383
  }
6389
6384
 
6390
6385
  return this.appendLeft(index, content);
6391
6386
  }
6392
6387
 
6393
6388
  insertRight(index, content) {
6394
- if (!warned.insertRight) {
6389
+ if (!warned$1.insertRight) {
6395
6390
  console.warn(
6396
6391
  'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
6397
6392
  );
6398
- warned.insertRight = true;
6393
+ warned$1.insertRight = true;
6399
6394
  }
6400
6395
 
6401
6396
  return this.prependRight(index, content);
@@ -6468,11 +6463,11 @@ class MagicString {
6468
6463
  this._split(end);
6469
6464
 
6470
6465
  if (options === true) {
6471
- if (!warned.storeName) {
6466
+ if (!warned$1.storeName) {
6472
6467
  console.warn(
6473
6468
  'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
6474
6469
  );
6475
- warned.storeName = true;
6470
+ warned$1.storeName = true;
6476
6471
  }
6477
6472
 
6478
6473
  options = { storeName: true };
@@ -6505,7 +6500,7 @@ class MagicString {
6505
6500
  first.edit(content, storeName, !overwrite);
6506
6501
  } else {
6507
6502
  // must be inserting at the end
6508
- const newChunk = new Chunk(start, end, '').edit(content, storeName);
6503
+ const newChunk = new Chunk$1(start, end, '').edit(content, storeName);
6509
6504
 
6510
6505
  // TODO last chunk in the array may not be the last chunk, if it's moved...
6511
6506
  last.next = newChunk;
@@ -6624,30 +6619,30 @@ class MagicString {
6624
6619
  }
6625
6620
 
6626
6621
  lastLine() {
6627
- let lineIndex = this.outro.lastIndexOf(n);
6622
+ let lineIndex = this.outro.lastIndexOf(n$1);
6628
6623
  if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
6629
6624
  let lineStr = this.outro;
6630
6625
  let chunk = this.lastChunk;
6631
6626
  do {
6632
6627
  if (chunk.outro.length > 0) {
6633
- lineIndex = chunk.outro.lastIndexOf(n);
6628
+ lineIndex = chunk.outro.lastIndexOf(n$1);
6634
6629
  if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
6635
6630
  lineStr = chunk.outro + lineStr;
6636
6631
  }
6637
6632
 
6638
6633
  if (chunk.content.length > 0) {
6639
- lineIndex = chunk.content.lastIndexOf(n);
6634
+ lineIndex = chunk.content.lastIndexOf(n$1);
6640
6635
  if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
6641
6636
  lineStr = chunk.content + lineStr;
6642
6637
  }
6643
6638
 
6644
6639
  if (chunk.intro.length > 0) {
6645
- lineIndex = chunk.intro.lastIndexOf(n);
6640
+ lineIndex = chunk.intro.lastIndexOf(n$1);
6646
6641
  if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
6647
6642
  lineStr = chunk.intro + lineStr;
6648
6643
  }
6649
6644
  } while ((chunk = chunk.previous));
6650
- lineIndex = this.intro.lastIndexOf(n);
6645
+ lineIndex = this.intro.lastIndexOf(n$1);
6651
6646
  if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
6652
6647
  return this.intro + lineStr;
6653
6648
  }
@@ -6719,19 +6714,25 @@ class MagicString {
6719
6714
  if (this.byStart[index] || this.byEnd[index]) return;
6720
6715
 
6721
6716
  let chunk = this.lastSearchedChunk;
6717
+ let previousChunk = chunk;
6722
6718
  const searchForward = index > chunk.end;
6723
6719
 
6724
6720
  while (chunk) {
6725
6721
  if (chunk.contains(index)) return this._splitChunk(chunk, index);
6726
6722
 
6727
6723
  chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
6724
+
6725
+ // Prevent infinite loop (e.g. via empty chunks, where start === end)
6726
+ if (chunk === previousChunk) return;
6727
+
6728
+ previousChunk = chunk;
6728
6729
  }
6729
6730
  }
6730
6731
 
6731
6732
  _splitChunk(chunk, index) {
6732
6733
  if (chunk.edited && chunk.content.length) {
6733
6734
  // zero-length edited chunks are a special case (overlapping replacements)
6734
- const loc = getLocator(this.original)(index);
6735
+ const loc = getLocator$1(this.original)(index);
6735
6736
  throw new Error(
6736
6737
  `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
6737
6738
  );
@@ -6912,7 +6913,12 @@ class MagicString {
6912
6913
  const index = original.indexOf(string);
6913
6914
 
6914
6915
  if (index !== -1) {
6915
- this.overwrite(index, index + string.length, replacement);
6916
+ if (typeof replacement === 'function') {
6917
+ replacement = replacement(string, index, original);
6918
+ }
6919
+ if (string !== replacement) {
6920
+ this.overwrite(index, index + string.length, replacement);
6921
+ }
6916
6922
  }
6917
6923
 
6918
6924
  return this;
@@ -6935,7 +6941,11 @@ class MagicString {
6935
6941
  index = original.indexOf(string, index + stringLength)
6936
6942
  ) {
6937
6943
  const previous = original.slice(index, index + stringLength);
6938
- if (previous !== replacement) this.overwrite(index, index + stringLength, replacement);
6944
+ let _replacement = replacement;
6945
+ if (typeof replacement === 'function') {
6946
+ _replacement = replacement(previous, index, original);
6947
+ }
6948
+ if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
6939
6949
  }
6940
6950
 
6941
6951
  return this;
@@ -6954,7 +6964,7 @@ class MagicString {
6954
6964
 
6955
6965
  return this._replaceRegexp(searchValue, replacement);
6956
6966
  }
6957
- }
6967
+ };
6958
6968
 
6959
6969
  const HASH_CHARACTER_LENGTH = 16;
6960
6970
  function hashM2c2kitAssets(rootDir, cwd = "") {
@@ -6963,7 +6973,7 @@ function hashM2c2kitAssets(rootDir, cwd = "") {
6963
6973
  name: "hash-m2c2kit-assets",
6964
6974
  renderChunk: {
6965
6975
  handler(code) {
6966
- const magicString = new MagicString(code);
6976
+ const magicString = new MagicString$1(code);
6967
6977
  magicString.replace(
6968
6978
  new RegExp("__NO_M2C2KIT_MANIFEST_JSON_URL__", "g"),
6969
6979
  "manifest.json"
@@ -7168,7 +7178,7 @@ function restoreImportMeta(pattern = "import_meta = {};", replacement = "import_
7168
7178
  name: "restore-import-meta",
7169
7179
  renderChunk: {
7170
7180
  handler(code) {
7171
- const magicString = new MagicString(code);
7181
+ const magicString = new MagicString$1(code);
7172
7182
  magicString.replace(new RegExp(pattern, "g"), replacement);
7173
7183
  return {
7174
7184
  code: magicString.toString(),
@@ -7321,11 +7331,14 @@ function requireNodeModulesPaths () {
7321
7331
  var path = path$3;
7322
7332
  var parse = path.parse || requirePathParse(); // eslint-disable-line global-require
7323
7333
 
7334
+ var driveLetterRegex = /^([A-Za-z]:)/;
7335
+ var uncPathRegex = /^\\\\/;
7336
+
7324
7337
  var getNodeModulesDirs = function getNodeModulesDirs(absoluteStart, modules) {
7325
7338
  var prefix = '/';
7326
- if ((/^([A-Za-z]:)/).test(absoluteStart)) {
7339
+ if (driveLetterRegex.test(absoluteStart)) {
7327
7340
  prefix = '';
7328
- } else if ((/^\\\\/).test(absoluteStart)) {
7341
+ } else if (uncPathRegex.test(absoluteStart)) {
7329
7342
  prefix = '\\\\';
7330
7343
  }
7331
7344
 
@@ -8041,6 +8054,10 @@ function requireAsync$6 () {
8041
8054
 
8042
8055
  var realpathFS = process.platform !== 'win32' && fs.realpath && typeof fs.realpath.native === 'function' ? fs.realpath.native : fs.realpath;
8043
8056
 
8057
+ var relativePathRegex = /^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/;
8058
+ var windowsDriveRegex = /^\w:[/\\]*$/;
8059
+ var nodeModulesRegex = /[/\\]node_modules[/\\]*$/;
8060
+
8044
8061
  var homedir = getHomedir();
8045
8062
  var defaultPaths = function () {
8046
8063
  return [
@@ -8157,10 +8174,10 @@ function requireAsync$6 () {
8157
8174
 
8158
8175
  var res;
8159
8176
  function init(basedir) {
8160
- if ((/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/).test(x)) {
8177
+ if (relativePathRegex.test(x)) {
8161
8178
  res = path.resolve(basedir, x);
8162
8179
  if (x === '.' || x === '..' || x.slice(-1) === '/') res += '/';
8163
- if ((/\/$/).test(x) && res === basedir) {
8180
+ if (x.slice(-1) === '/' && res === basedir) {
8164
8181
  loadAsDirectory(res, opts.package, onfile);
8165
8182
  } else loadAsFile(res, opts.package, onfile);
8166
8183
  } else if (includeCoreModules && isCore(x)) {
@@ -8248,10 +8265,10 @@ function requireAsync$6 () {
8248
8265
 
8249
8266
  function loadpkg(dir, cb) {
8250
8267
  if (dir === '' || dir === '/') return cb(null);
8251
- if (process.platform === 'win32' && (/^\w:[/\\]*$/).test(dir)) {
8268
+ if (process.platform === 'win32' && windowsDriveRegex.test(dir)) {
8252
8269
  return cb(null);
8253
8270
  }
8254
- if ((/[/\\]node_modules[/\\]*$/).test(dir)) return cb(null);
8271
+ if (nodeModulesRegex.test(dir)) return cb(null);
8255
8272
 
8256
8273
  maybeRealpath(realpath, dir, opts, function (unwrapErr, pkgdir) {
8257
8274
  if (unwrapErr) return loadpkg(path.dirname(dir), cb);
@@ -8644,7 +8661,10 @@ var require$$1 = {
8644
8661
  ">= 21.7"
8645
8662
  ],
8646
8663
  smalloc: smalloc,
8647
- "node:sqlite": ">= 23.4",
8664
+ "node:sqlite": [
8665
+ ">= 22.13 && < 23",
8666
+ ">= 23.4"
8667
+ ],
8648
8668
  _stream_duplex: _stream_duplex,
8649
8669
  "node:_stream_duplex": [
8650
8670
  ">= 14.18 && < 15",
@@ -8855,6 +8875,10 @@ function requireSync$6 () {
8855
8875
 
8856
8876
  var realpathFS = process.platform !== 'win32' && fs.realpathSync && typeof fs.realpathSync.native === 'function' ? fs.realpathSync.native : fs.realpathSync;
8857
8877
 
8878
+ var relativePathRegex = /^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/;
8879
+ var windowsDriveRegex = /^\w:[/\\]*$/;
8880
+ var nodeModulesRegex = /[/\\]node_modules[/\\]*$/;
8881
+
8858
8882
  var homedir = getHomedir();
8859
8883
  var defaultPaths = function () {
8860
8884
  return [
@@ -8943,7 +8967,7 @@ function requireSync$6 () {
8943
8967
  // ensure that `basedir` is an absolute path at this point, resolving against the process' current working directory
8944
8968
  var absoluteStart = maybeRealpathSync(realpathSync, path.resolve(basedir), opts);
8945
8969
 
8946
- if ((/^(?:\.\.?(?:\/|$)|\/|([A-Za-z]:)?[/\\])/).test(x)) {
8970
+ if (relativePathRegex.test(x)) {
8947
8971
  var res = path.resolve(absoluteStart, x);
8948
8972
  if (x === '.' || x === '..' || x.slice(-1) === '/') res += '/';
8949
8973
  var m = loadAsFileSync(res) || loadAsDirectorySync(res);
@@ -8984,10 +9008,10 @@ function requireSync$6 () {
8984
9008
 
8985
9009
  function loadpkg(dir) {
8986
9010
  if (dir === '' || dir === '/') return;
8987
- if (process.platform === 'win32' && (/^\w:[/\\]*$/).test(dir)) {
9011
+ if (process.platform === 'win32' && windowsDriveRegex.test(dir)) {
8988
9012
  return;
8989
9013
  }
8990
- if ((/[/\\]node_modules[/\\]*$/).test(dir)) return;
9014
+ if (nodeModulesRegex.test(dir)) return;
8991
9015
 
8992
9016
  var pkgfile = path.join(maybeRealpathSync(realpathSync, dir, opts), 'package.json');
8993
9017
 
@@ -20331,6 +20355,10 @@ function requireIdentifiers () {
20331
20355
 
20332
20356
  const numeric = /^[0-9]+$/;
20333
20357
  const compareIdentifiers = (a, b) => {
20358
+ if (typeof a === 'number' && typeof b === 'number') {
20359
+ return a === b ? 0 : a < b ? -1 : 1
20360
+ }
20361
+
20334
20362
  const anum = numeric.test(a);
20335
20363
  const bnum = numeric.test(b);
20336
20364
 
@@ -20473,11 +20501,25 @@ function requireSemver$1 () {
20473
20501
  other = new SemVer(other, this.options);
20474
20502
  }
20475
20503
 
20476
- return (
20477
- compareIdentifiers(this.major, other.major) ||
20478
- compareIdentifiers(this.minor, other.minor) ||
20479
- compareIdentifiers(this.patch, other.patch)
20480
- )
20504
+ if (this.major < other.major) {
20505
+ return -1
20506
+ }
20507
+ if (this.major > other.major) {
20508
+ return 1
20509
+ }
20510
+ if (this.minor < other.minor) {
20511
+ return -1
20512
+ }
20513
+ if (this.minor > other.minor) {
20514
+ return 1
20515
+ }
20516
+ if (this.patch < other.patch) {
20517
+ return -1
20518
+ }
20519
+ if (this.patch > other.patch) {
20520
+ return 1
20521
+ }
20522
+ return 0
20481
20523
  }
20482
20524
 
20483
20525
  comparePre (other) {
@@ -21498,6 +21540,7 @@ function requireRange () {
21498
21540
  // already replaced the hyphen ranges
21499
21541
  // turn into a set of JUST comparators.
21500
21542
  const parseComparator = (comp, options) => {
21543
+ comp = comp.replace(re[t.BUILD], '');
21501
21544
  debug('comp', comp, options);
21502
21545
  comp = replaceCarets(comp, options);
21503
21546
  debug('caret', comp);
@@ -23043,7 +23086,7 @@ function addModuleMetadata() {
23043
23086
  transform: {
23044
23087
  async handler(code) {
23045
23088
  const pkg = JSON.parse(await readFile("./package.json", "utf8"));
23046
- const magicString = new MagicString(code);
23089
+ const magicString = new MagicString$1(code);
23047
23090
  magicString.replace(
23048
23091
  new RegExp(
23049
23092
  "moduleMetadata:\\s*Constants.MODULE_METADATA_PLACEHOLDER",
@@ -23060,6 +23103,1280 @@ function addModuleMetadata() {
23060
23103
  };
23061
23104
  }
23062
23105
 
23106
+ class BitSet {
23107
+ constructor(arg) {
23108
+ this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
23109
+ }
23110
+
23111
+ add(n) {
23112
+ this.bits[n >> 5] |= 1 << (n & 31);
23113
+ }
23114
+
23115
+ has(n) {
23116
+ return !!(this.bits[n >> 5] & (1 << (n & 31)));
23117
+ }
23118
+ }
23119
+
23120
+ class Chunk {
23121
+ constructor(start, end, content) {
23122
+ this.start = start;
23123
+ this.end = end;
23124
+ this.original = content;
23125
+
23126
+ this.intro = '';
23127
+ this.outro = '';
23128
+
23129
+ this.content = content;
23130
+ this.storeName = false;
23131
+ this.edited = false;
23132
+
23133
+ {
23134
+ this.previous = null;
23135
+ this.next = null;
23136
+ }
23137
+ }
23138
+
23139
+ appendLeft(content) {
23140
+ this.outro += content;
23141
+ }
23142
+
23143
+ appendRight(content) {
23144
+ this.intro = this.intro + content;
23145
+ }
23146
+
23147
+ clone() {
23148
+ const chunk = new Chunk(this.start, this.end, this.original);
23149
+
23150
+ chunk.intro = this.intro;
23151
+ chunk.outro = this.outro;
23152
+ chunk.content = this.content;
23153
+ chunk.storeName = this.storeName;
23154
+ chunk.edited = this.edited;
23155
+
23156
+ return chunk;
23157
+ }
23158
+
23159
+ contains(index) {
23160
+ return this.start < index && index < this.end;
23161
+ }
23162
+
23163
+ eachNext(fn) {
23164
+ let chunk = this;
23165
+ while (chunk) {
23166
+ fn(chunk);
23167
+ chunk = chunk.next;
23168
+ }
23169
+ }
23170
+
23171
+ eachPrevious(fn) {
23172
+ let chunk = this;
23173
+ while (chunk) {
23174
+ fn(chunk);
23175
+ chunk = chunk.previous;
23176
+ }
23177
+ }
23178
+
23179
+ edit(content, storeName, contentOnly) {
23180
+ this.content = content;
23181
+ if (!contentOnly) {
23182
+ this.intro = '';
23183
+ this.outro = '';
23184
+ }
23185
+ this.storeName = storeName;
23186
+
23187
+ this.edited = true;
23188
+
23189
+ return this;
23190
+ }
23191
+
23192
+ prependLeft(content) {
23193
+ this.outro = content + this.outro;
23194
+ }
23195
+
23196
+ prependRight(content) {
23197
+ this.intro = content + this.intro;
23198
+ }
23199
+
23200
+ reset() {
23201
+ this.intro = '';
23202
+ this.outro = '';
23203
+ if (this.edited) {
23204
+ this.content = this.original;
23205
+ this.storeName = false;
23206
+ this.edited = false;
23207
+ }
23208
+ }
23209
+
23210
+ split(index) {
23211
+ const sliceIndex = index - this.start;
23212
+
23213
+ const originalBefore = this.original.slice(0, sliceIndex);
23214
+ const originalAfter = this.original.slice(sliceIndex);
23215
+
23216
+ this.original = originalBefore;
23217
+
23218
+ const newChunk = new Chunk(index, this.end, originalAfter);
23219
+ newChunk.outro = this.outro;
23220
+ this.outro = '';
23221
+
23222
+ this.end = index;
23223
+
23224
+ if (this.edited) {
23225
+ // after split we should save the edit content record into the correct chunk
23226
+ // to make sure sourcemap correct
23227
+ // For example:
23228
+ // ' test'.trim()
23229
+ // split -> ' ' + 'test'
23230
+ // ✔️ edit -> '' + 'test'
23231
+ // ✖️ edit -> 'test' + ''
23232
+ // TODO is this block necessary?...
23233
+ newChunk.edit('', false);
23234
+ this.content = '';
23235
+ } else {
23236
+ this.content = originalBefore;
23237
+ }
23238
+
23239
+ newChunk.next = this.next;
23240
+ if (newChunk.next) newChunk.next.previous = newChunk;
23241
+ newChunk.previous = this;
23242
+ this.next = newChunk;
23243
+
23244
+ return newChunk;
23245
+ }
23246
+
23247
+ toString() {
23248
+ return this.intro + this.content + this.outro;
23249
+ }
23250
+
23251
+ trimEnd(rx) {
23252
+ this.outro = this.outro.replace(rx, '');
23253
+ if (this.outro.length) return true;
23254
+
23255
+ const trimmed = this.content.replace(rx, '');
23256
+
23257
+ if (trimmed.length) {
23258
+ if (trimmed !== this.content) {
23259
+ this.split(this.start + trimmed.length).edit('', undefined, true);
23260
+ if (this.edited) {
23261
+ // save the change, if it has been edited
23262
+ this.edit(trimmed, this.storeName, true);
23263
+ }
23264
+ }
23265
+ return true;
23266
+ } else {
23267
+ this.edit('', undefined, true);
23268
+
23269
+ this.intro = this.intro.replace(rx, '');
23270
+ if (this.intro.length) return true;
23271
+ }
23272
+ }
23273
+
23274
+ trimStart(rx) {
23275
+ this.intro = this.intro.replace(rx, '');
23276
+ if (this.intro.length) return true;
23277
+
23278
+ const trimmed = this.content.replace(rx, '');
23279
+
23280
+ if (trimmed.length) {
23281
+ if (trimmed !== this.content) {
23282
+ const newChunk = this.split(this.end - trimmed.length);
23283
+ if (this.edited) {
23284
+ // save the change, if it has been edited
23285
+ newChunk.edit(trimmed, this.storeName, true);
23286
+ }
23287
+ this.edit('', undefined, true);
23288
+ }
23289
+ return true;
23290
+ } else {
23291
+ this.edit('', undefined, true);
23292
+
23293
+ this.outro = this.outro.replace(rx, '');
23294
+ if (this.outro.length) return true;
23295
+ }
23296
+ }
23297
+ }
23298
+
23299
+ function getBtoa() {
23300
+ if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
23301
+ return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
23302
+ } else if (typeof Buffer === 'function') {
23303
+ return (str) => Buffer.from(str, 'utf-8').toString('base64');
23304
+ } else {
23305
+ return () => {
23306
+ throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
23307
+ };
23308
+ }
23309
+ }
23310
+
23311
+ const btoa = /*#__PURE__*/ getBtoa();
23312
+
23313
+ class SourceMap {
23314
+ constructor(properties) {
23315
+ this.version = 3;
23316
+ this.file = properties.file;
23317
+ this.sources = properties.sources;
23318
+ this.sourcesContent = properties.sourcesContent;
23319
+ this.names = properties.names;
23320
+ this.mappings = encode(properties.mappings);
23321
+ if (typeof properties.x_google_ignoreList !== 'undefined') {
23322
+ this.x_google_ignoreList = properties.x_google_ignoreList;
23323
+ }
23324
+ if (typeof properties.debugId !== 'undefined') {
23325
+ this.debugId = properties.debugId;
23326
+ }
23327
+ }
23328
+
23329
+ toString() {
23330
+ return JSON.stringify(this);
23331
+ }
23332
+
23333
+ toUrl() {
23334
+ return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
23335
+ }
23336
+ }
23337
+
23338
+ function guessIndent(code) {
23339
+ const lines = code.split('\n');
23340
+
23341
+ const tabbed = lines.filter((line) => /^\t+/.test(line));
23342
+ const spaced = lines.filter((line) => /^ {2,}/.test(line));
23343
+
23344
+ if (tabbed.length === 0 && spaced.length === 0) {
23345
+ return null;
23346
+ }
23347
+
23348
+ // More lines tabbed than spaced? Assume tabs, and
23349
+ // default to tabs in the case of a tie (or nothing
23350
+ // to go on)
23351
+ if (tabbed.length >= spaced.length) {
23352
+ return '\t';
23353
+ }
23354
+
23355
+ // Otherwise, we need to guess the multiple
23356
+ const min = spaced.reduce((previous, current) => {
23357
+ const numSpaces = /^ +/.exec(current)[0].length;
23358
+ return Math.min(numSpaces, previous);
23359
+ }, Infinity);
23360
+
23361
+ return new Array(min + 1).join(' ');
23362
+ }
23363
+
23364
+ function getRelativePath(from, to) {
23365
+ const fromParts = from.split(/[/\\]/);
23366
+ const toParts = to.split(/[/\\]/);
23367
+
23368
+ fromParts.pop(); // get dirname
23369
+
23370
+ while (fromParts[0] === toParts[0]) {
23371
+ fromParts.shift();
23372
+ toParts.shift();
23373
+ }
23374
+
23375
+ if (fromParts.length) {
23376
+ let i = fromParts.length;
23377
+ while (i--) fromParts[i] = '..';
23378
+ }
23379
+
23380
+ return fromParts.concat(toParts).join('/');
23381
+ }
23382
+
23383
+ const toString = Object.prototype.toString;
23384
+
23385
+ function isObject(thing) {
23386
+ return toString.call(thing) === '[object Object]';
23387
+ }
23388
+
23389
+ function getLocator(source) {
23390
+ const originalLines = source.split('\n');
23391
+ const lineOffsets = [];
23392
+
23393
+ for (let i = 0, pos = 0; i < originalLines.length; i++) {
23394
+ lineOffsets.push(pos);
23395
+ pos += originalLines[i].length + 1;
23396
+ }
23397
+
23398
+ return function locate(index) {
23399
+ let i = 0;
23400
+ let j = lineOffsets.length;
23401
+ while (i < j) {
23402
+ const m = (i + j) >> 1;
23403
+ if (index < lineOffsets[m]) {
23404
+ j = m;
23405
+ } else {
23406
+ i = m + 1;
23407
+ }
23408
+ }
23409
+ const line = i - 1;
23410
+ const column = index - lineOffsets[line];
23411
+ return { line, column };
23412
+ };
23413
+ }
23414
+
23415
+ const wordRegex = /\w/;
23416
+
23417
+ class Mappings {
23418
+ constructor(hires) {
23419
+ this.hires = hires;
23420
+ this.generatedCodeLine = 0;
23421
+ this.generatedCodeColumn = 0;
23422
+ this.raw = [];
23423
+ this.rawSegments = this.raw[this.generatedCodeLine] = [];
23424
+ this.pending = null;
23425
+ }
23426
+
23427
+ addEdit(sourceIndex, content, loc, nameIndex) {
23428
+ if (content.length) {
23429
+ const contentLengthMinusOne = content.length - 1;
23430
+ let contentLineEnd = content.indexOf('\n', 0);
23431
+ let previousContentLineEnd = -1;
23432
+ // Loop through each line in the content and add a segment, but stop if the last line is empty,
23433
+ // else code afterwards would fill one line too many
23434
+ while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
23435
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
23436
+ if (nameIndex >= 0) {
23437
+ segment.push(nameIndex);
23438
+ }
23439
+ this.rawSegments.push(segment);
23440
+
23441
+ this.generatedCodeLine += 1;
23442
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
23443
+ this.generatedCodeColumn = 0;
23444
+
23445
+ previousContentLineEnd = contentLineEnd;
23446
+ contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
23447
+ }
23448
+
23449
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
23450
+ if (nameIndex >= 0) {
23451
+ segment.push(nameIndex);
23452
+ }
23453
+ this.rawSegments.push(segment);
23454
+
23455
+ this.advance(content.slice(previousContentLineEnd + 1));
23456
+ } else if (this.pending) {
23457
+ this.rawSegments.push(this.pending);
23458
+ this.advance(content);
23459
+ }
23460
+
23461
+ this.pending = null;
23462
+ }
23463
+
23464
+ addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
23465
+ let originalCharIndex = chunk.start;
23466
+ let first = true;
23467
+ // when iterating each char, check if it's in a word boundary
23468
+ let charInHiresBoundary = false;
23469
+
23470
+ while (originalCharIndex < chunk.end) {
23471
+ if (original[originalCharIndex] === '\n') {
23472
+ loc.line += 1;
23473
+ loc.column = 0;
23474
+ this.generatedCodeLine += 1;
23475
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
23476
+ this.generatedCodeColumn = 0;
23477
+ first = true;
23478
+ charInHiresBoundary = false;
23479
+ } else {
23480
+ if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
23481
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
23482
+
23483
+ if (this.hires === 'boundary') {
23484
+ // in hires "boundary", group segments per word boundary than per char
23485
+ if (wordRegex.test(original[originalCharIndex])) {
23486
+ // for first char in the boundary found, start the boundary by pushing a segment
23487
+ if (!charInHiresBoundary) {
23488
+ this.rawSegments.push(segment);
23489
+ charInHiresBoundary = true;
23490
+ }
23491
+ } else {
23492
+ // for non-word char, end the boundary by pushing a segment
23493
+ this.rawSegments.push(segment);
23494
+ charInHiresBoundary = false;
23495
+ }
23496
+ } else {
23497
+ this.rawSegments.push(segment);
23498
+ }
23499
+ }
23500
+
23501
+ loc.column += 1;
23502
+ this.generatedCodeColumn += 1;
23503
+ first = false;
23504
+ }
23505
+
23506
+ originalCharIndex += 1;
23507
+ }
23508
+
23509
+ this.pending = null;
23510
+ }
23511
+
23512
+ advance(str) {
23513
+ if (!str) return;
23514
+
23515
+ const lines = str.split('\n');
23516
+
23517
+ if (lines.length > 1) {
23518
+ for (let i = 0; i < lines.length - 1; i++) {
23519
+ this.generatedCodeLine++;
23520
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
23521
+ }
23522
+ this.generatedCodeColumn = 0;
23523
+ }
23524
+
23525
+ this.generatedCodeColumn += lines[lines.length - 1].length;
23526
+ }
23527
+ }
23528
+
23529
+ const n = '\n';
23530
+
23531
+ const warned = {
23532
+ insertLeft: false,
23533
+ insertRight: false,
23534
+ storeName: false,
23535
+ };
23536
+
23537
+ class MagicString {
23538
+ constructor(string, options = {}) {
23539
+ const chunk = new Chunk(0, string.length, string);
23540
+
23541
+ Object.defineProperties(this, {
23542
+ original: { writable: true, value: string },
23543
+ outro: { writable: true, value: '' },
23544
+ intro: { writable: true, value: '' },
23545
+ firstChunk: { writable: true, value: chunk },
23546
+ lastChunk: { writable: true, value: chunk },
23547
+ lastSearchedChunk: { writable: true, value: chunk },
23548
+ byStart: { writable: true, value: {} },
23549
+ byEnd: { writable: true, value: {} },
23550
+ filename: { writable: true, value: options.filename },
23551
+ indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
23552
+ sourcemapLocations: { writable: true, value: new BitSet() },
23553
+ storedNames: { writable: true, value: {} },
23554
+ indentStr: { writable: true, value: undefined },
23555
+ ignoreList: { writable: true, value: options.ignoreList },
23556
+ offset: { writable: true, value: options.offset || 0 },
23557
+ });
23558
+
23559
+ this.byStart[0] = chunk;
23560
+ this.byEnd[string.length] = chunk;
23561
+ }
23562
+
23563
+ addSourcemapLocation(char) {
23564
+ this.sourcemapLocations.add(char);
23565
+ }
23566
+
23567
+ append(content) {
23568
+ if (typeof content !== 'string') throw new TypeError('outro content must be a string');
23569
+
23570
+ this.outro += content;
23571
+ return this;
23572
+ }
23573
+
23574
+ appendLeft(index, content) {
23575
+ index = index + this.offset;
23576
+
23577
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
23578
+
23579
+ this._split(index);
23580
+
23581
+ const chunk = this.byEnd[index];
23582
+
23583
+ if (chunk) {
23584
+ chunk.appendLeft(content);
23585
+ } else {
23586
+ this.intro += content;
23587
+ }
23588
+ return this;
23589
+ }
23590
+
23591
+ appendRight(index, content) {
23592
+ index = index + this.offset;
23593
+
23594
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
23595
+
23596
+ this._split(index);
23597
+
23598
+ const chunk = this.byStart[index];
23599
+
23600
+ if (chunk) {
23601
+ chunk.appendRight(content);
23602
+ } else {
23603
+ this.outro += content;
23604
+ }
23605
+ return this;
23606
+ }
23607
+
23608
+ clone() {
23609
+ const cloned = new MagicString(this.original, { filename: this.filename, offset: this.offset });
23610
+
23611
+ let originalChunk = this.firstChunk;
23612
+ let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
23613
+
23614
+ while (originalChunk) {
23615
+ cloned.byStart[clonedChunk.start] = clonedChunk;
23616
+ cloned.byEnd[clonedChunk.end] = clonedChunk;
23617
+
23618
+ const nextOriginalChunk = originalChunk.next;
23619
+ const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
23620
+
23621
+ if (nextClonedChunk) {
23622
+ clonedChunk.next = nextClonedChunk;
23623
+ nextClonedChunk.previous = clonedChunk;
23624
+
23625
+ clonedChunk = nextClonedChunk;
23626
+ }
23627
+
23628
+ originalChunk = nextOriginalChunk;
23629
+ }
23630
+
23631
+ cloned.lastChunk = clonedChunk;
23632
+
23633
+ if (this.indentExclusionRanges) {
23634
+ cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
23635
+ }
23636
+
23637
+ cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
23638
+
23639
+ cloned.intro = this.intro;
23640
+ cloned.outro = this.outro;
23641
+
23642
+ return cloned;
23643
+ }
23644
+
23645
+ generateDecodedMap(options) {
23646
+ options = options || {};
23647
+
23648
+ const sourceIndex = 0;
23649
+ const names = Object.keys(this.storedNames);
23650
+ const mappings = new Mappings(options.hires);
23651
+
23652
+ const locate = getLocator(this.original);
23653
+
23654
+ if (this.intro) {
23655
+ mappings.advance(this.intro);
23656
+ }
23657
+
23658
+ this.firstChunk.eachNext((chunk) => {
23659
+ const loc = locate(chunk.start);
23660
+
23661
+ if (chunk.intro.length) mappings.advance(chunk.intro);
23662
+
23663
+ if (chunk.edited) {
23664
+ mappings.addEdit(
23665
+ sourceIndex,
23666
+ chunk.content,
23667
+ loc,
23668
+ chunk.storeName ? names.indexOf(chunk.original) : -1,
23669
+ );
23670
+ } else {
23671
+ mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
23672
+ }
23673
+
23674
+ if (chunk.outro.length) mappings.advance(chunk.outro);
23675
+ });
23676
+
23677
+ return {
23678
+ file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
23679
+ sources: [
23680
+ options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
23681
+ ],
23682
+ sourcesContent: options.includeContent ? [this.original] : undefined,
23683
+ names,
23684
+ mappings: mappings.raw,
23685
+ x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
23686
+ };
23687
+ }
23688
+
23689
+ generateMap(options) {
23690
+ return new SourceMap(this.generateDecodedMap(options));
23691
+ }
23692
+
23693
+ _ensureindentStr() {
23694
+ if (this.indentStr === undefined) {
23695
+ this.indentStr = guessIndent(this.original);
23696
+ }
23697
+ }
23698
+
23699
+ _getRawIndentString() {
23700
+ this._ensureindentStr();
23701
+ return this.indentStr;
23702
+ }
23703
+
23704
+ getIndentString() {
23705
+ this._ensureindentStr();
23706
+ return this.indentStr === null ? '\t' : this.indentStr;
23707
+ }
23708
+
23709
+ indent(indentStr, options) {
23710
+ const pattern = /^[^\r\n]/gm;
23711
+
23712
+ if (isObject(indentStr)) {
23713
+ options = indentStr;
23714
+ indentStr = undefined;
23715
+ }
23716
+
23717
+ if (indentStr === undefined) {
23718
+ this._ensureindentStr();
23719
+ indentStr = this.indentStr || '\t';
23720
+ }
23721
+
23722
+ if (indentStr === '') return this; // noop
23723
+
23724
+ options = options || {};
23725
+
23726
+ // Process exclusion ranges
23727
+ const isExcluded = {};
23728
+
23729
+ if (options.exclude) {
23730
+ const exclusions =
23731
+ typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
23732
+ exclusions.forEach((exclusion) => {
23733
+ for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
23734
+ isExcluded[i] = true;
23735
+ }
23736
+ });
23737
+ }
23738
+
23739
+ let shouldIndentNextCharacter = options.indentStart !== false;
23740
+ const replacer = (match) => {
23741
+ if (shouldIndentNextCharacter) return `${indentStr}${match}`;
23742
+ shouldIndentNextCharacter = true;
23743
+ return match;
23744
+ };
23745
+
23746
+ this.intro = this.intro.replace(pattern, replacer);
23747
+
23748
+ let charIndex = 0;
23749
+ let chunk = this.firstChunk;
23750
+
23751
+ while (chunk) {
23752
+ const end = chunk.end;
23753
+
23754
+ if (chunk.edited) {
23755
+ if (!isExcluded[charIndex]) {
23756
+ chunk.content = chunk.content.replace(pattern, replacer);
23757
+
23758
+ if (chunk.content.length) {
23759
+ shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
23760
+ }
23761
+ }
23762
+ } else {
23763
+ charIndex = chunk.start;
23764
+
23765
+ while (charIndex < end) {
23766
+ if (!isExcluded[charIndex]) {
23767
+ const char = this.original[charIndex];
23768
+
23769
+ if (char === '\n') {
23770
+ shouldIndentNextCharacter = true;
23771
+ } else if (char !== '\r' && shouldIndentNextCharacter) {
23772
+ shouldIndentNextCharacter = false;
23773
+
23774
+ if (charIndex === chunk.start) {
23775
+ chunk.prependRight(indentStr);
23776
+ } else {
23777
+ this._splitChunk(chunk, charIndex);
23778
+ chunk = chunk.next;
23779
+ chunk.prependRight(indentStr);
23780
+ }
23781
+ }
23782
+ }
23783
+
23784
+ charIndex += 1;
23785
+ }
23786
+ }
23787
+
23788
+ charIndex = chunk.end;
23789
+ chunk = chunk.next;
23790
+ }
23791
+
23792
+ this.outro = this.outro.replace(pattern, replacer);
23793
+
23794
+ return this;
23795
+ }
23796
+
23797
+ insert() {
23798
+ throw new Error(
23799
+ 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
23800
+ );
23801
+ }
23802
+
23803
+ insertLeft(index, content) {
23804
+ if (!warned.insertLeft) {
23805
+ console.warn(
23806
+ 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
23807
+ );
23808
+ warned.insertLeft = true;
23809
+ }
23810
+
23811
+ return this.appendLeft(index, content);
23812
+ }
23813
+
23814
+ insertRight(index, content) {
23815
+ if (!warned.insertRight) {
23816
+ console.warn(
23817
+ 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
23818
+ );
23819
+ warned.insertRight = true;
23820
+ }
23821
+
23822
+ return this.prependRight(index, content);
23823
+ }
23824
+
23825
+ move(start, end, index) {
23826
+ start = start + this.offset;
23827
+ end = end + this.offset;
23828
+ index = index + this.offset;
23829
+
23830
+ if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
23831
+
23832
+ this._split(start);
23833
+ this._split(end);
23834
+ this._split(index);
23835
+
23836
+ const first = this.byStart[start];
23837
+ const last = this.byEnd[end];
23838
+
23839
+ const oldLeft = first.previous;
23840
+ const oldRight = last.next;
23841
+
23842
+ const newRight = this.byStart[index];
23843
+ if (!newRight && last === this.lastChunk) return this;
23844
+ const newLeft = newRight ? newRight.previous : this.lastChunk;
23845
+
23846
+ if (oldLeft) oldLeft.next = oldRight;
23847
+ if (oldRight) oldRight.previous = oldLeft;
23848
+
23849
+ if (newLeft) newLeft.next = first;
23850
+ if (newRight) newRight.previous = last;
23851
+
23852
+ if (!first.previous) this.firstChunk = last.next;
23853
+ if (!last.next) {
23854
+ this.lastChunk = first.previous;
23855
+ this.lastChunk.next = null;
23856
+ }
23857
+
23858
+ first.previous = newLeft;
23859
+ last.next = newRight || null;
23860
+
23861
+ if (!newLeft) this.firstChunk = first;
23862
+ if (!newRight) this.lastChunk = last;
23863
+ return this;
23864
+ }
23865
+
23866
+ overwrite(start, end, content, options) {
23867
+ options = options || {};
23868
+ return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
23869
+ }
23870
+
23871
+ update(start, end, content, options) {
23872
+ start = start + this.offset;
23873
+ end = end + this.offset;
23874
+
23875
+ if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
23876
+
23877
+ if (this.original.length !== 0) {
23878
+ while (start < 0) start += this.original.length;
23879
+ while (end < 0) end += this.original.length;
23880
+ }
23881
+
23882
+ if (end > this.original.length) throw new Error('end is out of bounds');
23883
+ if (start === end)
23884
+ throw new Error(
23885
+ 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
23886
+ );
23887
+
23888
+ this._split(start);
23889
+ this._split(end);
23890
+
23891
+ if (options === true) {
23892
+ if (!warned.storeName) {
23893
+ console.warn(
23894
+ 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
23895
+ );
23896
+ warned.storeName = true;
23897
+ }
23898
+
23899
+ options = { storeName: true };
23900
+ }
23901
+ const storeName = options !== undefined ? options.storeName : false;
23902
+ const overwrite = options !== undefined ? options.overwrite : false;
23903
+
23904
+ if (storeName) {
23905
+ const original = this.original.slice(start, end);
23906
+ Object.defineProperty(this.storedNames, original, {
23907
+ writable: true,
23908
+ value: true,
23909
+ enumerable: true,
23910
+ });
23911
+ }
23912
+
23913
+ const first = this.byStart[start];
23914
+ const last = this.byEnd[end];
23915
+
23916
+ if (first) {
23917
+ let chunk = first;
23918
+ while (chunk !== last) {
23919
+ if (chunk.next !== this.byStart[chunk.end]) {
23920
+ throw new Error('Cannot overwrite across a split point');
23921
+ }
23922
+ chunk = chunk.next;
23923
+ chunk.edit('', false);
23924
+ }
23925
+
23926
+ first.edit(content, storeName, !overwrite);
23927
+ } else {
23928
+ // must be inserting at the end
23929
+ const newChunk = new Chunk(start, end, '').edit(content, storeName);
23930
+
23931
+ // TODO last chunk in the array may not be the last chunk, if it's moved...
23932
+ last.next = newChunk;
23933
+ newChunk.previous = last;
23934
+ }
23935
+ return this;
23936
+ }
23937
+
23938
+ prepend(content) {
23939
+ if (typeof content !== 'string') throw new TypeError('outro content must be a string');
23940
+
23941
+ this.intro = content + this.intro;
23942
+ return this;
23943
+ }
23944
+
23945
+ prependLeft(index, content) {
23946
+ index = index + this.offset;
23947
+
23948
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
23949
+
23950
+ this._split(index);
23951
+
23952
+ const chunk = this.byEnd[index];
23953
+
23954
+ if (chunk) {
23955
+ chunk.prependLeft(content);
23956
+ } else {
23957
+ this.intro = content + this.intro;
23958
+ }
23959
+ return this;
23960
+ }
23961
+
23962
+ prependRight(index, content) {
23963
+ index = index + this.offset;
23964
+
23965
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
23966
+
23967
+ this._split(index);
23968
+
23969
+ const chunk = this.byStart[index];
23970
+
23971
+ if (chunk) {
23972
+ chunk.prependRight(content);
23973
+ } else {
23974
+ this.outro = content + this.outro;
23975
+ }
23976
+ return this;
23977
+ }
23978
+
23979
+ remove(start, end) {
23980
+ start = start + this.offset;
23981
+ end = end + this.offset;
23982
+
23983
+ if (this.original.length !== 0) {
23984
+ while (start < 0) start += this.original.length;
23985
+ while (end < 0) end += this.original.length;
23986
+ }
23987
+
23988
+ if (start === end) return this;
23989
+
23990
+ if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
23991
+ if (start > end) throw new Error('end must be greater than start');
23992
+
23993
+ this._split(start);
23994
+ this._split(end);
23995
+
23996
+ let chunk = this.byStart[start];
23997
+
23998
+ while (chunk) {
23999
+ chunk.intro = '';
24000
+ chunk.outro = '';
24001
+ chunk.edit('');
24002
+
24003
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
24004
+ }
24005
+ return this;
24006
+ }
24007
+
24008
+ reset(start, end) {
24009
+ start = start + this.offset;
24010
+ end = end + this.offset;
24011
+
24012
+ if (this.original.length !== 0) {
24013
+ while (start < 0) start += this.original.length;
24014
+ while (end < 0) end += this.original.length;
24015
+ }
24016
+
24017
+ if (start === end) return this;
24018
+
24019
+ if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
24020
+ if (start > end) throw new Error('end must be greater than start');
24021
+
24022
+ this._split(start);
24023
+ this._split(end);
24024
+
24025
+ let chunk = this.byStart[start];
24026
+
24027
+ while (chunk) {
24028
+ chunk.reset();
24029
+
24030
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
24031
+ }
24032
+ return this;
24033
+ }
24034
+
24035
+ lastChar() {
24036
+ if (this.outro.length) return this.outro[this.outro.length - 1];
24037
+ let chunk = this.lastChunk;
24038
+ do {
24039
+ if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
24040
+ if (chunk.content.length) return chunk.content[chunk.content.length - 1];
24041
+ if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
24042
+ } while ((chunk = chunk.previous));
24043
+ if (this.intro.length) return this.intro[this.intro.length - 1];
24044
+ return '';
24045
+ }
24046
+
24047
+ lastLine() {
24048
+ let lineIndex = this.outro.lastIndexOf(n);
24049
+ if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
24050
+ let lineStr = this.outro;
24051
+ let chunk = this.lastChunk;
24052
+ do {
24053
+ if (chunk.outro.length > 0) {
24054
+ lineIndex = chunk.outro.lastIndexOf(n);
24055
+ if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
24056
+ lineStr = chunk.outro + lineStr;
24057
+ }
24058
+
24059
+ if (chunk.content.length > 0) {
24060
+ lineIndex = chunk.content.lastIndexOf(n);
24061
+ if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
24062
+ lineStr = chunk.content + lineStr;
24063
+ }
24064
+
24065
+ if (chunk.intro.length > 0) {
24066
+ lineIndex = chunk.intro.lastIndexOf(n);
24067
+ if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
24068
+ lineStr = chunk.intro + lineStr;
24069
+ }
24070
+ } while ((chunk = chunk.previous));
24071
+ lineIndex = this.intro.lastIndexOf(n);
24072
+ if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
24073
+ return this.intro + lineStr;
24074
+ }
24075
+
24076
+ slice(start = 0, end = this.original.length - this.offset) {
24077
+ start = start + this.offset;
24078
+ end = end + this.offset;
24079
+
24080
+ if (this.original.length !== 0) {
24081
+ while (start < 0) start += this.original.length;
24082
+ while (end < 0) end += this.original.length;
24083
+ }
24084
+
24085
+ let result = '';
24086
+
24087
+ // find start chunk
24088
+ let chunk = this.firstChunk;
24089
+ while (chunk && (chunk.start > start || chunk.end <= start)) {
24090
+ // found end chunk before start
24091
+ if (chunk.start < end && chunk.end >= end) {
24092
+ return result;
24093
+ }
24094
+
24095
+ chunk = chunk.next;
24096
+ }
24097
+
24098
+ if (chunk && chunk.edited && chunk.start !== start)
24099
+ throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
24100
+
24101
+ const startChunk = chunk;
24102
+ while (chunk) {
24103
+ if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
24104
+ result += chunk.intro;
24105
+ }
24106
+
24107
+ const containsEnd = chunk.start < end && chunk.end >= end;
24108
+ if (containsEnd && chunk.edited && chunk.end !== end)
24109
+ throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
24110
+
24111
+ const sliceStart = startChunk === chunk ? start - chunk.start : 0;
24112
+ const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
24113
+
24114
+ result += chunk.content.slice(sliceStart, sliceEnd);
24115
+
24116
+ if (chunk.outro && (!containsEnd || chunk.end === end)) {
24117
+ result += chunk.outro;
24118
+ }
24119
+
24120
+ if (containsEnd) {
24121
+ break;
24122
+ }
24123
+
24124
+ chunk = chunk.next;
24125
+ }
24126
+
24127
+ return result;
24128
+ }
24129
+
24130
+ // TODO deprecate this? not really very useful
24131
+ snip(start, end) {
24132
+ const clone = this.clone();
24133
+ clone.remove(0, start);
24134
+ clone.remove(end, clone.original.length);
24135
+
24136
+ return clone;
24137
+ }
24138
+
24139
+ _split(index) {
24140
+ if (this.byStart[index] || this.byEnd[index]) return;
24141
+
24142
+ let chunk = this.lastSearchedChunk;
24143
+ const searchForward = index > chunk.end;
24144
+
24145
+ while (chunk) {
24146
+ if (chunk.contains(index)) return this._splitChunk(chunk, index);
24147
+
24148
+ chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
24149
+ }
24150
+ }
24151
+
24152
+ _splitChunk(chunk, index) {
24153
+ if (chunk.edited && chunk.content.length) {
24154
+ // zero-length edited chunks are a special case (overlapping replacements)
24155
+ const loc = getLocator(this.original)(index);
24156
+ throw new Error(
24157
+ `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
24158
+ );
24159
+ }
24160
+
24161
+ const newChunk = chunk.split(index);
24162
+
24163
+ this.byEnd[index] = chunk;
24164
+ this.byStart[index] = newChunk;
24165
+ this.byEnd[newChunk.end] = newChunk;
24166
+
24167
+ if (chunk === this.lastChunk) this.lastChunk = newChunk;
24168
+
24169
+ this.lastSearchedChunk = chunk;
24170
+ return true;
24171
+ }
24172
+
24173
+ toString() {
24174
+ let str = this.intro;
24175
+
24176
+ let chunk = this.firstChunk;
24177
+ while (chunk) {
24178
+ str += chunk.toString();
24179
+ chunk = chunk.next;
24180
+ }
24181
+
24182
+ return str + this.outro;
24183
+ }
24184
+
24185
+ isEmpty() {
24186
+ let chunk = this.firstChunk;
24187
+ do {
24188
+ if (
24189
+ (chunk.intro.length && chunk.intro.trim()) ||
24190
+ (chunk.content.length && chunk.content.trim()) ||
24191
+ (chunk.outro.length && chunk.outro.trim())
24192
+ )
24193
+ return false;
24194
+ } while ((chunk = chunk.next));
24195
+ return true;
24196
+ }
24197
+
24198
+ length() {
24199
+ let chunk = this.firstChunk;
24200
+ let length = 0;
24201
+ do {
24202
+ length += chunk.intro.length + chunk.content.length + chunk.outro.length;
24203
+ } while ((chunk = chunk.next));
24204
+ return length;
24205
+ }
24206
+
24207
+ trimLines() {
24208
+ return this.trim('[\\r\\n]');
24209
+ }
24210
+
24211
+ trim(charType) {
24212
+ return this.trimStart(charType).trimEnd(charType);
24213
+ }
24214
+
24215
+ trimEndAborted(charType) {
24216
+ const rx = new RegExp((charType || '\\s') + '+$');
24217
+
24218
+ this.outro = this.outro.replace(rx, '');
24219
+ if (this.outro.length) return true;
24220
+
24221
+ let chunk = this.lastChunk;
24222
+
24223
+ do {
24224
+ const end = chunk.end;
24225
+ const aborted = chunk.trimEnd(rx);
24226
+
24227
+ // if chunk was trimmed, we have a new lastChunk
24228
+ if (chunk.end !== end) {
24229
+ if (this.lastChunk === chunk) {
24230
+ this.lastChunk = chunk.next;
24231
+ }
24232
+
24233
+ this.byEnd[chunk.end] = chunk;
24234
+ this.byStart[chunk.next.start] = chunk.next;
24235
+ this.byEnd[chunk.next.end] = chunk.next;
24236
+ }
24237
+
24238
+ if (aborted) return true;
24239
+ chunk = chunk.previous;
24240
+ } while (chunk);
24241
+
24242
+ return false;
24243
+ }
24244
+
24245
+ trimEnd(charType) {
24246
+ this.trimEndAborted(charType);
24247
+ return this;
24248
+ }
24249
+ trimStartAborted(charType) {
24250
+ const rx = new RegExp('^' + (charType || '\\s') + '+');
24251
+
24252
+ this.intro = this.intro.replace(rx, '');
24253
+ if (this.intro.length) return true;
24254
+
24255
+ let chunk = this.firstChunk;
24256
+
24257
+ do {
24258
+ const end = chunk.end;
24259
+ const aborted = chunk.trimStart(rx);
24260
+
24261
+ if (chunk.end !== end) {
24262
+ // special case...
24263
+ if (chunk === this.lastChunk) this.lastChunk = chunk.next;
24264
+
24265
+ this.byEnd[chunk.end] = chunk;
24266
+ this.byStart[chunk.next.start] = chunk.next;
24267
+ this.byEnd[chunk.next.end] = chunk.next;
24268
+ }
24269
+
24270
+ if (aborted) return true;
24271
+ chunk = chunk.next;
24272
+ } while (chunk);
24273
+
24274
+ return false;
24275
+ }
24276
+
24277
+ trimStart(charType) {
24278
+ this.trimStartAborted(charType);
24279
+ return this;
24280
+ }
24281
+
24282
+ hasChanged() {
24283
+ return this.original !== this.toString();
24284
+ }
24285
+
24286
+ _replaceRegexp(searchValue, replacement) {
24287
+ function getReplacement(match, str) {
24288
+ if (typeof replacement === 'string') {
24289
+ return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
24290
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
24291
+ if (i === '$') return '$';
24292
+ if (i === '&') return match[0];
24293
+ const num = +i;
24294
+ if (num < match.length) return match[+i];
24295
+ return `$${i}`;
24296
+ });
24297
+ } else {
24298
+ return replacement(...match, match.index, str, match.groups);
24299
+ }
24300
+ }
24301
+ function matchAll(re, str) {
24302
+ let match;
24303
+ const matches = [];
24304
+ while ((match = re.exec(str))) {
24305
+ matches.push(match);
24306
+ }
24307
+ return matches;
24308
+ }
24309
+ if (searchValue.global) {
24310
+ const matches = matchAll(searchValue, this.original);
24311
+ matches.forEach((match) => {
24312
+ if (match.index != null) {
24313
+ const replacement = getReplacement(match, this.original);
24314
+ if (replacement !== match[0]) {
24315
+ this.overwrite(match.index, match.index + match[0].length, replacement);
24316
+ }
24317
+ }
24318
+ });
24319
+ } else {
24320
+ const match = this.original.match(searchValue);
24321
+ if (match && match.index != null) {
24322
+ const replacement = getReplacement(match, this.original);
24323
+ if (replacement !== match[0]) {
24324
+ this.overwrite(match.index, match.index + match[0].length, replacement);
24325
+ }
24326
+ }
24327
+ }
24328
+ return this;
24329
+ }
24330
+
24331
+ _replaceString(string, replacement) {
24332
+ const { original } = this;
24333
+ const index = original.indexOf(string);
24334
+
24335
+ if (index !== -1) {
24336
+ this.overwrite(index, index + string.length, replacement);
24337
+ }
24338
+
24339
+ return this;
24340
+ }
24341
+
24342
+ replace(searchValue, replacement) {
24343
+ if (typeof searchValue === 'string') {
24344
+ return this._replaceString(searchValue, replacement);
24345
+ }
24346
+
24347
+ return this._replaceRegexp(searchValue, replacement);
24348
+ }
24349
+
24350
+ _replaceAllString(string, replacement) {
24351
+ const { original } = this;
24352
+ const stringLength = string.length;
24353
+ for (
24354
+ let index = original.indexOf(string);
24355
+ index !== -1;
24356
+ index = original.indexOf(string, index + stringLength)
24357
+ ) {
24358
+ const previous = original.slice(index, index + stringLength);
24359
+ if (previous !== replacement) this.overwrite(index, index + stringLength, replacement);
24360
+ }
24361
+
24362
+ return this;
24363
+ }
24364
+
24365
+ replaceAll(searchValue, replacement) {
24366
+ if (typeof searchValue === 'string') {
24367
+ return this._replaceAllString(searchValue, replacement);
24368
+ }
24369
+
24370
+ if (!searchValue.global) {
24371
+ throw new TypeError(
24372
+ 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
24373
+ );
24374
+ }
24375
+
24376
+ return this._replaceRegexp(searchValue, replacement);
24377
+ }
24378
+ }
24379
+
23063
24380
  var utils = {};
23064
24381
 
23065
24382
  var constants;
@@ -25309,7 +26626,7 @@ function replace(options) {
25309
26626
  if ( options === void 0 ) options = {};
25310
26627
 
25311
26628
  var filter = createFilter(options.include, options.exclude);
25312
- var delimiters = options.delimiters; if ( delimiters === void 0 ) delimiters = ['\\b', '\\b(?!\\.)'];
26629
+ var delimiters = options.delimiters; if ( delimiters === void 0 ) delimiters = ['(?<![_$a-zA-Z0-9\\xA0-\\uFFFF])', '(?![_$a-zA-Z0-9\\xA0-\\uFFFF])(?!\\.)'];
25313
26630
  var preventAssignment = options.preventAssignment;
25314
26631
  var objectGuards = options.objectGuards;
25315
26632
  var replacements = getReplacements(options);