@amqp-contract/testing 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,1014 @@
1
+ //#region ../../node_modules/.pnpm/@jridgewell+sourcemap-codec@1.5.5/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.mjs
2
+ var comma = ",".charCodeAt(0);
3
+ var semicolon = ";".charCodeAt(0);
4
+ var chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
5
+ var intToChar = new Uint8Array(64);
6
+ var charToInt = new Uint8Array(128);
7
+ for (let i = 0; i < chars.length; i++) {
8
+ const c = chars.charCodeAt(i);
9
+ intToChar[i] = c;
10
+ charToInt[c] = i;
11
+ }
12
+ function encodeInteger(builder, num, relative) {
13
+ let delta = num - relative;
14
+ delta = delta < 0 ? -delta << 1 | 1 : delta << 1;
15
+ do {
16
+ let clamped = delta & 31;
17
+ delta >>>= 5;
18
+ if (delta > 0) clamped |= 32;
19
+ builder.write(intToChar[clamped]);
20
+ } while (delta > 0);
21
+ return num;
22
+ }
23
+ var bufLength = 1024 * 16;
24
+ var td = typeof TextDecoder !== "undefined" ? /* @__PURE__ */ new TextDecoder() : typeof Buffer !== "undefined" ? { decode(buf) {
25
+ return Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength).toString();
26
+ } } : { decode(buf) {
27
+ let out = "";
28
+ for (let i = 0; i < buf.length; i++) out += String.fromCharCode(buf[i]);
29
+ return out;
30
+ } };
31
+ var StringWriter = class {
32
+ constructor() {
33
+ this.pos = 0;
34
+ this.out = "";
35
+ this.buffer = new Uint8Array(bufLength);
36
+ }
37
+ write(v) {
38
+ const { buffer } = this;
39
+ buffer[this.pos++] = v;
40
+ if (this.pos === bufLength) {
41
+ this.out += td.decode(buffer);
42
+ this.pos = 0;
43
+ }
44
+ }
45
+ flush() {
46
+ const { buffer, out, pos } = this;
47
+ return pos > 0 ? out + td.decode(buffer.subarray(0, pos)) : out;
48
+ }
49
+ };
50
+ function encode(decoded) {
51
+ const writer = new StringWriter();
52
+ let sourcesIndex = 0;
53
+ let sourceLine = 0;
54
+ let sourceColumn = 0;
55
+ let namesIndex = 0;
56
+ for (let i = 0; i < decoded.length; i++) {
57
+ const line = decoded[i];
58
+ if (i > 0) writer.write(semicolon);
59
+ if (line.length === 0) continue;
60
+ let genColumn = 0;
61
+ for (let j = 0; j < line.length; j++) {
62
+ const segment = line[j];
63
+ if (j > 0) writer.write(comma);
64
+ genColumn = encodeInteger(writer, segment[0], genColumn);
65
+ if (segment.length === 1) continue;
66
+ sourcesIndex = encodeInteger(writer, segment[1], sourcesIndex);
67
+ sourceLine = encodeInteger(writer, segment[2], sourceLine);
68
+ sourceColumn = encodeInteger(writer, segment[3], sourceColumn);
69
+ if (segment.length === 4) continue;
70
+ namesIndex = encodeInteger(writer, segment[4], namesIndex);
71
+ }
72
+ }
73
+ return writer.flush();
74
+ }
75
+
76
+ //#endregion
77
+ //#region ../../node_modules/.pnpm/magic-string@0.30.21/node_modules/magic-string/dist/magic-string.es.mjs
78
+ var BitSet = class BitSet {
79
+ constructor(arg) {
80
+ this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
81
+ }
82
+ add(n$1) {
83
+ this.bits[n$1 >> 5] |= 1 << (n$1 & 31);
84
+ }
85
+ has(n$1) {
86
+ return !!(this.bits[n$1 >> 5] & 1 << (n$1 & 31));
87
+ }
88
+ };
89
+ var Chunk = class Chunk {
90
+ constructor(start, end, content) {
91
+ this.start = start;
92
+ this.end = end;
93
+ this.original = content;
94
+ this.intro = "";
95
+ this.outro = "";
96
+ this.content = content;
97
+ this.storeName = false;
98
+ this.edited = false;
99
+ this.previous = null;
100
+ this.next = null;
101
+ }
102
+ appendLeft(content) {
103
+ this.outro += content;
104
+ }
105
+ appendRight(content) {
106
+ this.intro = this.intro + content;
107
+ }
108
+ clone() {
109
+ const chunk = new Chunk(this.start, this.end, this.original);
110
+ chunk.intro = this.intro;
111
+ chunk.outro = this.outro;
112
+ chunk.content = this.content;
113
+ chunk.storeName = this.storeName;
114
+ chunk.edited = this.edited;
115
+ return chunk;
116
+ }
117
+ contains(index) {
118
+ return this.start < index && index < this.end;
119
+ }
120
+ eachNext(fn) {
121
+ let chunk = this;
122
+ while (chunk) {
123
+ fn(chunk);
124
+ chunk = chunk.next;
125
+ }
126
+ }
127
+ eachPrevious(fn) {
128
+ let chunk = this;
129
+ while (chunk) {
130
+ fn(chunk);
131
+ chunk = chunk.previous;
132
+ }
133
+ }
134
+ edit(content, storeName, contentOnly) {
135
+ this.content = content;
136
+ if (!contentOnly) {
137
+ this.intro = "";
138
+ this.outro = "";
139
+ }
140
+ this.storeName = storeName;
141
+ this.edited = true;
142
+ return this;
143
+ }
144
+ prependLeft(content) {
145
+ this.outro = content + this.outro;
146
+ }
147
+ prependRight(content) {
148
+ this.intro = content + this.intro;
149
+ }
150
+ reset() {
151
+ this.intro = "";
152
+ this.outro = "";
153
+ if (this.edited) {
154
+ this.content = this.original;
155
+ this.storeName = false;
156
+ this.edited = false;
157
+ }
158
+ }
159
+ split(index) {
160
+ const sliceIndex = index - this.start;
161
+ const originalBefore = this.original.slice(0, sliceIndex);
162
+ const originalAfter = this.original.slice(sliceIndex);
163
+ this.original = originalBefore;
164
+ const newChunk = new Chunk(index, this.end, originalAfter);
165
+ newChunk.outro = this.outro;
166
+ this.outro = "";
167
+ this.end = index;
168
+ if (this.edited) {
169
+ newChunk.edit("", false);
170
+ this.content = "";
171
+ } else this.content = originalBefore;
172
+ newChunk.next = this.next;
173
+ if (newChunk.next) newChunk.next.previous = newChunk;
174
+ newChunk.previous = this;
175
+ this.next = newChunk;
176
+ return newChunk;
177
+ }
178
+ toString() {
179
+ return this.intro + this.content + this.outro;
180
+ }
181
+ trimEnd(rx) {
182
+ this.outro = this.outro.replace(rx, "");
183
+ if (this.outro.length) return true;
184
+ const trimmed = this.content.replace(rx, "");
185
+ if (trimmed.length) {
186
+ if (trimmed !== this.content) {
187
+ this.split(this.start + trimmed.length).edit("", void 0, true);
188
+ if (this.edited) this.edit(trimmed, this.storeName, true);
189
+ }
190
+ return true;
191
+ } else {
192
+ this.edit("", void 0, true);
193
+ this.intro = this.intro.replace(rx, "");
194
+ if (this.intro.length) return true;
195
+ }
196
+ }
197
+ trimStart(rx) {
198
+ this.intro = this.intro.replace(rx, "");
199
+ if (this.intro.length) return true;
200
+ const trimmed = this.content.replace(rx, "");
201
+ if (trimmed.length) {
202
+ if (trimmed !== this.content) {
203
+ const newChunk = this.split(this.end - trimmed.length);
204
+ if (this.edited) newChunk.edit(trimmed, this.storeName, true);
205
+ this.edit("", void 0, true);
206
+ }
207
+ return true;
208
+ } else {
209
+ this.edit("", void 0, true);
210
+ this.outro = this.outro.replace(rx, "");
211
+ if (this.outro.length) return true;
212
+ }
213
+ }
214
+ };
215
+ function getBtoa() {
216
+ if (typeof globalThis !== "undefined" && typeof globalThis.btoa === "function") return (str) => globalThis.btoa(unescape(encodeURIComponent(str)));
217
+ else if (typeof Buffer === "function") return (str) => Buffer.from(str, "utf-8").toString("base64");
218
+ else return () => {
219
+ throw new Error("Unsupported environment: `window.btoa` or `Buffer` should be supported.");
220
+ };
221
+ }
222
+ const btoa = /* @__PURE__ */ getBtoa();
223
+ var SourceMap = class {
224
+ constructor(properties) {
225
+ this.version = 3;
226
+ this.file = properties.file;
227
+ this.sources = properties.sources;
228
+ this.sourcesContent = properties.sourcesContent;
229
+ this.names = properties.names;
230
+ this.mappings = encode(properties.mappings);
231
+ if (typeof properties.x_google_ignoreList !== "undefined") this.x_google_ignoreList = properties.x_google_ignoreList;
232
+ if (typeof properties.debugId !== "undefined") this.debugId = properties.debugId;
233
+ }
234
+ toString() {
235
+ return JSON.stringify(this);
236
+ }
237
+ toUrl() {
238
+ return "data:application/json;charset=utf-8;base64," + btoa(this.toString());
239
+ }
240
+ };
241
+ function guessIndent(code) {
242
+ const lines = code.split("\n");
243
+ const tabbed = lines.filter((line) => /^\t+/.test(line));
244
+ const spaced = lines.filter((line) => /^ {2,}/.test(line));
245
+ if (tabbed.length === 0 && spaced.length === 0) return null;
246
+ if (tabbed.length >= spaced.length) return " ";
247
+ const min = spaced.reduce((previous, current) => {
248
+ const numSpaces = /^ +/.exec(current)[0].length;
249
+ return Math.min(numSpaces, previous);
250
+ }, Infinity);
251
+ return new Array(min + 1).join(" ");
252
+ }
253
+ function getRelativePath(from, to) {
254
+ const fromParts = from.split(/[/\\]/);
255
+ const toParts = to.split(/[/\\]/);
256
+ fromParts.pop();
257
+ while (fromParts[0] === toParts[0]) {
258
+ fromParts.shift();
259
+ toParts.shift();
260
+ }
261
+ if (fromParts.length) {
262
+ let i = fromParts.length;
263
+ while (i--) fromParts[i] = "..";
264
+ }
265
+ return fromParts.concat(toParts).join("/");
266
+ }
267
+ const toString = Object.prototype.toString;
268
+ function isObject(thing) {
269
+ return toString.call(thing) === "[object Object]";
270
+ }
271
+ function getLocator(source) {
272
+ const originalLines = source.split("\n");
273
+ const lineOffsets = [];
274
+ for (let i = 0, pos = 0; i < originalLines.length; i++) {
275
+ lineOffsets.push(pos);
276
+ pos += originalLines[i].length + 1;
277
+ }
278
+ return function locate(index) {
279
+ let i = 0;
280
+ let j = lineOffsets.length;
281
+ while (i < j) {
282
+ const m = i + j >> 1;
283
+ if (index < lineOffsets[m]) j = m;
284
+ else i = m + 1;
285
+ }
286
+ const line = i - 1;
287
+ return {
288
+ line,
289
+ column: index - lineOffsets[line]
290
+ };
291
+ };
292
+ }
293
+ const wordRegex = /\w/;
294
+ var Mappings = class {
295
+ constructor(hires) {
296
+ this.hires = hires;
297
+ this.generatedCodeLine = 0;
298
+ this.generatedCodeColumn = 0;
299
+ this.raw = [];
300
+ this.rawSegments = this.raw[this.generatedCodeLine] = [];
301
+ this.pending = null;
302
+ }
303
+ addEdit(sourceIndex, content, loc, nameIndex) {
304
+ if (content.length) {
305
+ const contentLengthMinusOne = content.length - 1;
306
+ let contentLineEnd = content.indexOf("\n", 0);
307
+ let previousContentLineEnd = -1;
308
+ while (contentLineEnd >= 0 && contentLengthMinusOne > contentLineEnd) {
309
+ const segment$1 = [
310
+ this.generatedCodeColumn,
311
+ sourceIndex,
312
+ loc.line,
313
+ loc.column
314
+ ];
315
+ if (nameIndex >= 0) segment$1.push(nameIndex);
316
+ this.rawSegments.push(segment$1);
317
+ this.generatedCodeLine += 1;
318
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
319
+ this.generatedCodeColumn = 0;
320
+ previousContentLineEnd = contentLineEnd;
321
+ contentLineEnd = content.indexOf("\n", contentLineEnd + 1);
322
+ }
323
+ const segment = [
324
+ this.generatedCodeColumn,
325
+ sourceIndex,
326
+ loc.line,
327
+ loc.column
328
+ ];
329
+ if (nameIndex >= 0) segment.push(nameIndex);
330
+ this.rawSegments.push(segment);
331
+ this.advance(content.slice(previousContentLineEnd + 1));
332
+ } else if (this.pending) {
333
+ this.rawSegments.push(this.pending);
334
+ this.advance(content);
335
+ }
336
+ this.pending = null;
337
+ }
338
+ addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
339
+ let originalCharIndex = chunk.start;
340
+ let first = true;
341
+ let charInHiresBoundary = false;
342
+ while (originalCharIndex < chunk.end) {
343
+ if (original[originalCharIndex] === "\n") {
344
+ loc.line += 1;
345
+ loc.column = 0;
346
+ this.generatedCodeLine += 1;
347
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
348
+ this.generatedCodeColumn = 0;
349
+ first = true;
350
+ charInHiresBoundary = false;
351
+ } else {
352
+ if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
353
+ const segment = [
354
+ this.generatedCodeColumn,
355
+ sourceIndex,
356
+ loc.line,
357
+ loc.column
358
+ ];
359
+ if (this.hires === "boundary") if (wordRegex.test(original[originalCharIndex])) {
360
+ if (!charInHiresBoundary) {
361
+ this.rawSegments.push(segment);
362
+ charInHiresBoundary = true;
363
+ }
364
+ } else {
365
+ this.rawSegments.push(segment);
366
+ charInHiresBoundary = false;
367
+ }
368
+ else this.rawSegments.push(segment);
369
+ }
370
+ loc.column += 1;
371
+ this.generatedCodeColumn += 1;
372
+ first = false;
373
+ }
374
+ originalCharIndex += 1;
375
+ }
376
+ this.pending = null;
377
+ }
378
+ advance(str) {
379
+ if (!str) return;
380
+ const lines = str.split("\n");
381
+ if (lines.length > 1) {
382
+ for (let i = 0; i < lines.length - 1; i++) {
383
+ this.generatedCodeLine++;
384
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
385
+ }
386
+ this.generatedCodeColumn = 0;
387
+ }
388
+ this.generatedCodeColumn += lines[lines.length - 1].length;
389
+ }
390
+ };
391
+ const n = "\n";
392
+ const warned = {
393
+ insertLeft: false,
394
+ insertRight: false,
395
+ storeName: false
396
+ };
397
+ var MagicString = class MagicString {
398
+ constructor(string, options = {}) {
399
+ const chunk = new Chunk(0, string.length, string);
400
+ Object.defineProperties(this, {
401
+ original: {
402
+ writable: true,
403
+ value: string
404
+ },
405
+ outro: {
406
+ writable: true,
407
+ value: ""
408
+ },
409
+ intro: {
410
+ writable: true,
411
+ value: ""
412
+ },
413
+ firstChunk: {
414
+ writable: true,
415
+ value: chunk
416
+ },
417
+ lastChunk: {
418
+ writable: true,
419
+ value: chunk
420
+ },
421
+ lastSearchedChunk: {
422
+ writable: true,
423
+ value: chunk
424
+ },
425
+ byStart: {
426
+ writable: true,
427
+ value: {}
428
+ },
429
+ byEnd: {
430
+ writable: true,
431
+ value: {}
432
+ },
433
+ filename: {
434
+ writable: true,
435
+ value: options.filename
436
+ },
437
+ indentExclusionRanges: {
438
+ writable: true,
439
+ value: options.indentExclusionRanges
440
+ },
441
+ sourcemapLocations: {
442
+ writable: true,
443
+ value: new BitSet()
444
+ },
445
+ storedNames: {
446
+ writable: true,
447
+ value: {}
448
+ },
449
+ indentStr: {
450
+ writable: true,
451
+ value: void 0
452
+ },
453
+ ignoreList: {
454
+ writable: true,
455
+ value: options.ignoreList
456
+ },
457
+ offset: {
458
+ writable: true,
459
+ value: options.offset || 0
460
+ }
461
+ });
462
+ this.byStart[0] = chunk;
463
+ this.byEnd[string.length] = chunk;
464
+ }
465
+ addSourcemapLocation(char) {
466
+ this.sourcemapLocations.add(char);
467
+ }
468
+ append(content) {
469
+ if (typeof content !== "string") throw new TypeError("outro content must be a string");
470
+ this.outro += content;
471
+ return this;
472
+ }
473
+ appendLeft(index, content) {
474
+ index = index + this.offset;
475
+ if (typeof content !== "string") throw new TypeError("inserted content must be a string");
476
+ this._split(index);
477
+ const chunk = this.byEnd[index];
478
+ if (chunk) chunk.appendLeft(content);
479
+ else this.intro += content;
480
+ return this;
481
+ }
482
+ appendRight(index, content) {
483
+ index = index + this.offset;
484
+ if (typeof content !== "string") throw new TypeError("inserted content must be a string");
485
+ this._split(index);
486
+ const chunk = this.byStart[index];
487
+ if (chunk) chunk.appendRight(content);
488
+ else this.outro += content;
489
+ return this;
490
+ }
491
+ clone() {
492
+ const cloned = new MagicString(this.original, {
493
+ filename: this.filename,
494
+ offset: this.offset
495
+ });
496
+ let originalChunk = this.firstChunk;
497
+ let clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
498
+ while (originalChunk) {
499
+ cloned.byStart[clonedChunk.start] = clonedChunk;
500
+ cloned.byEnd[clonedChunk.end] = clonedChunk;
501
+ const nextOriginalChunk = originalChunk.next;
502
+ const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
503
+ if (nextClonedChunk) {
504
+ clonedChunk.next = nextClonedChunk;
505
+ nextClonedChunk.previous = clonedChunk;
506
+ clonedChunk = nextClonedChunk;
507
+ }
508
+ originalChunk = nextOriginalChunk;
509
+ }
510
+ cloned.lastChunk = clonedChunk;
511
+ if (this.indentExclusionRanges) cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
512
+ cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
513
+ cloned.intro = this.intro;
514
+ cloned.outro = this.outro;
515
+ return cloned;
516
+ }
517
+ generateDecodedMap(options) {
518
+ options = options || {};
519
+ const sourceIndex = 0;
520
+ const names = Object.keys(this.storedNames);
521
+ const mappings = new Mappings(options.hires);
522
+ const locate = getLocator(this.original);
523
+ if (this.intro) mappings.advance(this.intro);
524
+ this.firstChunk.eachNext((chunk) => {
525
+ const loc = locate(chunk.start);
526
+ if (chunk.intro.length) mappings.advance(chunk.intro);
527
+ if (chunk.edited) mappings.addEdit(sourceIndex, chunk.content, loc, chunk.storeName ? names.indexOf(chunk.original) : -1);
528
+ else mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
529
+ if (chunk.outro.length) mappings.advance(chunk.outro);
530
+ });
531
+ if (this.outro) mappings.advance(this.outro);
532
+ return {
533
+ file: options.file ? options.file.split(/[/\\]/).pop() : void 0,
534
+ sources: [options.source ? getRelativePath(options.file || "", options.source) : options.file || ""],
535
+ sourcesContent: options.includeContent ? [this.original] : void 0,
536
+ names,
537
+ mappings: mappings.raw,
538
+ x_google_ignoreList: this.ignoreList ? [sourceIndex] : void 0
539
+ };
540
+ }
541
+ generateMap(options) {
542
+ return new SourceMap(this.generateDecodedMap(options));
543
+ }
544
+ _ensureindentStr() {
545
+ if (this.indentStr === void 0) this.indentStr = guessIndent(this.original);
546
+ }
547
+ _getRawIndentString() {
548
+ this._ensureindentStr();
549
+ return this.indentStr;
550
+ }
551
+ getIndentString() {
552
+ this._ensureindentStr();
553
+ return this.indentStr === null ? " " : this.indentStr;
554
+ }
555
+ indent(indentStr, options) {
556
+ const pattern = /^[^\r\n]/gm;
557
+ if (isObject(indentStr)) {
558
+ options = indentStr;
559
+ indentStr = void 0;
560
+ }
561
+ if (indentStr === void 0) {
562
+ this._ensureindentStr();
563
+ indentStr = this.indentStr || " ";
564
+ }
565
+ if (indentStr === "") return this;
566
+ options = options || {};
567
+ const isExcluded = {};
568
+ if (options.exclude) (typeof options.exclude[0] === "number" ? [options.exclude] : options.exclude).forEach((exclusion) => {
569
+ for (let i = exclusion[0]; i < exclusion[1]; i += 1) isExcluded[i] = true;
570
+ });
571
+ let shouldIndentNextCharacter = options.indentStart !== false;
572
+ const replacer = (match) => {
573
+ if (shouldIndentNextCharacter) return `${indentStr}${match}`;
574
+ shouldIndentNextCharacter = true;
575
+ return match;
576
+ };
577
+ this.intro = this.intro.replace(pattern, replacer);
578
+ let charIndex = 0;
579
+ let chunk = this.firstChunk;
580
+ while (chunk) {
581
+ const end = chunk.end;
582
+ if (chunk.edited) {
583
+ if (!isExcluded[charIndex]) {
584
+ chunk.content = chunk.content.replace(pattern, replacer);
585
+ if (chunk.content.length) shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === "\n";
586
+ }
587
+ } else {
588
+ charIndex = chunk.start;
589
+ while (charIndex < end) {
590
+ if (!isExcluded[charIndex]) {
591
+ const char = this.original[charIndex];
592
+ if (char === "\n") shouldIndentNextCharacter = true;
593
+ else if (char !== "\r" && shouldIndentNextCharacter) {
594
+ shouldIndentNextCharacter = false;
595
+ if (charIndex === chunk.start) chunk.prependRight(indentStr);
596
+ else {
597
+ this._splitChunk(chunk, charIndex);
598
+ chunk = chunk.next;
599
+ chunk.prependRight(indentStr);
600
+ }
601
+ }
602
+ }
603
+ charIndex += 1;
604
+ }
605
+ }
606
+ charIndex = chunk.end;
607
+ chunk = chunk.next;
608
+ }
609
+ this.outro = this.outro.replace(pattern, replacer);
610
+ return this;
611
+ }
612
+ insert() {
613
+ throw new Error("magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)");
614
+ }
615
+ insertLeft(index, content) {
616
+ if (!warned.insertLeft) {
617
+ console.warn("magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead");
618
+ warned.insertLeft = true;
619
+ }
620
+ return this.appendLeft(index, content);
621
+ }
622
+ insertRight(index, content) {
623
+ if (!warned.insertRight) {
624
+ console.warn("magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead");
625
+ warned.insertRight = true;
626
+ }
627
+ return this.prependRight(index, content);
628
+ }
629
+ move(start, end, index) {
630
+ start = start + this.offset;
631
+ end = end + this.offset;
632
+ index = index + this.offset;
633
+ if (index >= start && index <= end) throw new Error("Cannot move a selection inside itself");
634
+ this._split(start);
635
+ this._split(end);
636
+ this._split(index);
637
+ const first = this.byStart[start];
638
+ const last = this.byEnd[end];
639
+ const oldLeft = first.previous;
640
+ const oldRight = last.next;
641
+ const newRight = this.byStart[index];
642
+ if (!newRight && last === this.lastChunk) return this;
643
+ const newLeft = newRight ? newRight.previous : this.lastChunk;
644
+ if (oldLeft) oldLeft.next = oldRight;
645
+ if (oldRight) oldRight.previous = oldLeft;
646
+ if (newLeft) newLeft.next = first;
647
+ if (newRight) newRight.previous = last;
648
+ if (!first.previous) this.firstChunk = last.next;
649
+ if (!last.next) {
650
+ this.lastChunk = first.previous;
651
+ this.lastChunk.next = null;
652
+ }
653
+ first.previous = newLeft;
654
+ last.next = newRight || null;
655
+ if (!newLeft) this.firstChunk = first;
656
+ if (!newRight) this.lastChunk = last;
657
+ return this;
658
+ }
659
+ overwrite(start, end, content, options) {
660
+ options = options || {};
661
+ return this.update(start, end, content, {
662
+ ...options,
663
+ overwrite: !options.contentOnly
664
+ });
665
+ }
666
+ update(start, end, content, options) {
667
+ start = start + this.offset;
668
+ end = end + this.offset;
669
+ if (typeof content !== "string") throw new TypeError("replacement content must be a string");
670
+ if (this.original.length !== 0) {
671
+ while (start < 0) start += this.original.length;
672
+ while (end < 0) end += this.original.length;
673
+ }
674
+ if (end > this.original.length) throw new Error("end is out of bounds");
675
+ if (start === end) throw new Error("Cannot overwrite a zero-length range – use appendLeft or prependRight instead");
676
+ this._split(start);
677
+ this._split(end);
678
+ if (options === true) {
679
+ if (!warned.storeName) {
680
+ console.warn("The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string");
681
+ warned.storeName = true;
682
+ }
683
+ options = { storeName: true };
684
+ }
685
+ const storeName = options !== void 0 ? options.storeName : false;
686
+ const overwrite = options !== void 0 ? options.overwrite : false;
687
+ if (storeName) {
688
+ const original = this.original.slice(start, end);
689
+ Object.defineProperty(this.storedNames, original, {
690
+ writable: true,
691
+ value: true,
692
+ enumerable: true
693
+ });
694
+ }
695
+ const first = this.byStart[start];
696
+ const last = this.byEnd[end];
697
+ if (first) {
698
+ let chunk = first;
699
+ while (chunk !== last) {
700
+ if (chunk.next !== this.byStart[chunk.end]) throw new Error("Cannot overwrite across a split point");
701
+ chunk = chunk.next;
702
+ chunk.edit("", false);
703
+ }
704
+ first.edit(content, storeName, !overwrite);
705
+ } else {
706
+ const newChunk = new Chunk(start, end, "").edit(content, storeName);
707
+ last.next = newChunk;
708
+ newChunk.previous = last;
709
+ }
710
+ return this;
711
+ }
712
+ prepend(content) {
713
+ if (typeof content !== "string") throw new TypeError("outro content must be a string");
714
+ this.intro = content + this.intro;
715
+ return this;
716
+ }
717
+ prependLeft(index, content) {
718
+ index = index + this.offset;
719
+ if (typeof content !== "string") throw new TypeError("inserted content must be a string");
720
+ this._split(index);
721
+ const chunk = this.byEnd[index];
722
+ if (chunk) chunk.prependLeft(content);
723
+ else this.intro = content + this.intro;
724
+ return this;
725
+ }
726
+ prependRight(index, content) {
727
+ index = index + this.offset;
728
+ if (typeof content !== "string") throw new TypeError("inserted content must be a string");
729
+ this._split(index);
730
+ const chunk = this.byStart[index];
731
+ if (chunk) chunk.prependRight(content);
732
+ else this.outro = content + this.outro;
733
+ return this;
734
+ }
735
+ remove(start, end) {
736
+ start = start + this.offset;
737
+ end = end + this.offset;
738
+ if (this.original.length !== 0) {
739
+ while (start < 0) start += this.original.length;
740
+ while (end < 0) end += this.original.length;
741
+ }
742
+ if (start === end) return this;
743
+ if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
744
+ if (start > end) throw new Error("end must be greater than start");
745
+ this._split(start);
746
+ this._split(end);
747
+ let chunk = this.byStart[start];
748
+ while (chunk) {
749
+ chunk.intro = "";
750
+ chunk.outro = "";
751
+ chunk.edit("");
752
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
753
+ }
754
+ return this;
755
+ }
756
+ reset(start, end) {
757
+ start = start + this.offset;
758
+ end = end + this.offset;
759
+ if (this.original.length !== 0) {
760
+ while (start < 0) start += this.original.length;
761
+ while (end < 0) end += this.original.length;
762
+ }
763
+ if (start === end) return this;
764
+ if (start < 0 || end > this.original.length) throw new Error("Character is out of bounds");
765
+ if (start > end) throw new Error("end must be greater than start");
766
+ this._split(start);
767
+ this._split(end);
768
+ let chunk = this.byStart[start];
769
+ while (chunk) {
770
+ chunk.reset();
771
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
772
+ }
773
+ return this;
774
+ }
775
+ lastChar() {
776
+ if (this.outro.length) return this.outro[this.outro.length - 1];
777
+ let chunk = this.lastChunk;
778
+ do {
779
+ if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
780
+ if (chunk.content.length) return chunk.content[chunk.content.length - 1];
781
+ if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
782
+ } while (chunk = chunk.previous);
783
+ if (this.intro.length) return this.intro[this.intro.length - 1];
784
+ return "";
785
+ }
786
+ lastLine() {
787
+ let lineIndex = this.outro.lastIndexOf(n);
788
+ if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
789
+ let lineStr = this.outro;
790
+ let chunk = this.lastChunk;
791
+ do {
792
+ if (chunk.outro.length > 0) {
793
+ lineIndex = chunk.outro.lastIndexOf(n);
794
+ if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
795
+ lineStr = chunk.outro + lineStr;
796
+ }
797
+ if (chunk.content.length > 0) {
798
+ lineIndex = chunk.content.lastIndexOf(n);
799
+ if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
800
+ lineStr = chunk.content + lineStr;
801
+ }
802
+ if (chunk.intro.length > 0) {
803
+ lineIndex = chunk.intro.lastIndexOf(n);
804
+ if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
805
+ lineStr = chunk.intro + lineStr;
806
+ }
807
+ } while (chunk = chunk.previous);
808
+ lineIndex = this.intro.lastIndexOf(n);
809
+ if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
810
+ return this.intro + lineStr;
811
+ }
812
+ slice(start = 0, end = this.original.length - this.offset) {
813
+ start = start + this.offset;
814
+ end = end + this.offset;
815
+ if (this.original.length !== 0) {
816
+ while (start < 0) start += this.original.length;
817
+ while (end < 0) end += this.original.length;
818
+ }
819
+ let result = "";
820
+ let chunk = this.firstChunk;
821
+ while (chunk && (chunk.start > start || chunk.end <= start)) {
822
+ if (chunk.start < end && chunk.end >= end) return result;
823
+ chunk = chunk.next;
824
+ }
825
+ if (chunk && chunk.edited && chunk.start !== start) throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
826
+ const startChunk = chunk;
827
+ while (chunk) {
828
+ if (chunk.intro && (startChunk !== chunk || chunk.start === start)) result += chunk.intro;
829
+ const containsEnd = chunk.start < end && chunk.end >= end;
830
+ if (containsEnd && chunk.edited && chunk.end !== end) throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
831
+ const sliceStart = startChunk === chunk ? start - chunk.start : 0;
832
+ const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
833
+ result += chunk.content.slice(sliceStart, sliceEnd);
834
+ if (chunk.outro && (!containsEnd || chunk.end === end)) result += chunk.outro;
835
+ if (containsEnd) break;
836
+ chunk = chunk.next;
837
+ }
838
+ return result;
839
+ }
840
+ snip(start, end) {
841
+ const clone = this.clone();
842
+ clone.remove(0, start);
843
+ clone.remove(end, clone.original.length);
844
+ return clone;
845
+ }
846
+ _split(index) {
847
+ if (this.byStart[index] || this.byEnd[index]) return;
848
+ let chunk = this.lastSearchedChunk;
849
+ let previousChunk = chunk;
850
+ const searchForward = index > chunk.end;
851
+ while (chunk) {
852
+ if (chunk.contains(index)) return this._splitChunk(chunk, index);
853
+ chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
854
+ if (chunk === previousChunk) return;
855
+ previousChunk = chunk;
856
+ }
857
+ }
858
+ _splitChunk(chunk, index) {
859
+ if (chunk.edited && chunk.content.length) {
860
+ const loc = getLocator(this.original)(index);
861
+ throw new Error(`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`);
862
+ }
863
+ const newChunk = chunk.split(index);
864
+ this.byEnd[index] = chunk;
865
+ this.byStart[index] = newChunk;
866
+ this.byEnd[newChunk.end] = newChunk;
867
+ if (chunk === this.lastChunk) this.lastChunk = newChunk;
868
+ this.lastSearchedChunk = chunk;
869
+ return true;
870
+ }
871
+ toString() {
872
+ let str = this.intro;
873
+ let chunk = this.firstChunk;
874
+ while (chunk) {
875
+ str += chunk.toString();
876
+ chunk = chunk.next;
877
+ }
878
+ return str + this.outro;
879
+ }
880
+ isEmpty() {
881
+ let chunk = this.firstChunk;
882
+ do
883
+ if (chunk.intro.length && chunk.intro.trim() || chunk.content.length && chunk.content.trim() || chunk.outro.length && chunk.outro.trim()) return false;
884
+ while (chunk = chunk.next);
885
+ return true;
886
+ }
887
+ length() {
888
+ let chunk = this.firstChunk;
889
+ let length = 0;
890
+ do
891
+ length += chunk.intro.length + chunk.content.length + chunk.outro.length;
892
+ while (chunk = chunk.next);
893
+ return length;
894
+ }
895
+ trimLines() {
896
+ return this.trim("[\\r\\n]");
897
+ }
898
+ trim(charType) {
899
+ return this.trimStart(charType).trimEnd(charType);
900
+ }
901
+ trimEndAborted(charType) {
902
+ const rx = /* @__PURE__ */ new RegExp((charType || "\\s") + "+$");
903
+ this.outro = this.outro.replace(rx, "");
904
+ if (this.outro.length) return true;
905
+ let chunk = this.lastChunk;
906
+ do {
907
+ const end = chunk.end;
908
+ const aborted = chunk.trimEnd(rx);
909
+ if (chunk.end !== end) {
910
+ if (this.lastChunk === chunk) this.lastChunk = chunk.next;
911
+ this.byEnd[chunk.end] = chunk;
912
+ this.byStart[chunk.next.start] = chunk.next;
913
+ this.byEnd[chunk.next.end] = chunk.next;
914
+ }
915
+ if (aborted) return true;
916
+ chunk = chunk.previous;
917
+ } while (chunk);
918
+ return false;
919
+ }
920
+ trimEnd(charType) {
921
+ this.trimEndAborted(charType);
922
+ return this;
923
+ }
924
+ trimStartAborted(charType) {
925
+ const rx = /* @__PURE__ */ new RegExp("^" + (charType || "\\s") + "+");
926
+ this.intro = this.intro.replace(rx, "");
927
+ if (this.intro.length) return true;
928
+ let chunk = this.firstChunk;
929
+ do {
930
+ const end = chunk.end;
931
+ const aborted = chunk.trimStart(rx);
932
+ if (chunk.end !== end) {
933
+ if (chunk === this.lastChunk) this.lastChunk = chunk.next;
934
+ this.byEnd[chunk.end] = chunk;
935
+ this.byStart[chunk.next.start] = chunk.next;
936
+ this.byEnd[chunk.next.end] = chunk.next;
937
+ }
938
+ if (aborted) return true;
939
+ chunk = chunk.next;
940
+ } while (chunk);
941
+ return false;
942
+ }
943
+ trimStart(charType) {
944
+ this.trimStartAborted(charType);
945
+ return this;
946
+ }
947
+ hasChanged() {
948
+ return this.original !== this.toString();
949
+ }
950
+ _replaceRegexp(searchValue, replacement) {
951
+ function getReplacement(match, str) {
952
+ if (typeof replacement === "string") return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
953
+ if (i === "$") return "$";
954
+ if (i === "&") return match[0];
955
+ if (+i < match.length) return match[+i];
956
+ return `$${i}`;
957
+ });
958
+ else return replacement(...match, match.index, str, match.groups);
959
+ }
960
+ function matchAll(re, str) {
961
+ let match;
962
+ const matches = [];
963
+ while (match = re.exec(str)) matches.push(match);
964
+ return matches;
965
+ }
966
+ if (searchValue.global) matchAll(searchValue, this.original).forEach((match) => {
967
+ if (match.index != null) {
968
+ const replacement$1 = getReplacement(match, this.original);
969
+ if (replacement$1 !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement$1);
970
+ }
971
+ });
972
+ else {
973
+ const match = this.original.match(searchValue);
974
+ if (match && match.index != null) {
975
+ const replacement$1 = getReplacement(match, this.original);
976
+ if (replacement$1 !== match[0]) this.overwrite(match.index, match.index + match[0].length, replacement$1);
977
+ }
978
+ }
979
+ return this;
980
+ }
981
+ _replaceString(string, replacement) {
982
+ const { original } = this;
983
+ const index = original.indexOf(string);
984
+ if (index !== -1) {
985
+ if (typeof replacement === "function") replacement = replacement(string, index, original);
986
+ if (string !== replacement) this.overwrite(index, index + string.length, replacement);
987
+ }
988
+ return this;
989
+ }
990
+ replace(searchValue, replacement) {
991
+ if (typeof searchValue === "string") return this._replaceString(searchValue, replacement);
992
+ return this._replaceRegexp(searchValue, replacement);
993
+ }
994
+ _replaceAllString(string, replacement) {
995
+ const { original } = this;
996
+ const stringLength = string.length;
997
+ for (let index = original.indexOf(string); index !== -1; index = original.indexOf(string, index + stringLength)) {
998
+ const previous = original.slice(index, index + stringLength);
999
+ let _replacement = replacement;
1000
+ if (typeof replacement === "function") _replacement = replacement(previous, index, original);
1001
+ if (previous !== _replacement) this.overwrite(index, index + stringLength, _replacement);
1002
+ }
1003
+ return this;
1004
+ }
1005
+ replaceAll(searchValue, replacement) {
1006
+ if (typeof searchValue === "string") return this._replaceAllString(searchValue, replacement);
1007
+ if (!searchValue.global) throw new TypeError("MagicString.prototype.replaceAll called with a non-global RegExp argument");
1008
+ return this._replaceRegexp(searchValue, replacement);
1009
+ }
1010
+ };
1011
+
1012
+ //#endregion
1013
+ export { MagicString as default };
1014
+ //# sourceMappingURL=magic-string.es-mfcqQQ0l.mjs.map