@rstest/core 0.6.0 → 0.6.2

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