@m2c2kit/build-helpers 0.3.15 → 0.3.17

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 +1493 -132
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -5300,18 +5300,32 @@ const selectAll = getSelectorFunc((query, elems, options) => query === boolbase$
5300
5300
  ? []
5301
5301
  : options.adapter.findAll(query, elems));
5302
5302
 
5303
- const comma = ','.charCodeAt(0);
5304
- const semicolon = ';'.charCodeAt(0);
5305
- const chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
5306
- const intToChar = new Uint8Array(64); // 64 possible chars.
5307
- const charToInt = new Uint8Array(128); // z is 122 in ASCII
5308
- for (let i = 0; i < chars$1.length; i++) {
5309
- const c = chars$1.charCodeAt(i);
5310
- intToChar[i] = c;
5311
- charToInt[c] = i;
5303
+ const comma$1 = ','.charCodeAt(0);
5304
+ const semicolon$1 = ';'.charCodeAt(0);
5305
+ const chars$2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
5306
+ const intToChar$1 = new Uint8Array(64); // 64 possible chars.
5307
+ const charToInt$1 = new Uint8Array(128); // z is 122 in ASCII
5308
+ for (let i = 0; i < chars$2.length; i++) {
5309
+ const c = chars$2.charCodeAt(i);
5310
+ intToChar$1[i] = c;
5311
+ charToInt$1[c] = i;
5312
+ }
5313
+ function encodeInteger$1(builder, num, relative) {
5314
+ let delta = num - relative;
5315
+ delta = delta < 0 ? (-delta << 1) | 1 : delta << 1;
5316
+ do {
5317
+ let clamped = delta & 0b011111;
5318
+ delta >>>= 5;
5319
+ if (delta > 0)
5320
+ clamped |= 0b100000;
5321
+ builder.write(intToChar$1[clamped]);
5322
+ } while (delta > 0);
5323
+ return num;
5312
5324
  }
5325
+
5326
+ const bufLength = 1024 * 16;
5313
5327
  // Provide a fallback for older environments.
5314
- const td = typeof TextDecoder !== 'undefined'
5328
+ const td$1 = typeof TextDecoder !== 'undefined'
5315
5329
  ? /* #__PURE__ */ new TextDecoder()
5316
5330
  : typeof Buffer !== 'undefined'
5317
5331
  ? {
@@ -5329,66 +5343,57 @@ const td = typeof TextDecoder !== 'undefined'
5329
5343
  return out;
5330
5344
  },
5331
5345
  };
5332
- function encode(decoded) {
5333
- const state = new Int32Array(5);
5334
- const bufLength = 1024 * 16;
5335
- const subLength = bufLength - 36;
5336
- const buf = new Uint8Array(bufLength);
5337
- const sub = buf.subarray(0, subLength);
5338
- let pos = 0;
5339
- let out = '';
5346
+ class StringWriter {
5347
+ constructor() {
5348
+ this.pos = 0;
5349
+ this.out = '';
5350
+ this.buffer = new Uint8Array(bufLength);
5351
+ }
5352
+ write(v) {
5353
+ const { buffer } = this;
5354
+ buffer[this.pos++] = v;
5355
+ if (this.pos === bufLength) {
5356
+ this.out += td$1.decode(buffer);
5357
+ this.pos = 0;
5358
+ }
5359
+ }
5360
+ flush() {
5361
+ const { buffer, out, pos } = this;
5362
+ return pos > 0 ? out + td$1.decode(buffer.subarray(0, pos)) : out;
5363
+ }
5364
+ }
5365
+ function encode$1(decoded) {
5366
+ const writer = new StringWriter();
5367
+ let sourcesIndex = 0;
5368
+ let sourceLine = 0;
5369
+ let sourceColumn = 0;
5370
+ let namesIndex = 0;
5340
5371
  for (let i = 0; i < decoded.length; i++) {
5341
5372
  const line = decoded[i];
5342
- if (i > 0) {
5343
- if (pos === bufLength) {
5344
- out += td.decode(buf);
5345
- pos = 0;
5346
- }
5347
- buf[pos++] = semicolon;
5348
- }
5373
+ if (i > 0)
5374
+ writer.write(semicolon$1);
5349
5375
  if (line.length === 0)
5350
5376
  continue;
5351
- state[0] = 0;
5377
+ let genColumn = 0;
5352
5378
  for (let j = 0; j < line.length; j++) {
5353
5379
  const segment = line[j];
5354
- // We can push up to 5 ints, each int can take at most 7 chars, and we
5355
- // may push a comma.
5356
- if (pos > subLength) {
5357
- out += td.decode(sub);
5358
- buf.copyWithin(0, subLength, pos);
5359
- pos -= subLength;
5360
- }
5361
5380
  if (j > 0)
5362
- buf[pos++] = comma;
5363
- pos = encodeInteger(buf, pos, state, segment, 0); // genColumn
5381
+ writer.write(comma$1);
5382
+ genColumn = encodeInteger$1(writer, segment[0], genColumn);
5364
5383
  if (segment.length === 1)
5365
5384
  continue;
5366
- pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex
5367
- pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine
5368
- pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn
5385
+ sourcesIndex = encodeInteger$1(writer, segment[1], sourcesIndex);
5386
+ sourceLine = encodeInteger$1(writer, segment[2], sourceLine);
5387
+ sourceColumn = encodeInteger$1(writer, segment[3], sourceColumn);
5369
5388
  if (segment.length === 4)
5370
5389
  continue;
5371
- pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex
5390
+ namesIndex = encodeInteger$1(writer, segment[4], namesIndex);
5372
5391
  }
5373
5392
  }
5374
- return out + td.decode(buf.subarray(0, pos));
5375
- }
5376
- function encodeInteger(buf, pos, state, segment, j) {
5377
- const next = segment[j];
5378
- let num = next - state[j];
5379
- state[j] = next;
5380
- num = num < 0 ? (-num << 1) | 1 : num << 1;
5381
- do {
5382
- let clamped = num & 0b011111;
5383
- num >>>= 5;
5384
- if (num > 0)
5385
- clamped |= 0b100000;
5386
- buf[pos++] = intToChar[clamped];
5387
- } while (num > 0);
5388
- return pos;
5393
+ return writer.flush();
5389
5394
  }
5390
5395
 
5391
- class BitSet {
5396
+ let BitSet$1 = class BitSet {
5392
5397
  constructor(arg) {
5393
5398
  this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
5394
5399
  }
@@ -5400,9 +5405,9 @@ class BitSet {
5400
5405
  has(n) {
5401
5406
  return !!(this.bits[n >> 5] & (1 << (n & 31)));
5402
5407
  }
5403
- }
5408
+ };
5404
5409
 
5405
- class Chunk {
5410
+ let Chunk$1 = class Chunk {
5406
5411
  constructor(start, end, content) {
5407
5412
  this.start = start;
5408
5413
  this.end = end;
@@ -5579,9 +5584,9 @@ class Chunk {
5579
5584
  if (this.outro.length) return true;
5580
5585
  }
5581
5586
  }
5582
- }
5587
+ };
5583
5588
 
5584
- function getBtoa() {
5589
+ function getBtoa$1() {
5585
5590
  if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
5586
5591
  return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
5587
5592
  } else if (typeof Buffer === 'function') {
@@ -5593,16 +5598,16 @@ function getBtoa() {
5593
5598
  }
5594
5599
  }
5595
5600
 
5596
- const btoa = /*#__PURE__*/ getBtoa();
5601
+ const btoa$1 = /*#__PURE__*/ getBtoa$1();
5597
5602
 
5598
- class SourceMap {
5603
+ let SourceMap$1 = class SourceMap {
5599
5604
  constructor(properties) {
5600
5605
  this.version = 3;
5601
5606
  this.file = properties.file;
5602
5607
  this.sources = properties.sources;
5603
5608
  this.sourcesContent = properties.sourcesContent;
5604
5609
  this.names = properties.names;
5605
- this.mappings = encode(properties.mappings);
5610
+ this.mappings = encode$1(properties.mappings);
5606
5611
  if (typeof properties.x_google_ignoreList !== 'undefined') {
5607
5612
  this.x_google_ignoreList = properties.x_google_ignoreList;
5608
5613
  }
@@ -5613,11 +5618,11 @@ class SourceMap {
5613
5618
  }
5614
5619
 
5615
5620
  toUrl() {
5616
- return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
5621
+ return 'data:application/json;charset=utf-8;base64,' + btoa$1(this.toString());
5617
5622
  }
5618
- }
5623
+ };
5619
5624
 
5620
- function guessIndent(code) {
5625
+ function guessIndent$1(code) {
5621
5626
  const lines = code.split('\n');
5622
5627
 
5623
5628
  const tabbed = lines.filter((line) => /^\t+/.test(line));
@@ -5643,7 +5648,7 @@ function guessIndent(code) {
5643
5648
  return new Array(min + 1).join(' ');
5644
5649
  }
5645
5650
 
5646
- function getRelativePath(from, to) {
5651
+ function getRelativePath$1(from, to) {
5647
5652
  const fromParts = from.split(/[/\\]/);
5648
5653
  const toParts = to.split(/[/\\]/);
5649
5654
 
@@ -5662,13 +5667,13 @@ function getRelativePath(from, to) {
5662
5667
  return fromParts.concat(toParts).join('/');
5663
5668
  }
5664
5669
 
5665
- const toString = Object.prototype.toString;
5670
+ const toString$1 = Object.prototype.toString;
5666
5671
 
5667
- function isObject$3(thing) {
5668
- return toString.call(thing) === '[object Object]';
5672
+ function isObject$4(thing) {
5673
+ return toString$1.call(thing) === '[object Object]';
5669
5674
  }
5670
5675
 
5671
- function getLocator(source) {
5676
+ function getLocator$1(source) {
5672
5677
  const originalLines = source.split('\n');
5673
5678
  const lineOffsets = [];
5674
5679
 
@@ -5694,9 +5699,9 @@ function getLocator(source) {
5694
5699
  };
5695
5700
  }
5696
5701
 
5697
- const wordRegex = /\w/;
5702
+ const wordRegex$1 = /\w/;
5698
5703
 
5699
- class Mappings {
5704
+ let Mappings$1 = class Mappings {
5700
5705
  constructor(hires) {
5701
5706
  this.hires = hires;
5702
5707
  this.generatedCodeLine = 0;
@@ -5755,7 +5760,7 @@ class Mappings {
5755
5760
 
5756
5761
  if (this.hires === 'boundary') {
5757
5762
  // in hires "boundary", group segments per word boundary than per char
5758
- if (wordRegex.test(original[originalCharIndex])) {
5763
+ if (wordRegex$1.test(original[originalCharIndex])) {
5759
5764
  // for first char in the boundary found, start the boundary by pushing a segment
5760
5765
  if (!charInHiresBoundary) {
5761
5766
  this.rawSegments.push(segment);
@@ -5805,19 +5810,19 @@ class Mappings {
5805
5810
 
5806
5811
  this.generatedCodeColumn += lines[lines.length - 1].length;
5807
5812
  }
5808
- }
5813
+ };
5809
5814
 
5810
- const n = '\n';
5815
+ const n$1 = '\n';
5811
5816
 
5812
- const warned = {
5817
+ const warned$1 = {
5813
5818
  insertLeft: false,
5814
5819
  insertRight: false,
5815
5820
  storeName: false,
5816
5821
  };
5817
5822
 
5818
- class MagicString {
5823
+ let MagicString$1 = class MagicString {
5819
5824
  constructor(string, options = {}) {
5820
- const chunk = new Chunk(0, string.length, string);
5825
+ const chunk = new Chunk$1(0, string.length, string);
5821
5826
 
5822
5827
  Object.defineProperties(this, {
5823
5828
  original: { writable: true, value: string },
@@ -5830,7 +5835,7 @@ class MagicString {
5830
5835
  byEnd: { writable: true, value: {} },
5831
5836
  filename: { writable: true, value: options.filename },
5832
5837
  indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
5833
- sourcemapLocations: { writable: true, value: new BitSet() },
5838
+ sourcemapLocations: { writable: true, value: new BitSet$1() },
5834
5839
  storedNames: { writable: true, value: {} },
5835
5840
  indentStr: { writable: true, value: undefined },
5836
5841
  ignoreList: { writable: true, value: options.ignoreList },
@@ -5910,7 +5915,7 @@ class MagicString {
5910
5915
  cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
5911
5916
  }
5912
5917
 
5913
- cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
5918
+ cloned.sourcemapLocations = new BitSet$1(this.sourcemapLocations);
5914
5919
 
5915
5920
  cloned.intro = this.intro;
5916
5921
  cloned.outro = this.outro;
@@ -5923,9 +5928,9 @@ class MagicString {
5923
5928
 
5924
5929
  const sourceIndex = 0;
5925
5930
  const names = Object.keys(this.storedNames);
5926
- const mappings = new Mappings(options.hires);
5931
+ const mappings = new Mappings$1(options.hires);
5927
5932
 
5928
- const locate = getLocator(this.original);
5933
+ const locate = getLocator$1(this.original);
5929
5934
 
5930
5935
  if (this.intro) {
5931
5936
  mappings.advance(this.intro);
@@ -5953,7 +5958,7 @@ class MagicString {
5953
5958
  return {
5954
5959
  file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
5955
5960
  sources: [
5956
- options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
5961
+ options.source ? getRelativePath$1(options.file || '', options.source) : options.file || '',
5957
5962
  ],
5958
5963
  sourcesContent: options.includeContent ? [this.original] : undefined,
5959
5964
  names,
@@ -5963,12 +5968,12 @@ class MagicString {
5963
5968
  }
5964
5969
 
5965
5970
  generateMap(options) {
5966
- return new SourceMap(this.generateDecodedMap(options));
5971
+ return new SourceMap$1(this.generateDecodedMap(options));
5967
5972
  }
5968
5973
 
5969
5974
  _ensureindentStr() {
5970
5975
  if (this.indentStr === undefined) {
5971
- this.indentStr = guessIndent(this.original);
5976
+ this.indentStr = guessIndent$1(this.original);
5972
5977
  }
5973
5978
  }
5974
5979
 
@@ -5985,7 +5990,7 @@ class MagicString {
5985
5990
  indent(indentStr, options) {
5986
5991
  const pattern = /^[^\r\n]/gm;
5987
5992
 
5988
- if (isObject$3(indentStr)) {
5993
+ if (isObject$4(indentStr)) {
5989
5994
  options = indentStr;
5990
5995
  indentStr = undefined;
5991
5996
  }
@@ -6077,22 +6082,22 @@ class MagicString {
6077
6082
  }
6078
6083
 
6079
6084
  insertLeft(index, content) {
6080
- if (!warned.insertLeft) {
6085
+ if (!warned$1.insertLeft) {
6081
6086
  console.warn(
6082
6087
  'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
6083
6088
  ); // eslint-disable-line no-console
6084
- warned.insertLeft = true;
6089
+ warned$1.insertLeft = true;
6085
6090
  }
6086
6091
 
6087
6092
  return this.appendLeft(index, content);
6088
6093
  }
6089
6094
 
6090
6095
  insertRight(index, content) {
6091
- if (!warned.insertRight) {
6096
+ if (!warned$1.insertRight) {
6092
6097
  console.warn(
6093
6098
  'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
6094
6099
  ); // eslint-disable-line no-console
6095
- warned.insertRight = true;
6100
+ warned$1.insertRight = true;
6096
6101
  }
6097
6102
 
6098
6103
  return this.prependRight(index, content);
@@ -6143,8 +6148,10 @@ class MagicString {
6143
6148
  update(start, end, content, options) {
6144
6149
  if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
6145
6150
 
6146
- while (start < 0) start += this.original.length;
6147
- while (end < 0) end += this.original.length;
6151
+ if (this.original.length !== 0) {
6152
+ while (start < 0) start += this.original.length;
6153
+ while (end < 0) end += this.original.length;
6154
+ }
6148
6155
 
6149
6156
  if (end > this.original.length) throw new Error('end is out of bounds');
6150
6157
  if (start === end)
@@ -6156,11 +6163,11 @@ class MagicString {
6156
6163
  this._split(end);
6157
6164
 
6158
6165
  if (options === true) {
6159
- if (!warned.storeName) {
6166
+ if (!warned$1.storeName) {
6160
6167
  console.warn(
6161
6168
  'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
6162
6169
  ); // eslint-disable-line no-console
6163
- warned.storeName = true;
6170
+ warned$1.storeName = true;
6164
6171
  }
6165
6172
 
6166
6173
  options = { storeName: true };
@@ -6193,7 +6200,7 @@ class MagicString {
6193
6200
  first.edit(content, storeName, !overwrite);
6194
6201
  } else {
6195
6202
  // must be inserting at the end
6196
- const newChunk = new Chunk(start, end, '').edit(content, storeName);
6203
+ const newChunk = new Chunk$1(start, end, '').edit(content, storeName);
6197
6204
 
6198
6205
  // TODO last chunk in the array may not be the last chunk, if it's moved...
6199
6206
  last.next = newChunk;
@@ -6240,8 +6247,10 @@ class MagicString {
6240
6247
  }
6241
6248
 
6242
6249
  remove(start, end) {
6243
- while (start < 0) start += this.original.length;
6244
- while (end < 0) end += this.original.length;
6250
+ if (this.original.length !== 0) {
6251
+ while (start < 0) start += this.original.length;
6252
+ while (end < 0) end += this.original.length;
6253
+ }
6245
6254
 
6246
6255
  if (start === end) return this;
6247
6256
 
@@ -6264,8 +6273,10 @@ class MagicString {
6264
6273
  }
6265
6274
 
6266
6275
  reset(start, end) {
6267
- while (start < 0) start += this.original.length;
6268
- while (end < 0) end += this.original.length;
6276
+ if (this.original.length !== 0) {
6277
+ while (start < 0) start += this.original.length;
6278
+ while (end < 0) end += this.original.length;
6279
+ }
6269
6280
 
6270
6281
  if (start === end) return this;
6271
6282
 
@@ -6298,37 +6309,39 @@ class MagicString {
6298
6309
  }
6299
6310
 
6300
6311
  lastLine() {
6301
- let lineIndex = this.outro.lastIndexOf(n);
6312
+ let lineIndex = this.outro.lastIndexOf(n$1);
6302
6313
  if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
6303
6314
  let lineStr = this.outro;
6304
6315
  let chunk = this.lastChunk;
6305
6316
  do {
6306
6317
  if (chunk.outro.length > 0) {
6307
- lineIndex = chunk.outro.lastIndexOf(n);
6318
+ lineIndex = chunk.outro.lastIndexOf(n$1);
6308
6319
  if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
6309
6320
  lineStr = chunk.outro + lineStr;
6310
6321
  }
6311
6322
 
6312
6323
  if (chunk.content.length > 0) {
6313
- lineIndex = chunk.content.lastIndexOf(n);
6324
+ lineIndex = chunk.content.lastIndexOf(n$1);
6314
6325
  if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
6315
6326
  lineStr = chunk.content + lineStr;
6316
6327
  }
6317
6328
 
6318
6329
  if (chunk.intro.length > 0) {
6319
- lineIndex = chunk.intro.lastIndexOf(n);
6330
+ lineIndex = chunk.intro.lastIndexOf(n$1);
6320
6331
  if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
6321
6332
  lineStr = chunk.intro + lineStr;
6322
6333
  }
6323
6334
  } while ((chunk = chunk.previous));
6324
- lineIndex = this.intro.lastIndexOf(n);
6335
+ lineIndex = this.intro.lastIndexOf(n$1);
6325
6336
  if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
6326
6337
  return this.intro + lineStr;
6327
6338
  }
6328
6339
 
6329
6340
  slice(start = 0, end = this.original.length) {
6330
- while (start < 0) start += this.original.length;
6331
- while (end < 0) end += this.original.length;
6341
+ if (this.original.length !== 0) {
6342
+ while (start < 0) start += this.original.length;
6343
+ while (end < 0) end += this.original.length;
6344
+ }
6332
6345
 
6333
6346
  let result = '';
6334
6347
 
@@ -6400,7 +6413,7 @@ class MagicString {
6400
6413
  _splitChunk(chunk, index) {
6401
6414
  if (chunk.edited && chunk.content.length) {
6402
6415
  // zero-length edited chunks are a special case (overlapping replacements)
6403
- const loc = getLocator(this.original)(index);
6416
+ const loc = getLocator$1(this.original)(index);
6404
6417
  throw new Error(
6405
6418
  `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
6406
6419
  );
@@ -6632,7 +6645,7 @@ class MagicString {
6632
6645
 
6633
6646
  return this._replaceRegexp(searchValue, replacement);
6634
6647
  }
6635
- }
6648
+ };
6636
6649
 
6637
6650
  const HASH_CHARACTER_LENGTH = 16;
6638
6651
  function hashM2c2kitAssets(rootDir, cwd = "") {
@@ -6641,7 +6654,7 @@ function hashM2c2kitAssets(rootDir, cwd = "") {
6641
6654
  name: "hash-m2c2kit-assets",
6642
6655
  renderChunk: {
6643
6656
  handler(code) {
6644
- const magicString = new MagicString(code);
6657
+ const magicString = new MagicString$1(code);
6645
6658
  magicString.replace(
6646
6659
  new RegExp("__NO_M2C2KIT_MANIFEST_JSON_URL__", "g"),
6647
6660
  "manifest.json"
@@ -6846,7 +6859,7 @@ function restoreImportMeta(pattern = "import_meta = {};", replacement = "import_
6846
6859
  name: "restore-import-meta",
6847
6860
  renderChunk: {
6848
6861
  handler(code) {
6849
- const magicString = new MagicString(code);
6862
+ const magicString = new MagicString$1(code);
6850
6863
  magicString.replace(new RegExp(pattern, "g"), replacement);
6851
6864
  return {
6852
6865
  code: magicString.toString(),
@@ -7049,7 +7062,7 @@ var concatty = function concatty(a, b) {
7049
7062
 
7050
7063
  var slicy = function slicy(arrLike, offset) {
7051
7064
  var arr = [];
7052
- for (var i = offset , j = 0; i < arrLike.length; i += 1, j += 1) {
7065
+ for (var i = offset, j = 0; i < arrLike.length; i += 1, j += 1) {
7053
7066
  arr[j] = arrLike[i];
7054
7067
  }
7055
7068
  return arr;
@@ -10827,7 +10840,7 @@ var isExtglob$1 = function isExtglob(str) {
10827
10840
  */
10828
10841
 
10829
10842
  var isExtglob = isExtglob$1;
10830
- var chars = { '{': '}', '(': ')', '[': ']'};
10843
+ var chars$1 = { '{': '}', '(': ')', '[': ']'};
10831
10844
  var strictCheck = function(str) {
10832
10845
  if (str[0] === '!') {
10833
10846
  return true;
@@ -10900,7 +10913,7 @@ var strictCheck = function(str) {
10900
10913
  if (str[index] === '\\') {
10901
10914
  var open = str[index + 1];
10902
10915
  index += 2;
10903
- var close = chars[open];
10916
+ var close = chars$1[open];
10904
10917
 
10905
10918
  if (close) {
10906
10919
  var n = str.indexOf(close, index);
@@ -10932,7 +10945,7 @@ var relaxedCheck = function(str) {
10932
10945
  if (str[index] === '\\') {
10933
10946
  var open = str[index + 1];
10934
10947
  index += 2;
10935
- var close = chars[open];
10948
+ var close = chars$1[open];
10936
10949
 
10937
10950
  if (close) {
10938
10951
  var n = str.indexOf(close, index);
@@ -11481,7 +11494,7 @@ var toRegexRange_1 = toRegexRange$1;
11481
11494
  const util$1 = require$$0$1;
11482
11495
  const toRegexRange = toRegexRange_1;
11483
11496
 
11484
- const isObject$2 = val => val !== null && typeof val === 'object' && !Array.isArray(val);
11497
+ const isObject$3 = val => val !== null && typeof val === 'object' && !Array.isArray(val);
11485
11498
 
11486
11499
  const transform = toNumber => {
11487
11500
  return value => toNumber === true ? Number(value) : String(value);
@@ -11696,7 +11709,7 @@ const fill$2 = (start, end, step, options = {}) => {
11696
11709
  return fill$2(start, end, 1, { transform: step });
11697
11710
  }
11698
11711
 
11699
- if (isObject$2(step)) {
11712
+ if (isObject$3(step)) {
11700
11713
  return fill$2(start, end, 0, step);
11701
11714
  }
11702
11715
 
@@ -11705,7 +11718,7 @@ const fill$2 = (start, end, step, options = {}) => {
11705
11718
  step = step || opts.step || 1;
11706
11719
 
11707
11720
  if (!isNumber(step)) {
11708
- if (step != null && !isObject$2(step)) return invalidStep(step, opts);
11721
+ if (step != null && !isObject$3(step)) return invalidStep(step, opts);
11709
11722
  return fill$2(start, end, 1, step);
11710
11723
  }
11711
11724
 
@@ -14175,7 +14188,7 @@ const scan = scan_1;
14175
14188
  const parse$7 = parse_1$1;
14176
14189
  const utils$c = utils$f;
14177
14190
  const constants$3 = constants$5;
14178
- const isObject$1 = val => val && typeof val === 'object' && !Array.isArray(val);
14191
+ const isObject$2 = val => val && typeof val === 'object' && !Array.isArray(val);
14179
14192
 
14180
14193
  /**
14181
14194
  * Creates a matcher function from one or more glob patterns. The
@@ -14212,7 +14225,7 @@ const picomatch$2 = (glob, options, returnState = false) => {
14212
14225
  return arrayMatcher;
14213
14226
  }
14214
14227
 
14215
- const isState = isObject$1(glob) && glob.tokens && glob.input;
14228
+ const isState = isObject$2(glob) && glob.tokens && glob.input;
14216
14229
 
14217
14230
  if (glob === '' || (typeof glob !== 'string' && !isState)) {
14218
14231
  throw new TypeError('Expected pattern to be a non-empty string');
@@ -18678,7 +18691,7 @@ function requireSymbols () {
18678
18691
  return symbols.exports;
18679
18692
  }
18680
18693
 
18681
- const isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
18694
+ const isObject$1 = val => val !== null && typeof val === 'object' && !Array.isArray(val);
18682
18695
 
18683
18696
  /* eslint-disable no-control-regex */
18684
18697
  // this is a modified version of https://github.com/chalk/ansi-regex (MIT License)
@@ -18834,7 +18847,7 @@ const create = () => {
18834
18847
  };
18835
18848
 
18836
18849
  colors.theme = custom => {
18837
- if (!isObject(custom)) throw new TypeError('Expected theme to be an object');
18850
+ if (!isObject$1(custom)) throw new TypeError('Expected theme to be an object');
18838
18851
  for (let name of Object.keys(custom)) {
18839
18852
  colors.alias(name, custom[name]);
18840
18853
  }
@@ -19828,6 +19841,8 @@ var hasRequiredRange;
19828
19841
  function requireRange () {
19829
19842
  if (hasRequiredRange) return range;
19830
19843
  hasRequiredRange = 1;
19844
+ const SPACE_CHARACTERS = /\s+/g;
19845
+
19831
19846
  // hoisted class for cyclic dependency
19832
19847
  class Range {
19833
19848
  constructor (range, options) {
@@ -19848,7 +19863,7 @@ function requireRange () {
19848
19863
  // just put it in the set and return
19849
19864
  this.raw = range.value;
19850
19865
  this.set = [[range]];
19851
- this.format();
19866
+ this.formatted = undefined;
19852
19867
  return this
19853
19868
  }
19854
19869
 
@@ -19859,10 +19874,7 @@ function requireRange () {
19859
19874
  // First reduce all whitespace as much as possible so we do not have to rely
19860
19875
  // on potentially slow regexes like \s*. This is then stored and used for
19861
19876
  // future error messages as well.
19862
- this.raw = range
19863
- .trim()
19864
- .split(/\s+/)
19865
- .join(' ');
19877
+ this.raw = range.trim().replace(SPACE_CHARACTERS, ' ');
19866
19878
 
19867
19879
  // First, split on ||
19868
19880
  this.set = this.raw
@@ -19896,14 +19908,29 @@ function requireRange () {
19896
19908
  }
19897
19909
  }
19898
19910
 
19899
- this.format();
19911
+ this.formatted = undefined;
19912
+ }
19913
+
19914
+ get range () {
19915
+ if (this.formatted === undefined) {
19916
+ this.formatted = '';
19917
+ for (let i = 0; i < this.set.length; i++) {
19918
+ if (i > 0) {
19919
+ this.formatted += '||';
19920
+ }
19921
+ const comps = this.set[i];
19922
+ for (let k = 0; k < comps.length; k++) {
19923
+ if (k > 0) {
19924
+ this.formatted += ' ';
19925
+ }
19926
+ this.formatted += comps[k].toString().trim();
19927
+ }
19928
+ }
19929
+ }
19930
+ return this.formatted
19900
19931
  }
19901
19932
 
19902
19933
  format () {
19903
- this.range = this.set
19904
- .map((comps) => comps.join(' ').trim())
19905
- .join('||')
19906
- .trim();
19907
19934
  return this.range
19908
19935
  }
19909
19936
 
@@ -21496,7 +21523,7 @@ function addModuleMetadata() {
21496
21523
  transform: {
21497
21524
  async handler(code) {
21498
21525
  const pkg = JSON.parse(await readFile("./package.json", "utf8"));
21499
- const magicString = new MagicString(code);
21526
+ const magicString = new MagicString$1(code);
21500
21527
  magicString.replace(
21501
21528
  new RegExp(
21502
21529
  "moduleMetadata:\\s*Constants.MODULE_METADATA_PLACEHOLDER",
@@ -21513,6 +21540,1340 @@ function addModuleMetadata() {
21513
21540
  };
21514
21541
  }
21515
21542
 
21543
+ const comma = ','.charCodeAt(0);
21544
+ const semicolon = ';'.charCodeAt(0);
21545
+ const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
21546
+ const intToChar = new Uint8Array(64); // 64 possible chars.
21547
+ const charToInt = new Uint8Array(128); // z is 122 in ASCII
21548
+ for (let i = 0; i < chars.length; i++) {
21549
+ const c = chars.charCodeAt(i);
21550
+ intToChar[i] = c;
21551
+ charToInt[c] = i;
21552
+ }
21553
+ // Provide a fallback for older environments.
21554
+ const td = typeof TextDecoder !== 'undefined'
21555
+ ? /* #__PURE__ */ new TextDecoder()
21556
+ : typeof Buffer !== 'undefined'
21557
+ ? {
21558
+ decode(buf) {
21559
+ const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
21560
+ return out.toString();
21561
+ },
21562
+ }
21563
+ : {
21564
+ decode(buf) {
21565
+ let out = '';
21566
+ for (let i = 0; i < buf.length; i++) {
21567
+ out += String.fromCharCode(buf[i]);
21568
+ }
21569
+ return out;
21570
+ },
21571
+ };
21572
+ function encode(decoded) {
21573
+ const state = new Int32Array(5);
21574
+ const bufLength = 1024 * 16;
21575
+ const subLength = bufLength - 36;
21576
+ const buf = new Uint8Array(bufLength);
21577
+ const sub = buf.subarray(0, subLength);
21578
+ let pos = 0;
21579
+ let out = '';
21580
+ for (let i = 0; i < decoded.length; i++) {
21581
+ const line = decoded[i];
21582
+ if (i > 0) {
21583
+ if (pos === bufLength) {
21584
+ out += td.decode(buf);
21585
+ pos = 0;
21586
+ }
21587
+ buf[pos++] = semicolon;
21588
+ }
21589
+ if (line.length === 0)
21590
+ continue;
21591
+ state[0] = 0;
21592
+ for (let j = 0; j < line.length; j++) {
21593
+ const segment = line[j];
21594
+ // We can push up to 5 ints, each int can take at most 7 chars, and we
21595
+ // may push a comma.
21596
+ if (pos > subLength) {
21597
+ out += td.decode(sub);
21598
+ buf.copyWithin(0, subLength, pos);
21599
+ pos -= subLength;
21600
+ }
21601
+ if (j > 0)
21602
+ buf[pos++] = comma;
21603
+ pos = encodeInteger(buf, pos, state, segment, 0); // genColumn
21604
+ if (segment.length === 1)
21605
+ continue;
21606
+ pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex
21607
+ pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine
21608
+ pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn
21609
+ if (segment.length === 4)
21610
+ continue;
21611
+ pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex
21612
+ }
21613
+ }
21614
+ return out + td.decode(buf.subarray(0, pos));
21615
+ }
21616
+ function encodeInteger(buf, pos, state, segment, j) {
21617
+ const next = segment[j];
21618
+ let num = next - state[j];
21619
+ state[j] = next;
21620
+ num = num < 0 ? (-num << 1) | 1 : num << 1;
21621
+ do {
21622
+ let clamped = num & 0b011111;
21623
+ num >>>= 5;
21624
+ if (num > 0)
21625
+ clamped |= 0b100000;
21626
+ buf[pos++] = intToChar[clamped];
21627
+ } while (num > 0);
21628
+ return pos;
21629
+ }
21630
+
21631
+ class BitSet {
21632
+ constructor(arg) {
21633
+ this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
21634
+ }
21635
+
21636
+ add(n) {
21637
+ this.bits[n >> 5] |= 1 << (n & 31);
21638
+ }
21639
+
21640
+ has(n) {
21641
+ return !!(this.bits[n >> 5] & (1 << (n & 31)));
21642
+ }
21643
+ }
21644
+
21645
+ class Chunk {
21646
+ constructor(start, end, content) {
21647
+ this.start = start;
21648
+ this.end = end;
21649
+ this.original = content;
21650
+
21651
+ this.intro = '';
21652
+ this.outro = '';
21653
+
21654
+ this.content = content;
21655
+ this.storeName = false;
21656
+ this.edited = false;
21657
+
21658
+ {
21659
+ this.previous = null;
21660
+ this.next = null;
21661
+ }
21662
+ }
21663
+
21664
+ appendLeft(content) {
21665
+ this.outro += content;
21666
+ }
21667
+
21668
+ appendRight(content) {
21669
+ this.intro = this.intro + content;
21670
+ }
21671
+
21672
+ clone() {
21673
+ const chunk = new Chunk(this.start, this.end, this.original);
21674
+
21675
+ chunk.intro = this.intro;
21676
+ chunk.outro = this.outro;
21677
+ chunk.content = this.content;
21678
+ chunk.storeName = this.storeName;
21679
+ chunk.edited = this.edited;
21680
+
21681
+ return chunk;
21682
+ }
21683
+
21684
+ contains(index) {
21685
+ return this.start < index && index < this.end;
21686
+ }
21687
+
21688
+ eachNext(fn) {
21689
+ let chunk = this;
21690
+ while (chunk) {
21691
+ fn(chunk);
21692
+ chunk = chunk.next;
21693
+ }
21694
+ }
21695
+
21696
+ eachPrevious(fn) {
21697
+ let chunk = this;
21698
+ while (chunk) {
21699
+ fn(chunk);
21700
+ chunk = chunk.previous;
21701
+ }
21702
+ }
21703
+
21704
+ edit(content, storeName, contentOnly) {
21705
+ this.content = content;
21706
+ if (!contentOnly) {
21707
+ this.intro = '';
21708
+ this.outro = '';
21709
+ }
21710
+ this.storeName = storeName;
21711
+
21712
+ this.edited = true;
21713
+
21714
+ return this;
21715
+ }
21716
+
21717
+ prependLeft(content) {
21718
+ this.outro = content + this.outro;
21719
+ }
21720
+
21721
+ prependRight(content) {
21722
+ this.intro = content + this.intro;
21723
+ }
21724
+
21725
+ reset() {
21726
+ this.intro = '';
21727
+ this.outro = '';
21728
+ if (this.edited) {
21729
+ this.content = this.original;
21730
+ this.storeName = false;
21731
+ this.edited = false;
21732
+ }
21733
+ }
21734
+
21735
+ split(index) {
21736
+ const sliceIndex = index - this.start;
21737
+
21738
+ const originalBefore = this.original.slice(0, sliceIndex);
21739
+ const originalAfter = this.original.slice(sliceIndex);
21740
+
21741
+ this.original = originalBefore;
21742
+
21743
+ const newChunk = new Chunk(index, this.end, originalAfter);
21744
+ newChunk.outro = this.outro;
21745
+ this.outro = '';
21746
+
21747
+ this.end = index;
21748
+
21749
+ if (this.edited) {
21750
+ // after split we should save the edit content record into the correct chunk
21751
+ // to make sure sourcemap correct
21752
+ // For example:
21753
+ // ' test'.trim()
21754
+ // split -> ' ' + 'test'
21755
+ // ✔️ edit -> '' + 'test'
21756
+ // ✖️ edit -> 'test' + ''
21757
+ // TODO is this block necessary?...
21758
+ newChunk.edit('', false);
21759
+ this.content = '';
21760
+ } else {
21761
+ this.content = originalBefore;
21762
+ }
21763
+
21764
+ newChunk.next = this.next;
21765
+ if (newChunk.next) newChunk.next.previous = newChunk;
21766
+ newChunk.previous = this;
21767
+ this.next = newChunk;
21768
+
21769
+ return newChunk;
21770
+ }
21771
+
21772
+ toString() {
21773
+ return this.intro + this.content + this.outro;
21774
+ }
21775
+
21776
+ trimEnd(rx) {
21777
+ this.outro = this.outro.replace(rx, '');
21778
+ if (this.outro.length) return true;
21779
+
21780
+ const trimmed = this.content.replace(rx, '');
21781
+
21782
+ if (trimmed.length) {
21783
+ if (trimmed !== this.content) {
21784
+ this.split(this.start + trimmed.length).edit('', undefined, true);
21785
+ if (this.edited) {
21786
+ // save the change, if it has been edited
21787
+ this.edit(trimmed, this.storeName, true);
21788
+ }
21789
+ }
21790
+ return true;
21791
+ } else {
21792
+ this.edit('', undefined, true);
21793
+
21794
+ this.intro = this.intro.replace(rx, '');
21795
+ if (this.intro.length) return true;
21796
+ }
21797
+ }
21798
+
21799
+ trimStart(rx) {
21800
+ this.intro = this.intro.replace(rx, '');
21801
+ if (this.intro.length) return true;
21802
+
21803
+ const trimmed = this.content.replace(rx, '');
21804
+
21805
+ if (trimmed.length) {
21806
+ if (trimmed !== this.content) {
21807
+ const newChunk = this.split(this.end - trimmed.length);
21808
+ if (this.edited) {
21809
+ // save the change, if it has been edited
21810
+ newChunk.edit(trimmed, this.storeName, true);
21811
+ }
21812
+ this.edit('', undefined, true);
21813
+ }
21814
+ return true;
21815
+ } else {
21816
+ this.edit('', undefined, true);
21817
+
21818
+ this.outro = this.outro.replace(rx, '');
21819
+ if (this.outro.length) return true;
21820
+ }
21821
+ }
21822
+ }
21823
+
21824
+ function getBtoa() {
21825
+ if (typeof globalThis !== 'undefined' && typeof globalThis.btoa === 'function') {
21826
+ return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
21827
+ } else if (typeof Buffer === 'function') {
21828
+ return (str) => Buffer.from(str, 'utf-8').toString('base64');
21829
+ } else {
21830
+ return () => {
21831
+ throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
21832
+ };
21833
+ }
21834
+ }
21835
+
21836
+ const btoa = /*#__PURE__*/ getBtoa();
21837
+
21838
+ class SourceMap {
21839
+ constructor(properties) {
21840
+ this.version = 3;
21841
+ this.file = properties.file;
21842
+ this.sources = properties.sources;
21843
+ this.sourcesContent = properties.sourcesContent;
21844
+ this.names = properties.names;
21845
+ this.mappings = encode(properties.mappings);
21846
+ if (typeof properties.x_google_ignoreList !== 'undefined') {
21847
+ this.x_google_ignoreList = properties.x_google_ignoreList;
21848
+ }
21849
+ }
21850
+
21851
+ toString() {
21852
+ return JSON.stringify(this);
21853
+ }
21854
+
21855
+ toUrl() {
21856
+ return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
21857
+ }
21858
+ }
21859
+
21860
+ function guessIndent(code) {
21861
+ const lines = code.split('\n');
21862
+
21863
+ const tabbed = lines.filter((line) => /^\t+/.test(line));
21864
+ const spaced = lines.filter((line) => /^ {2,}/.test(line));
21865
+
21866
+ if (tabbed.length === 0 && spaced.length === 0) {
21867
+ return null;
21868
+ }
21869
+
21870
+ // More lines tabbed than spaced? Assume tabs, and
21871
+ // default to tabs in the case of a tie (or nothing
21872
+ // to go on)
21873
+ if (tabbed.length >= spaced.length) {
21874
+ return '\t';
21875
+ }
21876
+
21877
+ // Otherwise, we need to guess the multiple
21878
+ const min = spaced.reduce((previous, current) => {
21879
+ const numSpaces = /^ +/.exec(current)[0].length;
21880
+ return Math.min(numSpaces, previous);
21881
+ }, Infinity);
21882
+
21883
+ return new Array(min + 1).join(' ');
21884
+ }
21885
+
21886
+ function getRelativePath(from, to) {
21887
+ const fromParts = from.split(/[/\\]/);
21888
+ const toParts = to.split(/[/\\]/);
21889
+
21890
+ fromParts.pop(); // get dirname
21891
+
21892
+ while (fromParts[0] === toParts[0]) {
21893
+ fromParts.shift();
21894
+ toParts.shift();
21895
+ }
21896
+
21897
+ if (fromParts.length) {
21898
+ let i = fromParts.length;
21899
+ while (i--) fromParts[i] = '..';
21900
+ }
21901
+
21902
+ return fromParts.concat(toParts).join('/');
21903
+ }
21904
+
21905
+ const toString = Object.prototype.toString;
21906
+
21907
+ function isObject(thing) {
21908
+ return toString.call(thing) === '[object Object]';
21909
+ }
21910
+
21911
+ function getLocator(source) {
21912
+ const originalLines = source.split('\n');
21913
+ const lineOffsets = [];
21914
+
21915
+ for (let i = 0, pos = 0; i < originalLines.length; i++) {
21916
+ lineOffsets.push(pos);
21917
+ pos += originalLines[i].length + 1;
21918
+ }
21919
+
21920
+ return function locate(index) {
21921
+ let i = 0;
21922
+ let j = lineOffsets.length;
21923
+ while (i < j) {
21924
+ const m = (i + j) >> 1;
21925
+ if (index < lineOffsets[m]) {
21926
+ j = m;
21927
+ } else {
21928
+ i = m + 1;
21929
+ }
21930
+ }
21931
+ const line = i - 1;
21932
+ const column = index - lineOffsets[line];
21933
+ return { line, column };
21934
+ };
21935
+ }
21936
+
21937
+ const wordRegex = /\w/;
21938
+
21939
+ class Mappings {
21940
+ constructor(hires) {
21941
+ this.hires = hires;
21942
+ this.generatedCodeLine = 0;
21943
+ this.generatedCodeColumn = 0;
21944
+ this.raw = [];
21945
+ this.rawSegments = this.raw[this.generatedCodeLine] = [];
21946
+ this.pending = null;
21947
+ }
21948
+
21949
+ addEdit(sourceIndex, content, loc, nameIndex) {
21950
+ if (content.length) {
21951
+ const contentLengthMinusOne = content.length - 1;
21952
+ let contentLineEnd = content.indexOf('\n', 0);
21953
+ let previousContentLineEnd = -1;
21954
+ // Loop through each line in the content and add a segment, but stop if the last line is empty,
21955
+ // else code afterwards would fill one line too many
21956
+ while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
21957
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
21958
+ if (nameIndex >= 0) {
21959
+ segment.push(nameIndex);
21960
+ }
21961
+ this.rawSegments.push(segment);
21962
+
21963
+ this.generatedCodeLine += 1;
21964
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
21965
+ this.generatedCodeColumn = 0;
21966
+
21967
+ previousContentLineEnd = contentLineEnd;
21968
+ contentLineEnd = content.indexOf('\n', contentLineEnd + 1);
21969
+ }
21970
+
21971
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
21972
+ if (nameIndex >= 0) {
21973
+ segment.push(nameIndex);
21974
+ }
21975
+ this.rawSegments.push(segment);
21976
+
21977
+ this.advance(content.slice(previousContentLineEnd + 1));
21978
+ } else if (this.pending) {
21979
+ this.rawSegments.push(this.pending);
21980
+ this.advance(content);
21981
+ }
21982
+
21983
+ this.pending = null;
21984
+ }
21985
+
21986
+ addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
21987
+ let originalCharIndex = chunk.start;
21988
+ let first = true;
21989
+ // when iterating each char, check if it's in a word boundary
21990
+ let charInHiresBoundary = false;
21991
+
21992
+ while (originalCharIndex < chunk.end) {
21993
+ if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
21994
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
21995
+
21996
+ if (this.hires === 'boundary') {
21997
+ // in hires "boundary", group segments per word boundary than per char
21998
+ if (wordRegex.test(original[originalCharIndex])) {
21999
+ // for first char in the boundary found, start the boundary by pushing a segment
22000
+ if (!charInHiresBoundary) {
22001
+ this.rawSegments.push(segment);
22002
+ charInHiresBoundary = true;
22003
+ }
22004
+ } else {
22005
+ // for non-word char, end the boundary by pushing a segment
22006
+ this.rawSegments.push(segment);
22007
+ charInHiresBoundary = false;
22008
+ }
22009
+ } else {
22010
+ this.rawSegments.push(segment);
22011
+ }
22012
+ }
22013
+
22014
+ if (original[originalCharIndex] === '\n') {
22015
+ loc.line += 1;
22016
+ loc.column = 0;
22017
+ this.generatedCodeLine += 1;
22018
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
22019
+ this.generatedCodeColumn = 0;
22020
+ first = true;
22021
+ } else {
22022
+ loc.column += 1;
22023
+ this.generatedCodeColumn += 1;
22024
+ first = false;
22025
+ }
22026
+
22027
+ originalCharIndex += 1;
22028
+ }
22029
+
22030
+ this.pending = null;
22031
+ }
22032
+
22033
+ advance(str) {
22034
+ if (!str) return;
22035
+
22036
+ const lines = str.split('\n');
22037
+
22038
+ if (lines.length > 1) {
22039
+ for (let i = 0; i < lines.length - 1; i++) {
22040
+ this.generatedCodeLine++;
22041
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
22042
+ }
22043
+ this.generatedCodeColumn = 0;
22044
+ }
22045
+
22046
+ this.generatedCodeColumn += lines[lines.length - 1].length;
22047
+ }
22048
+ }
22049
+
22050
+ const n = '\n';
22051
+
22052
+ const warned = {
22053
+ insertLeft: false,
22054
+ insertRight: false,
22055
+ storeName: false,
22056
+ };
22057
+
22058
+ class MagicString {
22059
+ constructor(string, options = {}) {
22060
+ const chunk = new Chunk(0, string.length, string);
22061
+
22062
+ Object.defineProperties(this, {
22063
+ original: { writable: true, value: string },
22064
+ outro: { writable: true, value: '' },
22065
+ intro: { writable: true, value: '' },
22066
+ firstChunk: { writable: true, value: chunk },
22067
+ lastChunk: { writable: true, value: chunk },
22068
+ lastSearchedChunk: { writable: true, value: chunk },
22069
+ byStart: { writable: true, value: {} },
22070
+ byEnd: { writable: true, value: {} },
22071
+ filename: { writable: true, value: options.filename },
22072
+ indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
22073
+ sourcemapLocations: { writable: true, value: new BitSet() },
22074
+ storedNames: { writable: true, value: {} },
22075
+ indentStr: { writable: true, value: undefined },
22076
+ ignoreList: { writable: true, value: options.ignoreList },
22077
+ });
22078
+
22079
+ this.byStart[0] = chunk;
22080
+ this.byEnd[string.length] = chunk;
22081
+ }
22082
+
22083
+ addSourcemapLocation(char) {
22084
+ this.sourcemapLocations.add(char);
22085
+ }
22086
+
22087
+ append(content) {
22088
+ if (typeof content !== 'string') throw new TypeError('outro content must be a string');
22089
+
22090
+ this.outro += content;
22091
+ return this;
22092
+ }
22093
+
22094
+ appendLeft(index, content) {
22095
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
22096
+
22097
+ this._split(index);
22098
+
22099
+ const chunk = this.byEnd[index];
22100
+
22101
+ if (chunk) {
22102
+ chunk.appendLeft(content);
22103
+ } else {
22104
+ this.intro += content;
22105
+ }
22106
+ return this;
22107
+ }
22108
+
22109
+ appendRight(index, content) {
22110
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
22111
+
22112
+ this._split(index);
22113
+
22114
+ const chunk = this.byStart[index];
22115
+
22116
+ if (chunk) {
22117
+ chunk.appendRight(content);
22118
+ } else {
22119
+ this.outro += content;
22120
+ }
22121
+ return this;
22122
+ }
22123
+
22124
+ clone() {
22125
+ const cloned = new MagicString(this.original, { filename: this.filename });
22126
+
22127
+ let originalChunk = this.firstChunk;
22128
+ let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
22129
+
22130
+ while (originalChunk) {
22131
+ cloned.byStart[clonedChunk.start] = clonedChunk;
22132
+ cloned.byEnd[clonedChunk.end] = clonedChunk;
22133
+
22134
+ const nextOriginalChunk = originalChunk.next;
22135
+ const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
22136
+
22137
+ if (nextClonedChunk) {
22138
+ clonedChunk.next = nextClonedChunk;
22139
+ nextClonedChunk.previous = clonedChunk;
22140
+
22141
+ clonedChunk = nextClonedChunk;
22142
+ }
22143
+
22144
+ originalChunk = nextOriginalChunk;
22145
+ }
22146
+
22147
+ cloned.lastChunk = clonedChunk;
22148
+
22149
+ if (this.indentExclusionRanges) {
22150
+ cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
22151
+ }
22152
+
22153
+ cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
22154
+
22155
+ cloned.intro = this.intro;
22156
+ cloned.outro = this.outro;
22157
+
22158
+ return cloned;
22159
+ }
22160
+
22161
+ generateDecodedMap(options) {
22162
+ options = options || {};
22163
+
22164
+ const sourceIndex = 0;
22165
+ const names = Object.keys(this.storedNames);
22166
+ const mappings = new Mappings(options.hires);
22167
+
22168
+ const locate = getLocator(this.original);
22169
+
22170
+ if (this.intro) {
22171
+ mappings.advance(this.intro);
22172
+ }
22173
+
22174
+ this.firstChunk.eachNext((chunk) => {
22175
+ const loc = locate(chunk.start);
22176
+
22177
+ if (chunk.intro.length) mappings.advance(chunk.intro);
22178
+
22179
+ if (chunk.edited) {
22180
+ mappings.addEdit(
22181
+ sourceIndex,
22182
+ chunk.content,
22183
+ loc,
22184
+ chunk.storeName ? names.indexOf(chunk.original) : -1,
22185
+ );
22186
+ } else {
22187
+ mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
22188
+ }
22189
+
22190
+ if (chunk.outro.length) mappings.advance(chunk.outro);
22191
+ });
22192
+
22193
+ return {
22194
+ file: options.file ? options.file.split(/[/\\]/).pop() : undefined,
22195
+ sources: [
22196
+ options.source ? getRelativePath(options.file || '', options.source) : options.file || '',
22197
+ ],
22198
+ sourcesContent: options.includeContent ? [this.original] : undefined,
22199
+ names,
22200
+ mappings: mappings.raw,
22201
+ x_google_ignoreList: this.ignoreList ? [sourceIndex] : undefined,
22202
+ };
22203
+ }
22204
+
22205
+ generateMap(options) {
22206
+ return new SourceMap(this.generateDecodedMap(options));
22207
+ }
22208
+
22209
+ _ensureindentStr() {
22210
+ if (this.indentStr === undefined) {
22211
+ this.indentStr = guessIndent(this.original);
22212
+ }
22213
+ }
22214
+
22215
+ _getRawIndentString() {
22216
+ this._ensureindentStr();
22217
+ return this.indentStr;
22218
+ }
22219
+
22220
+ getIndentString() {
22221
+ this._ensureindentStr();
22222
+ return this.indentStr === null ? '\t' : this.indentStr;
22223
+ }
22224
+
22225
+ indent(indentStr, options) {
22226
+ const pattern = /^[^\r\n]/gm;
22227
+
22228
+ if (isObject(indentStr)) {
22229
+ options = indentStr;
22230
+ indentStr = undefined;
22231
+ }
22232
+
22233
+ if (indentStr === undefined) {
22234
+ this._ensureindentStr();
22235
+ indentStr = this.indentStr || '\t';
22236
+ }
22237
+
22238
+ if (indentStr === '') return this; // noop
22239
+
22240
+ options = options || {};
22241
+
22242
+ // Process exclusion ranges
22243
+ const isExcluded = {};
22244
+
22245
+ if (options.exclude) {
22246
+ const exclusions =
22247
+ typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
22248
+ exclusions.forEach((exclusion) => {
22249
+ for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
22250
+ isExcluded[i] = true;
22251
+ }
22252
+ });
22253
+ }
22254
+
22255
+ let shouldIndentNextCharacter = options.indentStart !== false;
22256
+ const replacer = (match) => {
22257
+ if (shouldIndentNextCharacter) return `${indentStr}${match}`;
22258
+ shouldIndentNextCharacter = true;
22259
+ return match;
22260
+ };
22261
+
22262
+ this.intro = this.intro.replace(pattern, replacer);
22263
+
22264
+ let charIndex = 0;
22265
+ let chunk = this.firstChunk;
22266
+
22267
+ while (chunk) {
22268
+ const end = chunk.end;
22269
+
22270
+ if (chunk.edited) {
22271
+ if (!isExcluded[charIndex]) {
22272
+ chunk.content = chunk.content.replace(pattern, replacer);
22273
+
22274
+ if (chunk.content.length) {
22275
+ shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
22276
+ }
22277
+ }
22278
+ } else {
22279
+ charIndex = chunk.start;
22280
+
22281
+ while (charIndex < end) {
22282
+ if (!isExcluded[charIndex]) {
22283
+ const char = this.original[charIndex];
22284
+
22285
+ if (char === '\n') {
22286
+ shouldIndentNextCharacter = true;
22287
+ } else if (char !== '\r' && shouldIndentNextCharacter) {
22288
+ shouldIndentNextCharacter = false;
22289
+
22290
+ if (charIndex === chunk.start) {
22291
+ chunk.prependRight(indentStr);
22292
+ } else {
22293
+ this._splitChunk(chunk, charIndex);
22294
+ chunk = chunk.next;
22295
+ chunk.prependRight(indentStr);
22296
+ }
22297
+ }
22298
+ }
22299
+
22300
+ charIndex += 1;
22301
+ }
22302
+ }
22303
+
22304
+ charIndex = chunk.end;
22305
+ chunk = chunk.next;
22306
+ }
22307
+
22308
+ this.outro = this.outro.replace(pattern, replacer);
22309
+
22310
+ return this;
22311
+ }
22312
+
22313
+ insert() {
22314
+ throw new Error(
22315
+ 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)',
22316
+ );
22317
+ }
22318
+
22319
+ insertLeft(index, content) {
22320
+ if (!warned.insertLeft) {
22321
+ console.warn(
22322
+ 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead',
22323
+ ); // eslint-disable-line no-console
22324
+ warned.insertLeft = true;
22325
+ }
22326
+
22327
+ return this.appendLeft(index, content);
22328
+ }
22329
+
22330
+ insertRight(index, content) {
22331
+ if (!warned.insertRight) {
22332
+ console.warn(
22333
+ 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead',
22334
+ ); // eslint-disable-line no-console
22335
+ warned.insertRight = true;
22336
+ }
22337
+
22338
+ return this.prependRight(index, content);
22339
+ }
22340
+
22341
+ move(start, end, index) {
22342
+ if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
22343
+
22344
+ this._split(start);
22345
+ this._split(end);
22346
+ this._split(index);
22347
+
22348
+ const first = this.byStart[start];
22349
+ const last = this.byEnd[end];
22350
+
22351
+ const oldLeft = first.previous;
22352
+ const oldRight = last.next;
22353
+
22354
+ const newRight = this.byStart[index];
22355
+ if (!newRight && last === this.lastChunk) return this;
22356
+ const newLeft = newRight ? newRight.previous : this.lastChunk;
22357
+
22358
+ if (oldLeft) oldLeft.next = oldRight;
22359
+ if (oldRight) oldRight.previous = oldLeft;
22360
+
22361
+ if (newLeft) newLeft.next = first;
22362
+ if (newRight) newRight.previous = last;
22363
+
22364
+ if (!first.previous) this.firstChunk = last.next;
22365
+ if (!last.next) {
22366
+ this.lastChunk = first.previous;
22367
+ this.lastChunk.next = null;
22368
+ }
22369
+
22370
+ first.previous = newLeft;
22371
+ last.next = newRight || null;
22372
+
22373
+ if (!newLeft) this.firstChunk = first;
22374
+ if (!newRight) this.lastChunk = last;
22375
+ return this;
22376
+ }
22377
+
22378
+ overwrite(start, end, content, options) {
22379
+ options = options || {};
22380
+ return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
22381
+ }
22382
+
22383
+ update(start, end, content, options) {
22384
+ if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
22385
+
22386
+ while (start < 0) start += this.original.length;
22387
+ while (end < 0) end += this.original.length;
22388
+
22389
+ if (end > this.original.length) throw new Error('end is out of bounds');
22390
+ if (start === end)
22391
+ throw new Error(
22392
+ 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead',
22393
+ );
22394
+
22395
+ this._split(start);
22396
+ this._split(end);
22397
+
22398
+ if (options === true) {
22399
+ if (!warned.storeName) {
22400
+ console.warn(
22401
+ 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string',
22402
+ ); // eslint-disable-line no-console
22403
+ warned.storeName = true;
22404
+ }
22405
+
22406
+ options = { storeName: true };
22407
+ }
22408
+ const storeName = options !== undefined ? options.storeName : false;
22409
+ const overwrite = options !== undefined ? options.overwrite : false;
22410
+
22411
+ if (storeName) {
22412
+ const original = this.original.slice(start, end);
22413
+ Object.defineProperty(this.storedNames, original, {
22414
+ writable: true,
22415
+ value: true,
22416
+ enumerable: true,
22417
+ });
22418
+ }
22419
+
22420
+ const first = this.byStart[start];
22421
+ const last = this.byEnd[end];
22422
+
22423
+ if (first) {
22424
+ let chunk = first;
22425
+ while (chunk !== last) {
22426
+ if (chunk.next !== this.byStart[chunk.end]) {
22427
+ throw new Error('Cannot overwrite across a split point');
22428
+ }
22429
+ chunk = chunk.next;
22430
+ chunk.edit('', false);
22431
+ }
22432
+
22433
+ first.edit(content, storeName, !overwrite);
22434
+ } else {
22435
+ // must be inserting at the end
22436
+ const newChunk = new Chunk(start, end, '').edit(content, storeName);
22437
+
22438
+ // TODO last chunk in the array may not be the last chunk, if it's moved...
22439
+ last.next = newChunk;
22440
+ newChunk.previous = last;
22441
+ }
22442
+ return this;
22443
+ }
22444
+
22445
+ prepend(content) {
22446
+ if (typeof content !== 'string') throw new TypeError('outro content must be a string');
22447
+
22448
+ this.intro = content + this.intro;
22449
+ return this;
22450
+ }
22451
+
22452
+ prependLeft(index, content) {
22453
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
22454
+
22455
+ this._split(index);
22456
+
22457
+ const chunk = this.byEnd[index];
22458
+
22459
+ if (chunk) {
22460
+ chunk.prependLeft(content);
22461
+ } else {
22462
+ this.intro = content + this.intro;
22463
+ }
22464
+ return this;
22465
+ }
22466
+
22467
+ prependRight(index, content) {
22468
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
22469
+
22470
+ this._split(index);
22471
+
22472
+ const chunk = this.byStart[index];
22473
+
22474
+ if (chunk) {
22475
+ chunk.prependRight(content);
22476
+ } else {
22477
+ this.outro = content + this.outro;
22478
+ }
22479
+ return this;
22480
+ }
22481
+
22482
+ remove(start, end) {
22483
+ while (start < 0) start += this.original.length;
22484
+ while (end < 0) end += this.original.length;
22485
+
22486
+ if (start === end) return this;
22487
+
22488
+ if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
22489
+ if (start > end) throw new Error('end must be greater than start');
22490
+
22491
+ this._split(start);
22492
+ this._split(end);
22493
+
22494
+ let chunk = this.byStart[start];
22495
+
22496
+ while (chunk) {
22497
+ chunk.intro = '';
22498
+ chunk.outro = '';
22499
+ chunk.edit('');
22500
+
22501
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
22502
+ }
22503
+ return this;
22504
+ }
22505
+
22506
+ reset(start, end) {
22507
+ while (start < 0) start += this.original.length;
22508
+ while (end < 0) end += this.original.length;
22509
+
22510
+ if (start === end) return this;
22511
+
22512
+ if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
22513
+ if (start > end) throw new Error('end must be greater than start');
22514
+
22515
+ this._split(start);
22516
+ this._split(end);
22517
+
22518
+ let chunk = this.byStart[start];
22519
+
22520
+ while (chunk) {
22521
+ chunk.reset();
22522
+
22523
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
22524
+ }
22525
+ return this;
22526
+ }
22527
+
22528
+ lastChar() {
22529
+ if (this.outro.length) return this.outro[this.outro.length - 1];
22530
+ let chunk = this.lastChunk;
22531
+ do {
22532
+ if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
22533
+ if (chunk.content.length) return chunk.content[chunk.content.length - 1];
22534
+ if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
22535
+ } while ((chunk = chunk.previous));
22536
+ if (this.intro.length) return this.intro[this.intro.length - 1];
22537
+ return '';
22538
+ }
22539
+
22540
+ lastLine() {
22541
+ let lineIndex = this.outro.lastIndexOf(n);
22542
+ if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
22543
+ let lineStr = this.outro;
22544
+ let chunk = this.lastChunk;
22545
+ do {
22546
+ if (chunk.outro.length > 0) {
22547
+ lineIndex = chunk.outro.lastIndexOf(n);
22548
+ if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
22549
+ lineStr = chunk.outro + lineStr;
22550
+ }
22551
+
22552
+ if (chunk.content.length > 0) {
22553
+ lineIndex = chunk.content.lastIndexOf(n);
22554
+ if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
22555
+ lineStr = chunk.content + lineStr;
22556
+ }
22557
+
22558
+ if (chunk.intro.length > 0) {
22559
+ lineIndex = chunk.intro.lastIndexOf(n);
22560
+ if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
22561
+ lineStr = chunk.intro + lineStr;
22562
+ }
22563
+ } while ((chunk = chunk.previous));
22564
+ lineIndex = this.intro.lastIndexOf(n);
22565
+ if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
22566
+ return this.intro + lineStr;
22567
+ }
22568
+
22569
+ slice(start = 0, end = this.original.length) {
22570
+ while (start < 0) start += this.original.length;
22571
+ while (end < 0) end += this.original.length;
22572
+
22573
+ let result = '';
22574
+
22575
+ // find start chunk
22576
+ let chunk = this.firstChunk;
22577
+ while (chunk && (chunk.start > start || chunk.end <= start)) {
22578
+ // found end chunk before start
22579
+ if (chunk.start < end && chunk.end >= end) {
22580
+ return result;
22581
+ }
22582
+
22583
+ chunk = chunk.next;
22584
+ }
22585
+
22586
+ if (chunk && chunk.edited && chunk.start !== start)
22587
+ throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
22588
+
22589
+ const startChunk = chunk;
22590
+ while (chunk) {
22591
+ if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
22592
+ result += chunk.intro;
22593
+ }
22594
+
22595
+ const containsEnd = chunk.start < end && chunk.end >= end;
22596
+ if (containsEnd && chunk.edited && chunk.end !== end)
22597
+ throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
22598
+
22599
+ const sliceStart = startChunk === chunk ? start - chunk.start : 0;
22600
+ const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
22601
+
22602
+ result += chunk.content.slice(sliceStart, sliceEnd);
22603
+
22604
+ if (chunk.outro && (!containsEnd || chunk.end === end)) {
22605
+ result += chunk.outro;
22606
+ }
22607
+
22608
+ if (containsEnd) {
22609
+ break;
22610
+ }
22611
+
22612
+ chunk = chunk.next;
22613
+ }
22614
+
22615
+ return result;
22616
+ }
22617
+
22618
+ // TODO deprecate this? not really very useful
22619
+ snip(start, end) {
22620
+ const clone = this.clone();
22621
+ clone.remove(0, start);
22622
+ clone.remove(end, clone.original.length);
22623
+
22624
+ return clone;
22625
+ }
22626
+
22627
+ _split(index) {
22628
+ if (this.byStart[index] || this.byEnd[index]) return;
22629
+
22630
+ let chunk = this.lastSearchedChunk;
22631
+ const searchForward = index > chunk.end;
22632
+
22633
+ while (chunk) {
22634
+ if (chunk.contains(index)) return this._splitChunk(chunk, index);
22635
+
22636
+ chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
22637
+ }
22638
+ }
22639
+
22640
+ _splitChunk(chunk, index) {
22641
+ if (chunk.edited && chunk.content.length) {
22642
+ // zero-length edited chunks are a special case (overlapping replacements)
22643
+ const loc = getLocator(this.original)(index);
22644
+ throw new Error(
22645
+ `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`,
22646
+ );
22647
+ }
22648
+
22649
+ const newChunk = chunk.split(index);
22650
+
22651
+ this.byEnd[index] = chunk;
22652
+ this.byStart[index] = newChunk;
22653
+ this.byEnd[newChunk.end] = newChunk;
22654
+
22655
+ if (chunk === this.lastChunk) this.lastChunk = newChunk;
22656
+
22657
+ this.lastSearchedChunk = chunk;
22658
+ return true;
22659
+ }
22660
+
22661
+ toString() {
22662
+ let str = this.intro;
22663
+
22664
+ let chunk = this.firstChunk;
22665
+ while (chunk) {
22666
+ str += chunk.toString();
22667
+ chunk = chunk.next;
22668
+ }
22669
+
22670
+ return str + this.outro;
22671
+ }
22672
+
22673
+ isEmpty() {
22674
+ let chunk = this.firstChunk;
22675
+ do {
22676
+ if (
22677
+ (chunk.intro.length && chunk.intro.trim()) ||
22678
+ (chunk.content.length && chunk.content.trim()) ||
22679
+ (chunk.outro.length && chunk.outro.trim())
22680
+ )
22681
+ return false;
22682
+ } while ((chunk = chunk.next));
22683
+ return true;
22684
+ }
22685
+
22686
+ length() {
22687
+ let chunk = this.firstChunk;
22688
+ let length = 0;
22689
+ do {
22690
+ length += chunk.intro.length + chunk.content.length + chunk.outro.length;
22691
+ } while ((chunk = chunk.next));
22692
+ return length;
22693
+ }
22694
+
22695
+ trimLines() {
22696
+ return this.trim('[\\r\\n]');
22697
+ }
22698
+
22699
+ trim(charType) {
22700
+ return this.trimStart(charType).trimEnd(charType);
22701
+ }
22702
+
22703
+ trimEndAborted(charType) {
22704
+ const rx = new RegExp((charType || '\\s') + '+$');
22705
+
22706
+ this.outro = this.outro.replace(rx, '');
22707
+ if (this.outro.length) return true;
22708
+
22709
+ let chunk = this.lastChunk;
22710
+
22711
+ do {
22712
+ const end = chunk.end;
22713
+ const aborted = chunk.trimEnd(rx);
22714
+
22715
+ // if chunk was trimmed, we have a new lastChunk
22716
+ if (chunk.end !== end) {
22717
+ if (this.lastChunk === chunk) {
22718
+ this.lastChunk = chunk.next;
22719
+ }
22720
+
22721
+ this.byEnd[chunk.end] = chunk;
22722
+ this.byStart[chunk.next.start] = chunk.next;
22723
+ this.byEnd[chunk.next.end] = chunk.next;
22724
+ }
22725
+
22726
+ if (aborted) return true;
22727
+ chunk = chunk.previous;
22728
+ } while (chunk);
22729
+
22730
+ return false;
22731
+ }
22732
+
22733
+ trimEnd(charType) {
22734
+ this.trimEndAborted(charType);
22735
+ return this;
22736
+ }
22737
+ trimStartAborted(charType) {
22738
+ const rx = new RegExp('^' + (charType || '\\s') + '+');
22739
+
22740
+ this.intro = this.intro.replace(rx, '');
22741
+ if (this.intro.length) return true;
22742
+
22743
+ let chunk = this.firstChunk;
22744
+
22745
+ do {
22746
+ const end = chunk.end;
22747
+ const aborted = chunk.trimStart(rx);
22748
+
22749
+ if (chunk.end !== end) {
22750
+ // special case...
22751
+ if (chunk === this.lastChunk) this.lastChunk = chunk.next;
22752
+
22753
+ this.byEnd[chunk.end] = chunk;
22754
+ this.byStart[chunk.next.start] = chunk.next;
22755
+ this.byEnd[chunk.next.end] = chunk.next;
22756
+ }
22757
+
22758
+ if (aborted) return true;
22759
+ chunk = chunk.next;
22760
+ } while (chunk);
22761
+
22762
+ return false;
22763
+ }
22764
+
22765
+ trimStart(charType) {
22766
+ this.trimStartAborted(charType);
22767
+ return this;
22768
+ }
22769
+
22770
+ hasChanged() {
22771
+ return this.original !== this.toString();
22772
+ }
22773
+
22774
+ _replaceRegexp(searchValue, replacement) {
22775
+ function getReplacement(match, str) {
22776
+ if (typeof replacement === 'string') {
22777
+ return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
22778
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
22779
+ if (i === '$') return '$';
22780
+ if (i === '&') return match[0];
22781
+ const num = +i;
22782
+ if (num < match.length) return match[+i];
22783
+ return `$${i}`;
22784
+ });
22785
+ } else {
22786
+ return replacement(...match, match.index, str, match.groups);
22787
+ }
22788
+ }
22789
+ function matchAll(re, str) {
22790
+ let match;
22791
+ const matches = [];
22792
+ while ((match = re.exec(str))) {
22793
+ matches.push(match);
22794
+ }
22795
+ return matches;
22796
+ }
22797
+ if (searchValue.global) {
22798
+ const matches = matchAll(searchValue, this.original);
22799
+ matches.forEach((match) => {
22800
+ if (match.index != null) {
22801
+ const replacement = getReplacement(match, this.original);
22802
+ if (replacement !== match[0]) {
22803
+ this.overwrite(
22804
+ match.index,
22805
+ match.index + match[0].length,
22806
+ replacement
22807
+ );
22808
+ }
22809
+ }
22810
+ });
22811
+ } else {
22812
+ const match = this.original.match(searchValue);
22813
+ if (match && match.index != null) {
22814
+ const replacement = getReplacement(match, this.original);
22815
+ if (replacement !== match[0]) {
22816
+ this.overwrite(
22817
+ match.index,
22818
+ match.index + match[0].length,
22819
+ replacement
22820
+ );
22821
+ }
22822
+ }
22823
+ }
22824
+ return this;
22825
+ }
22826
+
22827
+ _replaceString(string, replacement) {
22828
+ const { original } = this;
22829
+ const index = original.indexOf(string);
22830
+
22831
+ if (index !== -1) {
22832
+ this.overwrite(index, index + string.length, replacement);
22833
+ }
22834
+
22835
+ return this;
22836
+ }
22837
+
22838
+ replace(searchValue, replacement) {
22839
+ if (typeof searchValue === 'string') {
22840
+ return this._replaceString(searchValue, replacement);
22841
+ }
22842
+
22843
+ return this._replaceRegexp(searchValue, replacement);
22844
+ }
22845
+
22846
+ _replaceAllString(string, replacement) {
22847
+ const { original } = this;
22848
+ const stringLength = string.length;
22849
+ for (
22850
+ let index = original.indexOf(string);
22851
+ index !== -1;
22852
+ index = original.indexOf(string, index + stringLength)
22853
+ ) {
22854
+ const previous = original.slice(index, index + stringLength);
22855
+ if (previous !== replacement)
22856
+ this.overwrite(index, index + stringLength, replacement);
22857
+ }
22858
+
22859
+ return this;
22860
+ }
22861
+
22862
+ replaceAll(searchValue, replacement) {
22863
+ if (typeof searchValue === 'string') {
22864
+ return this._replaceAllString(searchValue, replacement);
22865
+ }
22866
+
22867
+ if (!searchValue.global) {
22868
+ throw new TypeError(
22869
+ 'MagicString.prototype.replaceAll called with a non-global RegExp argument',
22870
+ );
22871
+ }
22872
+
22873
+ return this._replaceRegexp(searchValue, replacement);
22874
+ }
22875
+ }
22876
+
21516
22877
  // Helper since Typescript can't detect readonly arrays with Array.isArray
21517
22878
  function isArray(arg) {
21518
22879
  return Array.isArray(arg);