rollup 2.70.1 → 2.70.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.
@@ -1,7 +1,7 @@
1
1
  /*
2
2
  @license
3
- Rollup.js v2.70.1
4
- Mon, 14 Mar 2022 05:50:08 GMT - commit b8315e03f9790d610a413316fbf6d565f9340cab
3
+ Rollup.js v2.70.2
4
+ Fri, 15 Apr 2022 05:14:21 GMT - commit 030c56fd6b186a0ddfd57d143ad703f34fd2c17a
5
5
 
6
6
  https://github.com/rollup/rollup
7
7
 
@@ -14,7 +14,7 @@ import { createHash as createHash$1 } from 'crypto';
14
14
  import { promises } from 'fs';
15
15
  import { EventEmitter } from 'events';
16
16
 
17
- var version$1 = "2.70.1";
17
+ var version$1 = "2.70.2";
18
18
 
19
19
  var charToInteger = {};
20
20
  var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
@@ -138,204 +138,208 @@ function encodeInteger(num) {
138
138
  return result;
139
139
  }
140
140
 
141
- var BitSet = function BitSet(arg) {
142
- this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
143
- };
144
-
145
- BitSet.prototype.add = function add (n) {
146
- this.bits[n >> 5] |= 1 << (n & 31);
147
- };
141
+ class BitSet {
142
+ constructor(arg) {
143
+ this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
144
+ }
148
145
 
149
- BitSet.prototype.has = function has (n) {
150
- return !!(this.bits[n >> 5] & (1 << (n & 31)));
151
- };
146
+ add(n) {
147
+ this.bits[n >> 5] |= 1 << (n & 31);
148
+ }
152
149
 
153
- var Chunk$1 = function Chunk(start, end, content) {
154
- this.start = start;
155
- this.end = end;
156
- this.original = content;
150
+ has(n) {
151
+ return !!(this.bits[n >> 5] & (1 << (n & 31)));
152
+ }
153
+ }
157
154
 
158
- this.intro = '';
159
- this.outro = '';
155
+ class Chunk$1 {
156
+ constructor(start, end, content) {
157
+ this.start = start;
158
+ this.end = end;
159
+ this.original = content;
160
160
 
161
- this.content = content;
162
- this.storeName = false;
163
- this.edited = false;
161
+ this.intro = '';
162
+ this.outro = '';
164
163
 
165
- // we make these non-enumerable, for sanity while debugging
166
- Object.defineProperties(this, {
167
- previous: { writable: true, value: null },
168
- next: { writable: true, value: null }
169
- });
170
- };
164
+ this.content = content;
165
+ this.storeName = false;
166
+ this.edited = false;
171
167
 
172
- Chunk$1.prototype.appendLeft = function appendLeft (content) {
173
- this.outro += content;
174
- };
168
+ // we make these non-enumerable, for sanity while debugging
169
+ Object.defineProperties(this, {
170
+ previous: { writable: true, value: null },
171
+ next: { writable: true, value: null },
172
+ });
173
+ }
175
174
 
176
- Chunk$1.prototype.appendRight = function appendRight (content) {
177
- this.intro = this.intro + content;
178
- };
175
+ appendLeft(content) {
176
+ this.outro += content;
177
+ }
179
178
 
180
- Chunk$1.prototype.clone = function clone () {
181
- var chunk = new Chunk$1(this.start, this.end, this.original);
179
+ appendRight(content) {
180
+ this.intro = this.intro + content;
181
+ }
182
182
 
183
- chunk.intro = this.intro;
184
- chunk.outro = this.outro;
185
- chunk.content = this.content;
186
- chunk.storeName = this.storeName;
187
- chunk.edited = this.edited;
183
+ clone() {
184
+ const chunk = new Chunk$1(this.start, this.end, this.original);
188
185
 
189
- return chunk;
190
- };
186
+ chunk.intro = this.intro;
187
+ chunk.outro = this.outro;
188
+ chunk.content = this.content;
189
+ chunk.storeName = this.storeName;
190
+ chunk.edited = this.edited;
191
191
 
192
- Chunk$1.prototype.contains = function contains (index) {
193
- return this.start < index && index < this.end;
194
- };
192
+ return chunk;
193
+ }
195
194
 
196
- Chunk$1.prototype.eachNext = function eachNext (fn) {
197
- var chunk = this;
198
- while (chunk) {
199
- fn(chunk);
200
- chunk = chunk.next;
195
+ contains(index) {
196
+ return this.start < index && index < this.end;
201
197
  }
202
- };
203
198
 
204
- Chunk$1.prototype.eachPrevious = function eachPrevious (fn) {
205
- var chunk = this;
206
- while (chunk) {
207
- fn(chunk);
208
- chunk = chunk.previous;
199
+ eachNext(fn) {
200
+ let chunk = this;
201
+ while (chunk) {
202
+ fn(chunk);
203
+ chunk = chunk.next;
204
+ }
209
205
  }
210
- };
211
206
 
212
- Chunk$1.prototype.edit = function edit (content, storeName, contentOnly) {
213
- this.content = content;
214
- if (!contentOnly) {
215
- this.intro = '';
216
- this.outro = '';
207
+ eachPrevious(fn) {
208
+ let chunk = this;
209
+ while (chunk) {
210
+ fn(chunk);
211
+ chunk = chunk.previous;
212
+ }
217
213
  }
218
- this.storeName = storeName;
219
214
 
220
- this.edited = true;
215
+ edit(content, storeName, contentOnly) {
216
+ this.content = content;
217
+ if (!contentOnly) {
218
+ this.intro = '';
219
+ this.outro = '';
220
+ }
221
+ this.storeName = storeName;
221
222
 
222
- return this;
223
- };
223
+ this.edited = true;
224
224
 
225
- Chunk$1.prototype.prependLeft = function prependLeft (content) {
226
- this.outro = content + this.outro;
227
- };
225
+ return this;
226
+ }
228
227
 
229
- Chunk$1.prototype.prependRight = function prependRight (content) {
230
- this.intro = content + this.intro;
231
- };
228
+ prependLeft(content) {
229
+ this.outro = content + this.outro;
230
+ }
232
231
 
233
- Chunk$1.prototype.split = function split (index) {
234
- var sliceIndex = index - this.start;
232
+ prependRight(content) {
233
+ this.intro = content + this.intro;
234
+ }
235
235
 
236
- var originalBefore = this.original.slice(0, sliceIndex);
237
- var originalAfter = this.original.slice(sliceIndex);
236
+ split(index) {
237
+ const sliceIndex = index - this.start;
238
238
 
239
- this.original = originalBefore;
239
+ const originalBefore = this.original.slice(0, sliceIndex);
240
+ const originalAfter = this.original.slice(sliceIndex);
240
241
 
241
- var newChunk = new Chunk$1(index, this.end, originalAfter);
242
- newChunk.outro = this.outro;
243
- this.outro = '';
242
+ this.original = originalBefore;
244
243
 
245
- this.end = index;
244
+ const newChunk = new Chunk$1(index, this.end, originalAfter);
245
+ newChunk.outro = this.outro;
246
+ this.outro = '';
246
247
 
247
- if (this.edited) {
248
- // TODO is this block necessary?...
249
- newChunk.edit('', false);
250
- this.content = '';
251
- } else {
252
- this.content = originalBefore;
253
- }
248
+ this.end = index;
254
249
 
255
- newChunk.next = this.next;
256
- if (newChunk.next) { newChunk.next.previous = newChunk; }
257
- newChunk.previous = this;
258
- this.next = newChunk;
250
+ if (this.edited) {
251
+ // TODO is this block necessary?...
252
+ newChunk.edit('', false);
253
+ this.content = '';
254
+ } else {
255
+ this.content = originalBefore;
256
+ }
259
257
 
260
- return newChunk;
261
- };
258
+ newChunk.next = this.next;
259
+ if (newChunk.next) newChunk.next.previous = newChunk;
260
+ newChunk.previous = this;
261
+ this.next = newChunk;
262
262
 
263
- Chunk$1.prototype.toString = function toString () {
264
- return this.intro + this.content + this.outro;
265
- };
263
+ return newChunk;
264
+ }
266
265
 
267
- Chunk$1.prototype.trimEnd = function trimEnd (rx) {
268
- this.outro = this.outro.replace(rx, '');
269
- if (this.outro.length) { return true; }
266
+ toString() {
267
+ return this.intro + this.content + this.outro;
268
+ }
270
269
 
271
- var trimmed = this.content.replace(rx, '');
270
+ trimEnd(rx) {
271
+ this.outro = this.outro.replace(rx, '');
272
+ if (this.outro.length) return true;
272
273
 
273
- if (trimmed.length) {
274
- if (trimmed !== this.content) {
275
- this.split(this.start + trimmed.length).edit('', undefined, true);
276
- }
277
- return true;
274
+ const trimmed = this.content.replace(rx, '');
278
275
 
279
- } else {
280
- this.edit('', undefined, true);
276
+ if (trimmed.length) {
277
+ if (trimmed !== this.content) {
278
+ this.split(this.start + trimmed.length).edit('', undefined, true);
279
+ }
280
+ return true;
281
+ } else {
282
+ this.edit('', undefined, true);
281
283
 
282
- this.intro = this.intro.replace(rx, '');
283
- if (this.intro.length) { return true; }
284
+ this.intro = this.intro.replace(rx, '');
285
+ if (this.intro.length) return true;
286
+ }
284
287
  }
285
- };
286
288
 
287
- Chunk$1.prototype.trimStart = function trimStart (rx) {
288
- this.intro = this.intro.replace(rx, '');
289
- if (this.intro.length) { return true; }
289
+ trimStart(rx) {
290
+ this.intro = this.intro.replace(rx, '');
291
+ if (this.intro.length) return true;
290
292
 
291
- var trimmed = this.content.replace(rx, '');
293
+ const trimmed = this.content.replace(rx, '');
292
294
 
293
- if (trimmed.length) {
294
- if (trimmed !== this.content) {
295
- this.split(this.end - trimmed.length);
295
+ if (trimmed.length) {
296
+ if (trimmed !== this.content) {
297
+ this.split(this.end - trimmed.length);
298
+ this.edit('', undefined, true);
299
+ }
300
+ return true;
301
+ } else {
296
302
  this.edit('', undefined, true);
297
- }
298
- return true;
299
-
300
- } else {
301
- this.edit('', undefined, true);
302
303
 
303
- this.outro = this.outro.replace(rx, '');
304
- if (this.outro.length) { return true; }
304
+ this.outro = this.outro.replace(rx, '');
305
+ if (this.outro.length) return true;
306
+ }
305
307
  }
306
- };
308
+ }
307
309
 
308
- var btoa = function () {
310
+ let btoa = () => {
309
311
  throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
310
312
  };
311
313
  if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
312
- btoa = function (str) { return window.btoa(unescape(encodeURIComponent(str))); };
314
+ btoa = (str) => window.btoa(unescape(encodeURIComponent(str)));
313
315
  } else if (typeof Buffer === 'function') {
314
- btoa = function (str) { return Buffer.from(str, 'utf-8').toString('base64'); };
316
+ btoa = (str) => Buffer.from(str, 'utf-8').toString('base64');
315
317
  }
316
318
 
317
- var SourceMap = function SourceMap(properties) {
318
- this.version = 3;
319
- this.file = properties.file;
320
- this.sources = properties.sources;
321
- this.sourcesContent = properties.sourcesContent;
322
- this.names = properties.names;
323
- this.mappings = encode(properties.mappings);
324
- };
319
+ class SourceMap {
320
+ constructor(properties) {
321
+ this.version = 3;
322
+ this.file = properties.file;
323
+ this.sources = properties.sources;
324
+ this.sourcesContent = properties.sourcesContent;
325
+ this.names = properties.names;
326
+ this.mappings = encode(properties.mappings);
327
+ }
325
328
 
326
- SourceMap.prototype.toString = function toString () {
327
- return JSON.stringify(this);
328
- };
329
+ toString() {
330
+ return JSON.stringify(this);
331
+ }
329
332
 
330
- SourceMap.prototype.toUrl = function toUrl () {
331
- return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
332
- };
333
+ toUrl() {
334
+ return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
335
+ }
336
+ }
333
337
 
334
338
  function guessIndent(code) {
335
- var lines = code.split('\n');
339
+ const lines = code.split('\n');
336
340
 
337
- var tabbed = lines.filter(function (line) { return /^\t+/.test(line); });
338
- var spaced = lines.filter(function (line) { return /^ {2,}/.test(line); });
341
+ const tabbed = lines.filter((line) => /^\t+/.test(line));
342
+ const spaced = lines.filter((line) => /^ {2,}/.test(line));
339
343
 
340
344
  if (tabbed.length === 0 && spaced.length === 0) {
341
345
  return null;
@@ -349,8 +353,8 @@ function guessIndent(code) {
349
353
  }
350
354
 
351
355
  // Otherwise, we need to guess the multiple
352
- var min = spaced.reduce(function (previous, current) {
353
- var numSpaces = /^ +/.exec(current)[0].length;
356
+ const min = spaced.reduce((previous, current) => {
357
+ const numSpaces = /^ +/.exec(current)[0].length;
354
358
  return Math.min(numSpaces, previous);
355
359
  }, Infinity);
356
360
 
@@ -358,8 +362,8 @@ function guessIndent(code) {
358
362
  }
359
363
 
360
364
  function getRelativePath(from, to) {
361
- var fromParts = from.split(/[/\\]/);
362
- var toParts = to.split(/[/\\]/);
365
+ const fromParts = from.split(/[/\\]/);
366
+ const toParts = to.split(/[/\\]/);
363
367
 
364
368
  fromParts.pop(); // get dirname
365
369
 
@@ -369,1079 +373,1120 @@ function getRelativePath(from, to) {
369
373
  }
370
374
 
371
375
  if (fromParts.length) {
372
- var i = fromParts.length;
373
- while (i--) { fromParts[i] = '..'; }
376
+ let i = fromParts.length;
377
+ while (i--) fromParts[i] = '..';
374
378
  }
375
379
 
376
380
  return fromParts.concat(toParts).join('/');
377
381
  }
378
382
 
379
- var toString$1 = Object.prototype.toString;
383
+ const toString$1 = Object.prototype.toString;
380
384
 
381
385
  function isObject$1(thing) {
382
386
  return toString$1.call(thing) === '[object Object]';
383
387
  }
384
388
 
385
389
  function getLocator$1(source) {
386
- var originalLines = source.split('\n');
387
- var lineOffsets = [];
390
+ const originalLines = source.split('\n');
391
+ const lineOffsets = [];
388
392
 
389
- for (var i = 0, pos = 0; i < originalLines.length; i++) {
393
+ for (let i = 0, pos = 0; i < originalLines.length; i++) {
390
394
  lineOffsets.push(pos);
391
395
  pos += originalLines[i].length + 1;
392
396
  }
393
397
 
394
398
  return function locate(index) {
395
- var i = 0;
396
- var j = lineOffsets.length;
399
+ let i = 0;
400
+ let j = lineOffsets.length;
397
401
  while (i < j) {
398
- var m = (i + j) >> 1;
402
+ const m = (i + j) >> 1;
399
403
  if (index < lineOffsets[m]) {
400
404
  j = m;
401
405
  } else {
402
406
  i = m + 1;
403
407
  }
404
408
  }
405
- var line = i - 1;
406
- var column = index - lineOffsets[line];
407
- return { line: line, column: column };
409
+ const line = i - 1;
410
+ const column = index - lineOffsets[line];
411
+ return { line, column };
408
412
  };
409
413
  }
410
414
 
411
- var Mappings = function Mappings(hires) {
412
- this.hires = hires;
413
- this.generatedCodeLine = 0;
414
- this.generatedCodeColumn = 0;
415
- this.raw = [];
416
- this.rawSegments = this.raw[this.generatedCodeLine] = [];
417
- this.pending = null;
418
- };
415
+ class Mappings {
416
+ constructor(hires) {
417
+ this.hires = hires;
418
+ this.generatedCodeLine = 0;
419
+ this.generatedCodeColumn = 0;
420
+ this.raw = [];
421
+ this.rawSegments = this.raw[this.generatedCodeLine] = [];
422
+ this.pending = null;
423
+ }
419
424
 
420
- Mappings.prototype.addEdit = function addEdit (sourceIndex, content, loc, nameIndex) {
421
- if (content.length) {
422
- var segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
423
- if (nameIndex >= 0) {
424
- segment.push(nameIndex);
425
+ addEdit(sourceIndex, content, loc, nameIndex) {
426
+ if (content.length) {
427
+ const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
428
+ if (nameIndex >= 0) {
429
+ segment.push(nameIndex);
430
+ }
431
+ this.rawSegments.push(segment);
432
+ } else if (this.pending) {
433
+ this.rawSegments.push(this.pending);
425
434
  }
426
- this.rawSegments.push(segment);
427
- } else if (this.pending) {
428
- this.rawSegments.push(this.pending);
435
+
436
+ this.advance(content);
437
+ this.pending = null;
429
438
  }
430
439
 
431
- this.advance(content);
432
- this.pending = null;
433
- };
440
+ addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
441
+ let originalCharIndex = chunk.start;
442
+ let first = true;
434
443
 
435
- Mappings.prototype.addUneditedChunk = function addUneditedChunk (sourceIndex, chunk, original, loc, sourcemapLocations) {
436
- var originalCharIndex = chunk.start;
437
- var first = true;
444
+ while (originalCharIndex < chunk.end) {
445
+ if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
446
+ this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
447
+ }
438
448
 
439
- while (originalCharIndex < chunk.end) {
440
- if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
441
- this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
442
- }
449
+ if (original[originalCharIndex] === '\n') {
450
+ loc.line += 1;
451
+ loc.column = 0;
452
+ this.generatedCodeLine += 1;
453
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
454
+ this.generatedCodeColumn = 0;
455
+ first = true;
456
+ } else {
457
+ loc.column += 1;
458
+ this.generatedCodeColumn += 1;
459
+ first = false;
460
+ }
443
461
 
444
- if (original[originalCharIndex] === '\n') {
445
- loc.line += 1;
446
- loc.column = 0;
447
- this.generatedCodeLine += 1;
448
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
449
- this.generatedCodeColumn = 0;
450
- first = true;
451
- } else {
452
- loc.column += 1;
453
- this.generatedCodeColumn += 1;
454
- first = false;
462
+ originalCharIndex += 1;
455
463
  }
456
464
 
457
- originalCharIndex += 1;
465
+ this.pending = null;
458
466
  }
459
467
 
460
- this.pending = null;
461
- };
462
-
463
- Mappings.prototype.advance = function advance (str) {
464
- if (!str) { return; }
468
+ advance(str) {
469
+ if (!str) return;
465
470
 
466
- var lines = str.split('\n');
471
+ const lines = str.split('\n');
467
472
 
468
- if (lines.length > 1) {
469
- for (var i = 0; i < lines.length - 1; i++) {
470
- this.generatedCodeLine++;
471
- this.raw[this.generatedCodeLine] = this.rawSegments = [];
473
+ if (lines.length > 1) {
474
+ for (let i = 0; i < lines.length - 1; i++) {
475
+ this.generatedCodeLine++;
476
+ this.raw[this.generatedCodeLine] = this.rawSegments = [];
477
+ }
478
+ this.generatedCodeColumn = 0;
472
479
  }
473
- this.generatedCodeColumn = 0;
474
- }
475
480
 
476
- this.generatedCodeColumn += lines[lines.length - 1].length;
477
- };
481
+ this.generatedCodeColumn += lines[lines.length - 1].length;
482
+ }
483
+ }
478
484
 
479
- var n = '\n';
485
+ const n = '\n';
480
486
 
481
- var warned = {
487
+ const warned = {
482
488
  insertLeft: false,
483
489
  insertRight: false,
484
- storeName: false
485
- };
486
-
487
- var MagicString = function MagicString(string, options) {
488
- if ( options === void 0 ) options = {};
489
-
490
- var chunk = new Chunk$1(0, string.length, string);
491
-
492
- Object.defineProperties(this, {
493
- original: { writable: true, value: string },
494
- outro: { writable: true, value: '' },
495
- intro: { writable: true, value: '' },
496
- firstChunk: { writable: true, value: chunk },
497
- lastChunk: { writable: true, value: chunk },
498
- lastSearchedChunk: { writable: true, value: chunk },
499
- byStart: { writable: true, value: {} },
500
- byEnd: { writable: true, value: {} },
501
- filename: { writable: true, value: options.filename },
502
- indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
503
- sourcemapLocations: { writable: true, value: new BitSet() },
504
- storedNames: { writable: true, value: {} },
505
- indentStr: { writable: true, value: guessIndent(string) }
506
- });
507
-
508
- this.byStart[0] = chunk;
509
- this.byEnd[string.length] = chunk;
510
- };
511
-
512
- MagicString.prototype.addSourcemapLocation = function addSourcemapLocation (char) {
513
- this.sourcemapLocations.add(char);
514
- };
515
-
516
- MagicString.prototype.append = function append (content) {
517
- if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
518
-
519
- this.outro += content;
520
- return this;
521
- };
490
+ storeName: false,
491
+ };
492
+
493
+ class MagicString {
494
+ constructor(string, options = {}) {
495
+ const chunk = new Chunk$1(0, string.length, string);
496
+
497
+ Object.defineProperties(this, {
498
+ original: { writable: true, value: string },
499
+ outro: { writable: true, value: '' },
500
+ intro: { writable: true, value: '' },
501
+ firstChunk: { writable: true, value: chunk },
502
+ lastChunk: { writable: true, value: chunk },
503
+ lastSearchedChunk: { writable: true, value: chunk },
504
+ byStart: { writable: true, value: {} },
505
+ byEnd: { writable: true, value: {} },
506
+ filename: { writable: true, value: options.filename },
507
+ indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
508
+ sourcemapLocations: { writable: true, value: new BitSet() },
509
+ storedNames: { writable: true, value: {} },
510
+ indentStr: { writable: true, value: guessIndent(string) },
511
+ });
522
512
 
523
- MagicString.prototype.appendLeft = function appendLeft (index, content) {
524
- if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
513
+ this.byStart[0] = chunk;
514
+ this.byEnd[string.length] = chunk;
515
+ }
525
516
 
526
- this._split(index);
517
+ addSourcemapLocation(char) {
518
+ this.sourcemapLocations.add(char);
519
+ }
527
520
 
528
- var chunk = this.byEnd[index];
521
+ append(content) {
522
+ if (typeof content !== 'string') throw new TypeError('outro content must be a string');
529
523
 
530
- if (chunk) {
531
- chunk.appendLeft(content);
532
- } else {
533
- this.intro += content;
524
+ this.outro += content;
525
+ return this;
534
526
  }
535
- return this;
536
- };
537
527
 
538
- MagicString.prototype.appendRight = function appendRight (index, content) {
539
- if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
528
+ appendLeft(index, content) {
529
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
540
530
 
541
- this._split(index);
531
+ this._split(index);
542
532
 
543
- var chunk = this.byStart[index];
533
+ const chunk = this.byEnd[index];
544
534
 
545
- if (chunk) {
546
- chunk.appendRight(content);
547
- } else {
548
- this.outro += content;
535
+ if (chunk) {
536
+ chunk.appendLeft(content);
537
+ } else {
538
+ this.intro += content;
539
+ }
540
+ return this;
549
541
  }
550
- return this;
551
- };
552
-
553
- MagicString.prototype.clone = function clone () {
554
- var cloned = new MagicString(this.original, { filename: this.filename });
555
-
556
- var originalChunk = this.firstChunk;
557
- var clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
558
542
 
559
- while (originalChunk) {
560
- cloned.byStart[clonedChunk.start] = clonedChunk;
561
- cloned.byEnd[clonedChunk.end] = clonedChunk;
543
+ appendRight(index, content) {
544
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
562
545
 
563
- var nextOriginalChunk = originalChunk.next;
564
- var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
546
+ this._split(index);
565
547
 
566
- if (nextClonedChunk) {
567
- clonedChunk.next = nextClonedChunk;
568
- nextClonedChunk.previous = clonedChunk;
548
+ const chunk = this.byStart[index];
569
549
 
570
- clonedChunk = nextClonedChunk;
550
+ if (chunk) {
551
+ chunk.appendRight(content);
552
+ } else {
553
+ this.outro += content;
571
554
  }
572
-
573
- originalChunk = nextOriginalChunk;
555
+ return this;
574
556
  }
575
557
 
576
- cloned.lastChunk = clonedChunk;
558
+ clone() {
559
+ const cloned = new MagicString(this.original, { filename: this.filename });
577
560
 
578
- if (this.indentExclusionRanges) {
579
- cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
580
- }
561
+ let originalChunk = this.firstChunk;
562
+ let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
581
563
 
582
- cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
564
+ while (originalChunk) {
565
+ cloned.byStart[clonedChunk.start] = clonedChunk;
566
+ cloned.byEnd[clonedChunk.end] = clonedChunk;
583
567
 
584
- cloned.intro = this.intro;
585
- cloned.outro = this.outro;
568
+ const nextOriginalChunk = originalChunk.next;
569
+ const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
586
570
 
587
- return cloned;
588
- };
571
+ if (nextClonedChunk) {
572
+ clonedChunk.next = nextClonedChunk;
573
+ nextClonedChunk.previous = clonedChunk;
589
574
 
590
- MagicString.prototype.generateDecodedMap = function generateDecodedMap (options) {
591
- var this$1$1 = this;
575
+ clonedChunk = nextClonedChunk;
576
+ }
592
577
 
593
- options = options || {};
578
+ originalChunk = nextOriginalChunk;
579
+ }
594
580
 
595
- var sourceIndex = 0;
596
- var names = Object.keys(this.storedNames);
597
- var mappings = new Mappings(options.hires);
581
+ cloned.lastChunk = clonedChunk;
598
582
 
599
- var locate = getLocator$1(this.original);
583
+ if (this.indentExclusionRanges) {
584
+ cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
585
+ }
586
+
587
+ cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
588
+
589
+ cloned.intro = this.intro;
590
+ cloned.outro = this.outro;
600
591
 
601
- if (this.intro) {
602
- mappings.advance(this.intro);
592
+ return cloned;
603
593
  }
604
594
 
605
- this.firstChunk.eachNext(function (chunk) {
606
- var loc = locate(chunk.start);
595
+ generateDecodedMap(options) {
596
+ options = options || {};
607
597
 
608
- if (chunk.intro.length) { mappings.advance(chunk.intro); }
598
+ const sourceIndex = 0;
599
+ const names = Object.keys(this.storedNames);
600
+ const mappings = new Mappings(options.hires);
609
601
 
610
- if (chunk.edited) {
611
- mappings.addEdit(
612
- sourceIndex,
613
- chunk.content,
614
- loc,
615
- chunk.storeName ? names.indexOf(chunk.original) : -1
616
- );
617
- } else {
618
- mappings.addUneditedChunk(sourceIndex, chunk, this$1$1.original, loc, this$1$1.sourcemapLocations);
602
+ const locate = getLocator$1(this.original);
603
+
604
+ if (this.intro) {
605
+ mappings.advance(this.intro);
619
606
  }
620
607
 
621
- if (chunk.outro.length) { mappings.advance(chunk.outro); }
622
- });
608
+ this.firstChunk.eachNext((chunk) => {
609
+ const loc = locate(chunk.start);
623
610
 
624
- return {
625
- file: options.file ? options.file.split(/[/\\]/).pop() : null,
626
- sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
627
- sourcesContent: options.includeContent ? [this.original] : [null],
628
- names: names,
629
- mappings: mappings.raw
630
- };
631
- };
611
+ if (chunk.intro.length) mappings.advance(chunk.intro);
632
612
 
633
- MagicString.prototype.generateMap = function generateMap (options) {
634
- return new SourceMap(this.generateDecodedMap(options));
635
- };
613
+ if (chunk.edited) {
614
+ mappings.addEdit(
615
+ sourceIndex,
616
+ chunk.content,
617
+ loc,
618
+ chunk.storeName ? names.indexOf(chunk.original) : -1
619
+ );
620
+ } else {
621
+ mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
622
+ }
636
623
 
637
- MagicString.prototype.getIndentString = function getIndentString () {
638
- return this.indentStr === null ? '\t' : this.indentStr;
639
- };
624
+ if (chunk.outro.length) mappings.advance(chunk.outro);
625
+ });
640
626
 
641
- MagicString.prototype.indent = function indent (indentStr, options) {
642
- var pattern = /^[^\r\n]/gm;
627
+ return {
628
+ file: options.file ? options.file.split(/[/\\]/).pop() : null,
629
+ sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
630
+ sourcesContent: options.includeContent ? [this.original] : [null],
631
+ names,
632
+ mappings: mappings.raw,
633
+ };
634
+ }
643
635
 
644
- if (isObject$1(indentStr)) {
645
- options = indentStr;
646
- indentStr = undefined;
636
+ generateMap(options) {
637
+ return new SourceMap(this.generateDecodedMap(options));
647
638
  }
648
639
 
649
- indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
640
+ getIndentString() {
641
+ return this.indentStr === null ? '\t' : this.indentStr;
642
+ }
650
643
 
651
- if (indentStr === '') { return this; } // noop
644
+ indent(indentStr, options) {
645
+ const pattern = /^[^\r\n]/gm;
652
646
 
653
- options = options || {};
647
+ if (isObject$1(indentStr)) {
648
+ options = indentStr;
649
+ indentStr = undefined;
650
+ }
654
651
 
655
- // Process exclusion ranges
656
- var isExcluded = {};
652
+ indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
657
653
 
658
- if (options.exclude) {
659
- var exclusions =
660
- typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
661
- exclusions.forEach(function (exclusion) {
662
- for (var i = exclusion[0]; i < exclusion[1]; i += 1) {
663
- isExcluded[i] = true;
664
- }
665
- });
666
- }
654
+ if (indentStr === '') return this; // noop
667
655
 
668
- var shouldIndentNextCharacter = options.indentStart !== false;
669
- var replacer = function (match) {
670
- if (shouldIndentNextCharacter) { return ("" + indentStr + match); }
671
- shouldIndentNextCharacter = true;
672
- return match;
673
- };
656
+ options = options || {};
674
657
 
675
- this.intro = this.intro.replace(pattern, replacer);
658
+ // Process exclusion ranges
659
+ const isExcluded = {};
676
660
 
677
- var charIndex = 0;
678
- var chunk = this.firstChunk;
661
+ if (options.exclude) {
662
+ const exclusions =
663
+ typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
664
+ exclusions.forEach((exclusion) => {
665
+ for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
666
+ isExcluded[i] = true;
667
+ }
668
+ });
669
+ }
679
670
 
680
- while (chunk) {
681
- var end = chunk.end;
671
+ let shouldIndentNextCharacter = options.indentStart !== false;
672
+ const replacer = (match) => {
673
+ if (shouldIndentNextCharacter) return `${indentStr}${match}`;
674
+ shouldIndentNextCharacter = true;
675
+ return match;
676
+ };
682
677
 
683
- if (chunk.edited) {
684
- if (!isExcluded[charIndex]) {
685
- chunk.content = chunk.content.replace(pattern, replacer);
678
+ this.intro = this.intro.replace(pattern, replacer);
686
679
 
687
- if (chunk.content.length) {
688
- shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
689
- }
690
- }
691
- } else {
692
- charIndex = chunk.start;
680
+ let charIndex = 0;
681
+ let chunk = this.firstChunk;
682
+
683
+ while (chunk) {
684
+ const end = chunk.end;
693
685
 
694
- while (charIndex < end) {
686
+ if (chunk.edited) {
695
687
  if (!isExcluded[charIndex]) {
696
- var char = this.original[charIndex];
697
-
698
- if (char === '\n') {
699
- shouldIndentNextCharacter = true;
700
- } else if (char !== '\r' && shouldIndentNextCharacter) {
701
- shouldIndentNextCharacter = false;
702
-
703
- if (charIndex === chunk.start) {
704
- chunk.prependRight(indentStr);
705
- } else {
706
- this._splitChunk(chunk, charIndex);
707
- chunk = chunk.next;
708
- chunk.prependRight(indentStr);
709
- }
688
+ chunk.content = chunk.content.replace(pattern, replacer);
689
+
690
+ if (chunk.content.length) {
691
+ shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
710
692
  }
711
693
  }
694
+ } else {
695
+ charIndex = chunk.start;
696
+
697
+ while (charIndex < end) {
698
+ if (!isExcluded[charIndex]) {
699
+ const char = this.original[charIndex];
700
+
701
+ if (char === '\n') {
702
+ shouldIndentNextCharacter = true;
703
+ } else if (char !== '\r' && shouldIndentNextCharacter) {
704
+ shouldIndentNextCharacter = false;
705
+
706
+ if (charIndex === chunk.start) {
707
+ chunk.prependRight(indentStr);
708
+ } else {
709
+ this._splitChunk(chunk, charIndex);
710
+ chunk = chunk.next;
711
+ chunk.prependRight(indentStr);
712
+ }
713
+ }
714
+ }
712
715
 
713
- charIndex += 1;
716
+ charIndex += 1;
717
+ }
714
718
  }
719
+
720
+ charIndex = chunk.end;
721
+ chunk = chunk.next;
715
722
  }
716
723
 
717
- charIndex = chunk.end;
718
- chunk = chunk.next;
719
- }
724
+ this.outro = this.outro.replace(pattern, replacer);
720
725
 
721
- this.outro = this.outro.replace(pattern, replacer);
726
+ return this;
727
+ }
722
728
 
723
- return this;
724
- };
729
+ insert() {
730
+ throw new Error(
731
+ 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
732
+ );
733
+ }
725
734
 
726
- MagicString.prototype.insert = function insert () {
727
- throw new Error('magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)');
728
- };
735
+ insertLeft(index, content) {
736
+ if (!warned.insertLeft) {
737
+ console.warn(
738
+ 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
739
+ ); // eslint-disable-line no-console
740
+ warned.insertLeft = true;
741
+ }
729
742
 
730
- MagicString.prototype.insertLeft = function insertLeft (index, content) {
731
- if (!warned.insertLeft) {
732
- console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
733
- warned.insertLeft = true;
743
+ return this.appendLeft(index, content);
734
744
  }
735
745
 
736
- return this.appendLeft(index, content);
737
- };
746
+ insertRight(index, content) {
747
+ if (!warned.insertRight) {
748
+ console.warn(
749
+ 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
750
+ ); // eslint-disable-line no-console
751
+ warned.insertRight = true;
752
+ }
738
753
 
739
- MagicString.prototype.insertRight = function insertRight (index, content) {
740
- if (!warned.insertRight) {
741
- console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
742
- warned.insertRight = true;
754
+ return this.prependRight(index, content);
743
755
  }
744
756
 
745
- return this.prependRight(index, content);
746
- };
757
+ move(start, end, index) {
758
+ if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
747
759
 
748
- MagicString.prototype.move = function move (start, end, index) {
749
- if (index >= start && index <= end) { throw new Error('Cannot move a selection inside itself'); }
760
+ this._split(start);
761
+ this._split(end);
762
+ this._split(index);
750
763
 
751
- this._split(start);
752
- this._split(end);
753
- this._split(index);
764
+ const first = this.byStart[start];
765
+ const last = this.byEnd[end];
754
766
 
755
- var first = this.byStart[start];
756
- var last = this.byEnd[end];
767
+ const oldLeft = first.previous;
768
+ const oldRight = last.next;
757
769
 
758
- var oldLeft = first.previous;
759
- var oldRight = last.next;
770
+ const newRight = this.byStart[index];
771
+ if (!newRight && last === this.lastChunk) return this;
772
+ const newLeft = newRight ? newRight.previous : this.lastChunk;
760
773
 
761
- var newRight = this.byStart[index];
762
- if (!newRight && last === this.lastChunk) { return this; }
763
- var newLeft = newRight ? newRight.previous : this.lastChunk;
774
+ if (oldLeft) oldLeft.next = oldRight;
775
+ if (oldRight) oldRight.previous = oldLeft;
764
776
 
765
- if (oldLeft) { oldLeft.next = oldRight; }
766
- if (oldRight) { oldRight.previous = oldLeft; }
777
+ if (newLeft) newLeft.next = first;
778
+ if (newRight) newRight.previous = last;
767
779
 
768
- if (newLeft) { newLeft.next = first; }
769
- if (newRight) { newRight.previous = last; }
780
+ if (!first.previous) this.firstChunk = last.next;
781
+ if (!last.next) {
782
+ this.lastChunk = first.previous;
783
+ this.lastChunk.next = null;
784
+ }
770
785
 
771
- if (!first.previous) { this.firstChunk = last.next; }
772
- if (!last.next) {
773
- this.lastChunk = first.previous;
774
- this.lastChunk.next = null;
775
- }
786
+ first.previous = newLeft;
787
+ last.next = newRight || null;
776
788
 
777
- first.previous = newLeft;
778
- last.next = newRight || null;
789
+ if (!newLeft) this.firstChunk = first;
790
+ if (!newRight) this.lastChunk = last;
791
+ return this;
792
+ }
779
793
 
780
- if (!newLeft) { this.firstChunk = first; }
781
- if (!newRight) { this.lastChunk = last; }
782
- return this;
783
- };
794
+ overwrite(start, end, content, options) {
795
+ if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
784
796
 
785
- MagicString.prototype.overwrite = function overwrite (start, end, content, options) {
786
- if (typeof content !== 'string') { throw new TypeError('replacement content must be a string'); }
797
+ while (start < 0) start += this.original.length;
798
+ while (end < 0) end += this.original.length;
787
799
 
788
- while (start < 0) { start += this.original.length; }
789
- while (end < 0) { end += this.original.length; }
800
+ if (end > this.original.length) throw new Error('end is out of bounds');
801
+ if (start === end)
802
+ throw new Error(
803
+ 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
804
+ );
790
805
 
791
- if (end > this.original.length) { throw new Error('end is out of bounds'); }
792
- if (start === end)
793
- { throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
806
+ this._split(start);
807
+ this._split(end);
794
808
 
795
- this._split(start);
796
- this._split(end);
809
+ if (options === true) {
810
+ if (!warned.storeName) {
811
+ console.warn(
812
+ 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
813
+ ); // eslint-disable-line no-console
814
+ warned.storeName = true;
815
+ }
797
816
 
798
- if (options === true) {
799
- if (!warned.storeName) {
800
- console.warn('The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'); // eslint-disable-line no-console
801
- warned.storeName = true;
817
+ options = { storeName: true };
802
818
  }
803
-
804
- options = { storeName: true };
805
- }
806
- var storeName = options !== undefined ? options.storeName : false;
807
- var contentOnly = options !== undefined ? options.contentOnly : false;
808
-
809
- if (storeName) {
810
- var original = this.original.slice(start, end);
811
- this.storedNames[original] = true;
812
- }
813
-
814
- var first = this.byStart[start];
815
- var last = this.byEnd[end];
816
-
817
- if (first) {
818
- if (end > first.end && first.next !== this.byStart[first.end]) {
819
- throw new Error('Cannot overwrite across a split point');
819
+ const storeName = options !== undefined ? options.storeName : false;
820
+ const contentOnly = options !== undefined ? options.contentOnly : false;
821
+
822
+ if (storeName) {
823
+ const original = this.original.slice(start, end);
824
+ Object.defineProperty(this.storedNames, original, {
825
+ writable: true,
826
+ value: true,
827
+ enumerable: true,
828
+ });
820
829
  }
821
830
 
822
- first.edit(content, storeName, contentOnly);
831
+ const first = this.byStart[start];
832
+ const last = this.byEnd[end];
823
833
 
824
- if (first !== last) {
825
- var chunk = first.next;
834
+ if (first) {
835
+ let chunk = first;
826
836
  while (chunk !== last) {
827
- chunk.edit('', false);
837
+ if (chunk.next !== this.byStart[chunk.end]) {
838
+ throw new Error('Cannot overwrite across a split point');
839
+ }
828
840
  chunk = chunk.next;
841
+ chunk.edit('', false);
829
842
  }
830
843
 
831
- chunk.edit('', false);
832
- }
833
- } else {
834
- // must be inserting at the end
835
- var newChunk = new Chunk$1(start, end, '').edit(content, storeName);
844
+ first.edit(content, storeName, contentOnly);
845
+ } else {
846
+ // must be inserting at the end
847
+ const newChunk = new Chunk$1(start, end, '').edit(content, storeName);
836
848
 
837
- // TODO last chunk in the array may not be the last chunk, if it's moved...
838
- last.next = newChunk;
839
- newChunk.previous = last;
849
+ // TODO last chunk in the array may not be the last chunk, if it's moved...
850
+ last.next = newChunk;
851
+ newChunk.previous = last;
852
+ }
853
+ return this;
840
854
  }
841
- return this;
842
- };
843
-
844
- MagicString.prototype.prepend = function prepend (content) {
845
- if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
846
-
847
- this.intro = content + this.intro;
848
- return this;
849
- };
850
855
 
851
- MagicString.prototype.prependLeft = function prependLeft (index, content) {
852
- if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
856
+ prepend(content) {
857
+ if (typeof content !== 'string') throw new TypeError('outro content must be a string');
853
858
 
854
- this._split(index);
855
-
856
- var chunk = this.byEnd[index];
857
-
858
- if (chunk) {
859
- chunk.prependLeft(content);
860
- } else {
861
859
  this.intro = content + this.intro;
860
+ return this;
862
861
  }
863
- return this;
864
- };
865
862
 
866
- MagicString.prototype.prependRight = function prependRight (index, content) {
867
- if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
863
+ prependLeft(index, content) {
864
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
868
865
 
869
- this._split(index);
866
+ this._split(index);
870
867
 
871
- var chunk = this.byStart[index];
868
+ const chunk = this.byEnd[index];
872
869
 
873
- if (chunk) {
874
- chunk.prependRight(content);
875
- } else {
876
- this.outro = content + this.outro;
870
+ if (chunk) {
871
+ chunk.prependLeft(content);
872
+ } else {
873
+ this.intro = content + this.intro;
874
+ }
875
+ return this;
877
876
  }
878
- return this;
879
- };
880
-
881
- MagicString.prototype.remove = function remove (start, end) {
882
- while (start < 0) { start += this.original.length; }
883
- while (end < 0) { end += this.original.length; }
884
-
885
- if (start === end) { return this; }
886
877
 
887
- if (start < 0 || end > this.original.length) { throw new Error('Character is out of bounds'); }
888
- if (start > end) { throw new Error('end must be greater than start'); }
878
+ prependRight(index, content) {
879
+ if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
889
880
 
890
- this._split(start);
891
- this._split(end);
881
+ this._split(index);
892
882
 
893
- var chunk = this.byStart[start];
883
+ const chunk = this.byStart[index];
894
884
 
895
- while (chunk) {
896
- chunk.intro = '';
897
- chunk.outro = '';
898
- chunk.edit('');
899
-
900
- chunk = end > chunk.end ? this.byStart[chunk.end] : null;
901
- }
902
- return this;
903
- };
904
-
905
- MagicString.prototype.lastChar = function lastChar () {
906
- if (this.outro.length)
907
- { return this.outro[this.outro.length - 1]; }
908
- var chunk = this.lastChunk;
909
- do {
910
- if (chunk.outro.length)
911
- { return chunk.outro[chunk.outro.length - 1]; }
912
- if (chunk.content.length)
913
- { return chunk.content[chunk.content.length - 1]; }
914
- if (chunk.intro.length)
915
- { return chunk.intro[chunk.intro.length - 1]; }
916
- } while (chunk = chunk.previous);
917
- if (this.intro.length)
918
- { return this.intro[this.intro.length - 1]; }
919
- return '';
920
- };
921
-
922
- MagicString.prototype.lastLine = function lastLine () {
923
- var lineIndex = this.outro.lastIndexOf(n);
924
- if (lineIndex !== -1)
925
- { return this.outro.substr(lineIndex + 1); }
926
- var lineStr = this.outro;
927
- var chunk = this.lastChunk;
928
- do {
929
- if (chunk.outro.length > 0) {
930
- lineIndex = chunk.outro.lastIndexOf(n);
931
- if (lineIndex !== -1)
932
- { return chunk.outro.substr(lineIndex + 1) + lineStr; }
933
- lineStr = chunk.outro + lineStr;
885
+ if (chunk) {
886
+ chunk.prependRight(content);
887
+ } else {
888
+ this.outro = content + this.outro;
934
889
  }
890
+ return this;
891
+ }
935
892
 
936
- if (chunk.content.length > 0) {
937
- lineIndex = chunk.content.lastIndexOf(n);
938
- if (lineIndex !== -1)
939
- { return chunk.content.substr(lineIndex + 1) + lineStr; }
940
- lineStr = chunk.content + lineStr;
941
- }
893
+ remove(start, end) {
894
+ while (start < 0) start += this.original.length;
895
+ while (end < 0) end += this.original.length;
942
896
 
943
- if (chunk.intro.length > 0) {
944
- lineIndex = chunk.intro.lastIndexOf(n);
945
- if (lineIndex !== -1)
946
- { return chunk.intro.substr(lineIndex + 1) + lineStr; }
947
- lineStr = chunk.intro + lineStr;
948
- }
949
- } while (chunk = chunk.previous);
950
- lineIndex = this.intro.lastIndexOf(n);
951
- if (lineIndex !== -1)
952
- { return this.intro.substr(lineIndex + 1) + lineStr; }
953
- return this.intro + lineStr;
954
- };
897
+ if (start === end) return this;
898
+
899
+ if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
900
+ if (start > end) throw new Error('end must be greater than start');
955
901
 
956
- MagicString.prototype.slice = function slice (start, end) {
957
- if ( start === void 0 ) start = 0;
958
- if ( end === void 0 ) end = this.original.length;
902
+ this._split(start);
903
+ this._split(end);
959
904
 
960
- while (start < 0) { start += this.original.length; }
961
- while (end < 0) { end += this.original.length; }
905
+ let chunk = this.byStart[start];
962
906
 
963
- var result = '';
907
+ while (chunk) {
908
+ chunk.intro = '';
909
+ chunk.outro = '';
910
+ chunk.edit('');
964
911
 
965
- // find start chunk
966
- var chunk = this.firstChunk;
967
- while (chunk && (chunk.start > start || chunk.end <= start)) {
968
- // found end chunk before start
969
- if (chunk.start < end && chunk.end >= end) {
970
- return result;
912
+ chunk = end > chunk.end ? this.byStart[chunk.end] : null;
971
913
  }
914
+ return this;
915
+ }
972
916
 
973
- chunk = chunk.next;
917
+ lastChar() {
918
+ if (this.outro.length) return this.outro[this.outro.length - 1];
919
+ let chunk = this.lastChunk;
920
+ do {
921
+ if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
922
+ if (chunk.content.length) return chunk.content[chunk.content.length - 1];
923
+ if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
924
+ } while ((chunk = chunk.previous));
925
+ if (this.intro.length) return this.intro[this.intro.length - 1];
926
+ return '';
974
927
  }
975
928
 
976
- if (chunk && chunk.edited && chunk.start !== start)
977
- { throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
929
+ lastLine() {
930
+ let lineIndex = this.outro.lastIndexOf(n);
931
+ if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
932
+ let lineStr = this.outro;
933
+ let chunk = this.lastChunk;
934
+ do {
935
+ if (chunk.outro.length > 0) {
936
+ lineIndex = chunk.outro.lastIndexOf(n);
937
+ if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
938
+ lineStr = chunk.outro + lineStr;
939
+ }
978
940
 
979
- var startChunk = chunk;
980
- while (chunk) {
981
- if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
982
- result += chunk.intro;
983
- }
941
+ if (chunk.content.length > 0) {
942
+ lineIndex = chunk.content.lastIndexOf(n);
943
+ if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
944
+ lineStr = chunk.content + lineStr;
945
+ }
984
946
 
985
- var containsEnd = chunk.start < end && chunk.end >= end;
986
- if (containsEnd && chunk.edited && chunk.end !== end)
987
- { throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
947
+ if (chunk.intro.length > 0) {
948
+ lineIndex = chunk.intro.lastIndexOf(n);
949
+ if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
950
+ lineStr = chunk.intro + lineStr;
951
+ }
952
+ } while ((chunk = chunk.previous));
953
+ lineIndex = this.intro.lastIndexOf(n);
954
+ if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
955
+ return this.intro + lineStr;
956
+ }
988
957
 
989
- var sliceStart = startChunk === chunk ? start - chunk.start : 0;
990
- var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
958
+ slice(start = 0, end = this.original.length) {
959
+ while (start < 0) start += this.original.length;
960
+ while (end < 0) end += this.original.length;
991
961
 
992
- result += chunk.content.slice(sliceStart, sliceEnd);
962
+ let result = '';
993
963
 
994
- if (chunk.outro && (!containsEnd || chunk.end === end)) {
995
- result += chunk.outro;
996
- }
964
+ // find start chunk
965
+ let chunk = this.firstChunk;
966
+ while (chunk && (chunk.start > start || chunk.end <= start)) {
967
+ // found end chunk before start
968
+ if (chunk.start < end && chunk.end >= end) {
969
+ return result;
970
+ }
997
971
 
998
- if (containsEnd) {
999
- break;
972
+ chunk = chunk.next;
1000
973
  }
1001
974
 
1002
- chunk = chunk.next;
1003
- }
975
+ if (chunk && chunk.edited && chunk.start !== start)
976
+ throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
1004
977
 
1005
- return result;
1006
- };
978
+ const startChunk = chunk;
979
+ while (chunk) {
980
+ if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
981
+ result += chunk.intro;
982
+ }
1007
983
 
1008
- // TODO deprecate this? not really very useful
1009
- MagicString.prototype.snip = function snip (start, end) {
1010
- var clone = this.clone();
1011
- clone.remove(0, start);
1012
- clone.remove(end, clone.original.length);
984
+ const containsEnd = chunk.start < end && chunk.end >= end;
985
+ if (containsEnd && chunk.edited && chunk.end !== end)
986
+ throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
1013
987
 
1014
- return clone;
1015
- };
988
+ const sliceStart = startChunk === chunk ? start - chunk.start : 0;
989
+ const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
1016
990
 
1017
- MagicString.prototype._split = function _split (index) {
1018
- if (this.byStart[index] || this.byEnd[index]) { return; }
991
+ result += chunk.content.slice(sliceStart, sliceEnd);
1019
992
 
1020
- var chunk = this.lastSearchedChunk;
1021
- var searchForward = index > chunk.end;
993
+ if (chunk.outro && (!containsEnd || chunk.end === end)) {
994
+ result += chunk.outro;
995
+ }
1022
996
 
1023
- while (chunk) {
1024
- if (chunk.contains(index)) { return this._splitChunk(chunk, index); }
997
+ if (containsEnd) {
998
+ break;
999
+ }
1025
1000
 
1026
- chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
1027
- }
1028
- };
1001
+ chunk = chunk.next;
1002
+ }
1029
1003
 
1030
- MagicString.prototype._splitChunk = function _splitChunk (chunk, index) {
1031
- if (chunk.edited && chunk.content.length) {
1032
- // zero-length edited chunks are a special case (overlapping replacements)
1033
- var loc = getLocator$1(this.original)(index);
1034
- throw new Error(
1035
- ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")")
1036
- );
1004
+ return result;
1037
1005
  }
1038
1006
 
1039
- var newChunk = chunk.split(index);
1007
+ // TODO deprecate this? not really very useful
1008
+ snip(start, end) {
1009
+ const clone = this.clone();
1010
+ clone.remove(0, start);
1011
+ clone.remove(end, clone.original.length);
1040
1012
 
1041
- this.byEnd[index] = chunk;
1042
- this.byStart[index] = newChunk;
1043
- this.byEnd[newChunk.end] = newChunk;
1013
+ return clone;
1014
+ }
1044
1015
 
1045
- if (chunk === this.lastChunk) { this.lastChunk = newChunk; }
1016
+ _split(index) {
1017
+ if (this.byStart[index] || this.byEnd[index]) return;
1046
1018
 
1047
- this.lastSearchedChunk = chunk;
1048
- return true;
1049
- };
1019
+ let chunk = this.lastSearchedChunk;
1020
+ const searchForward = index > chunk.end;
1050
1021
 
1051
- MagicString.prototype.toString = function toString () {
1052
- var str = this.intro;
1022
+ while (chunk) {
1023
+ if (chunk.contains(index)) return this._splitChunk(chunk, index);
1053
1024
 
1054
- var chunk = this.firstChunk;
1055
- while (chunk) {
1056
- str += chunk.toString();
1057
- chunk = chunk.next;
1025
+ chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
1026
+ }
1058
1027
  }
1059
1028
 
1060
- return str + this.outro;
1061
- };
1029
+ _splitChunk(chunk, index) {
1030
+ if (chunk.edited && chunk.content.length) {
1031
+ // zero-length edited chunks are a special case (overlapping replacements)
1032
+ const loc = getLocator$1(this.original)(index);
1033
+ throw new Error(
1034
+ `Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`
1035
+ );
1036
+ }
1062
1037
 
1063
- MagicString.prototype.isEmpty = function isEmpty () {
1064
- var chunk = this.firstChunk;
1065
- do {
1066
- if (chunk.intro.length && chunk.intro.trim() ||
1067
- chunk.content.length && chunk.content.trim() ||
1068
- chunk.outro.length && chunk.outro.trim())
1069
- { return false; }
1070
- } while (chunk = chunk.next);
1071
- return true;
1072
- };
1038
+ const newChunk = chunk.split(index);
1073
1039
 
1074
- MagicString.prototype.length = function length () {
1075
- var chunk = this.firstChunk;
1076
- var length = 0;
1077
- do {
1078
- length += chunk.intro.length + chunk.content.length + chunk.outro.length;
1079
- } while (chunk = chunk.next);
1080
- return length;
1081
- };
1040
+ this.byEnd[index] = chunk;
1041
+ this.byStart[index] = newChunk;
1042
+ this.byEnd[newChunk.end] = newChunk;
1082
1043
 
1083
- MagicString.prototype.trimLines = function trimLines () {
1084
- return this.trim('[\\r\\n]');
1085
- };
1044
+ if (chunk === this.lastChunk) this.lastChunk = newChunk;
1086
1045
 
1087
- MagicString.prototype.trim = function trim (charType) {
1088
- return this.trimStart(charType).trimEnd(charType);
1089
- };
1046
+ this.lastSearchedChunk = chunk;
1047
+ return true;
1048
+ }
1090
1049
 
1091
- MagicString.prototype.trimEndAborted = function trimEndAborted (charType) {
1092
- var rx = new RegExp((charType || '\\s') + '+$');
1050
+ toString() {
1051
+ let str = this.intro;
1093
1052
 
1094
- this.outro = this.outro.replace(rx, '');
1095
- if (this.outro.length) { return true; }
1053
+ let chunk = this.firstChunk;
1054
+ while (chunk) {
1055
+ str += chunk.toString();
1056
+ chunk = chunk.next;
1057
+ }
1096
1058
 
1097
- var chunk = this.lastChunk;
1059
+ return str + this.outro;
1060
+ }
1098
1061
 
1099
- do {
1100
- var end = chunk.end;
1101
- var aborted = chunk.trimEnd(rx);
1062
+ isEmpty() {
1063
+ let chunk = this.firstChunk;
1064
+ do {
1065
+ if (
1066
+ (chunk.intro.length && chunk.intro.trim()) ||
1067
+ (chunk.content.length && chunk.content.trim()) ||
1068
+ (chunk.outro.length && chunk.outro.trim())
1069
+ )
1070
+ return false;
1071
+ } while ((chunk = chunk.next));
1072
+ return true;
1073
+ }
1102
1074
 
1103
- // if chunk was trimmed, we have a new lastChunk
1104
- if (chunk.end !== end) {
1105
- if (this.lastChunk === chunk) {
1106
- this.lastChunk = chunk.next;
1107
- }
1075
+ length() {
1076
+ let chunk = this.firstChunk;
1077
+ let length = 0;
1078
+ do {
1079
+ length += chunk.intro.length + chunk.content.length + chunk.outro.length;
1080
+ } while ((chunk = chunk.next));
1081
+ return length;
1082
+ }
1108
1083
 
1109
- this.byEnd[chunk.end] = chunk;
1110
- this.byStart[chunk.next.start] = chunk.next;
1111
- this.byEnd[chunk.next.end] = chunk.next;
1112
- }
1084
+ trimLines() {
1085
+ return this.trim('[\\r\\n]');
1086
+ }
1113
1087
 
1114
- if (aborted) { return true; }
1115
- chunk = chunk.previous;
1116
- } while (chunk);
1088
+ trim(charType) {
1089
+ return this.trimStart(charType).trimEnd(charType);
1090
+ }
1117
1091
 
1118
- return false;
1119
- };
1092
+ trimEndAborted(charType) {
1093
+ const rx = new RegExp((charType || '\\s') + '+$');
1120
1094
 
1121
- MagicString.prototype.trimEnd = function trimEnd (charType) {
1122
- this.trimEndAborted(charType);
1123
- return this;
1124
- };
1125
- MagicString.prototype.trimStartAborted = function trimStartAborted (charType) {
1126
- var rx = new RegExp('^' + (charType || '\\s') + '+');
1095
+ this.outro = this.outro.replace(rx, '');
1096
+ if (this.outro.length) return true;
1127
1097
 
1128
- this.intro = this.intro.replace(rx, '');
1129
- if (this.intro.length) { return true; }
1098
+ let chunk = this.lastChunk;
1130
1099
 
1131
- var chunk = this.firstChunk;
1100
+ do {
1101
+ const end = chunk.end;
1102
+ const aborted = chunk.trimEnd(rx);
1132
1103
 
1133
- do {
1134
- var end = chunk.end;
1135
- var aborted = chunk.trimStart(rx);
1104
+ // if chunk was trimmed, we have a new lastChunk
1105
+ if (chunk.end !== end) {
1106
+ if (this.lastChunk === chunk) {
1107
+ this.lastChunk = chunk.next;
1108
+ }
1136
1109
 
1137
- if (chunk.end !== end) {
1138
- // special case...
1139
- if (chunk === this.lastChunk) { this.lastChunk = chunk.next; }
1110
+ this.byEnd[chunk.end] = chunk;
1111
+ this.byStart[chunk.next.start] = chunk.next;
1112
+ this.byEnd[chunk.next.end] = chunk.next;
1113
+ }
1140
1114
 
1141
- this.byEnd[chunk.end] = chunk;
1142
- this.byStart[chunk.next.start] = chunk.next;
1143
- this.byEnd[chunk.next.end] = chunk.next;
1144
- }
1115
+ if (aborted) return true;
1116
+ chunk = chunk.previous;
1117
+ } while (chunk);
1145
1118
 
1146
- if (aborted) { return true; }
1147
- chunk = chunk.next;
1148
- } while (chunk);
1119
+ return false;
1120
+ }
1149
1121
 
1150
- return false;
1151
- };
1122
+ trimEnd(charType) {
1123
+ this.trimEndAborted(charType);
1124
+ return this;
1125
+ }
1126
+ trimStartAborted(charType) {
1127
+ const rx = new RegExp('^' + (charType || '\\s') + '+');
1152
1128
 
1153
- MagicString.prototype.trimStart = function trimStart (charType) {
1154
- this.trimStartAborted(charType);
1155
- return this;
1156
- };
1129
+ this.intro = this.intro.replace(rx, '');
1130
+ if (this.intro.length) return true;
1157
1131
 
1158
- var hasOwnProp = Object.prototype.hasOwnProperty;
1132
+ let chunk = this.firstChunk;
1159
1133
 
1160
- var Bundle$1 = function Bundle(options) {
1161
- if ( options === void 0 ) options = {};
1134
+ do {
1135
+ const end = chunk.end;
1136
+ const aborted = chunk.trimStart(rx);
1162
1137
 
1163
- this.intro = options.intro || '';
1164
- this.separator = options.separator !== undefined ? options.separator : '\n';
1165
- this.sources = [];
1166
- this.uniqueSources = [];
1167
- this.uniqueSourceIndexByFilename = {};
1168
- };
1138
+ if (chunk.end !== end) {
1139
+ // special case...
1140
+ if (chunk === this.lastChunk) this.lastChunk = chunk.next;
1169
1141
 
1170
- Bundle$1.prototype.addSource = function addSource (source) {
1171
- if (source instanceof MagicString) {
1172
- return this.addSource({
1173
- content: source,
1174
- filename: source.filename,
1175
- separator: this.separator
1176
- });
1177
- }
1142
+ this.byEnd[chunk.end] = chunk;
1143
+ this.byStart[chunk.next.start] = chunk.next;
1144
+ this.byEnd[chunk.next.end] = chunk.next;
1145
+ }
1146
+
1147
+ if (aborted) return true;
1148
+ chunk = chunk.next;
1149
+ } while (chunk);
1178
1150
 
1179
- if (!isObject$1(source) || !source.content) {
1180
- throw new Error('bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`');
1151
+ return false;
1181
1152
  }
1182
1153
 
1183
- ['filename', 'indentExclusionRanges', 'separator'].forEach(function (option) {
1184
- if (!hasOwnProp.call(source, option)) { source[option] = source.content[option]; }
1185
- });
1154
+ trimStart(charType) {
1155
+ this.trimStartAborted(charType);
1156
+ return this;
1157
+ }
1186
1158
 
1187
- if (source.separator === undefined) {
1188
- // TODO there's a bunch of this sort of thing, needs cleaning up
1189
- source.separator = this.separator;
1159
+ hasChanged() {
1160
+ return this.original !== this.toString();
1190
1161
  }
1191
1162
 
1192
- if (source.filename) {
1193
- if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
1194
- this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
1195
- this.uniqueSources.push({ filename: source.filename, content: source.content.original });
1196
- } else {
1197
- var uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
1198
- if (source.content.original !== uniqueSource.content) {
1199
- throw new Error(("Illegal source: same filename (" + (source.filename) + "), different contents"));
1163
+ replace(searchValue, replacement) {
1164
+ function getReplacement(match, str) {
1165
+ if (typeof replacement === 'string') {
1166
+ return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
1167
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
1168
+ if (i === '$') return '$';
1169
+ if (i === '&') return match[0];
1170
+ const num = +i;
1171
+ if (num < match.length) return match[+i];
1172
+ return `$${i}`;
1173
+ });
1174
+ } else {
1175
+ return replacement(...match, match.index, str, match.groups);
1176
+ }
1177
+ }
1178
+ function matchAll(re, str) {
1179
+ let match;
1180
+ const matches = [];
1181
+ while ((match = re.exec(str))) {
1182
+ matches.push(match);
1200
1183
  }
1184
+ return matches;
1201
1185
  }
1186
+ if (typeof searchValue !== 'string' && searchValue.global) {
1187
+ const matches = matchAll(searchValue, this.original);
1188
+ matches.forEach((match) => {
1189
+ if (match.index != null)
1190
+ this.overwrite(
1191
+ match.index,
1192
+ match.index + match[0].length,
1193
+ getReplacement(match, this.original)
1194
+ );
1195
+ });
1196
+ } else {
1197
+ const match = this.original.match(searchValue);
1198
+ if (match && match.index != null)
1199
+ this.overwrite(
1200
+ match.index,
1201
+ match.index + match[0].length,
1202
+ getReplacement(match, this.original)
1203
+ );
1204
+ }
1205
+ return this;
1202
1206
  }
1207
+ }
1203
1208
 
1204
- this.sources.push(source);
1205
- return this;
1206
- };
1209
+ const hasOwnProp = Object.prototype.hasOwnProperty;
1207
1210
 
1208
- Bundle$1.prototype.append = function append (str, options) {
1209
- this.addSource({
1210
- content: new MagicString(str),
1211
- separator: (options && options.separator) || ''
1212
- });
1211
+ class Bundle$1 {
1212
+ constructor(options = {}) {
1213
+ this.intro = options.intro || '';
1214
+ this.separator = options.separator !== undefined ? options.separator : '\n';
1215
+ this.sources = [];
1216
+ this.uniqueSources = [];
1217
+ this.uniqueSourceIndexByFilename = {};
1218
+ }
1213
1219
 
1214
- return this;
1215
- };
1220
+ addSource(source) {
1221
+ if (source instanceof MagicString) {
1222
+ return this.addSource({
1223
+ content: source,
1224
+ filename: source.filename,
1225
+ separator: this.separator,
1226
+ });
1227
+ }
1216
1228
 
1217
- Bundle$1.prototype.clone = function clone () {
1218
- var bundle = new Bundle$1({
1219
- intro: this.intro,
1220
- separator: this.separator
1221
- });
1229
+ if (!isObject$1(source) || !source.content) {
1230
+ throw new Error(
1231
+ 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`'
1232
+ );
1233
+ }
1222
1234
 
1223
- this.sources.forEach(function (source) {
1224
- bundle.addSource({
1225
- filename: source.filename,
1226
- content: source.content.clone(),
1227
- separator: source.separator
1235
+ ['filename', 'indentExclusionRanges', 'separator'].forEach((option) => {
1236
+ if (!hasOwnProp.call(source, option)) source[option] = source.content[option];
1228
1237
  });
1229
- });
1230
1238
 
1231
- return bundle;
1232
- };
1239
+ if (source.separator === undefined) {
1240
+ // TODO there's a bunch of this sort of thing, needs cleaning up
1241
+ source.separator = this.separator;
1242
+ }
1233
1243
 
1234
- Bundle$1.prototype.generateDecodedMap = function generateDecodedMap (options) {
1235
- var this$1$1 = this;
1236
- if ( options === void 0 ) options = {};
1244
+ if (source.filename) {
1245
+ if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
1246
+ this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
1247
+ this.uniqueSources.push({ filename: source.filename, content: source.content.original });
1248
+ } else {
1249
+ const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
1250
+ if (source.content.original !== uniqueSource.content) {
1251
+ throw new Error(`Illegal source: same filename (${source.filename}), different contents`);
1252
+ }
1253
+ }
1254
+ }
1255
+
1256
+ this.sources.push(source);
1257
+ return this;
1258
+ }
1237
1259
 
1238
- var names = [];
1239
- this.sources.forEach(function (source) {
1240
- Object.keys(source.content.storedNames).forEach(function (name) {
1241
- if (!~names.indexOf(name)) { names.push(name); }
1260
+ append(str, options) {
1261
+ this.addSource({
1262
+ content: new MagicString(str),
1263
+ separator: (options && options.separator) || '',
1242
1264
  });
1243
- });
1244
1265
 
1245
- var mappings = new Mappings(options.hires);
1266
+ return this;
1267
+ }
1268
+
1269
+ clone() {
1270
+ const bundle = new Bundle$1({
1271
+ intro: this.intro,
1272
+ separator: this.separator,
1273
+ });
1246
1274
 
1247
- if (this.intro) {
1248
- mappings.advance(this.intro);
1275
+ this.sources.forEach((source) => {
1276
+ bundle.addSource({
1277
+ filename: source.filename,
1278
+ content: source.content.clone(),
1279
+ separator: source.separator,
1280
+ });
1281
+ });
1282
+
1283
+ return bundle;
1249
1284
  }
1250
1285
 
1251
- this.sources.forEach(function (source, i) {
1252
- if (i > 0) {
1253
- mappings.advance(this$1$1.separator);
1254
- }
1286
+ generateDecodedMap(options = {}) {
1287
+ const names = [];
1288
+ this.sources.forEach((source) => {
1289
+ Object.keys(source.content.storedNames).forEach((name) => {
1290
+ if (!~names.indexOf(name)) names.push(name);
1291
+ });
1292
+ });
1255
1293
 
1256
- var sourceIndex = source.filename ? this$1$1.uniqueSourceIndexByFilename[source.filename] : -1;
1257
- var magicString = source.content;
1258
- var locate = getLocator$1(magicString.original);
1294
+ const mappings = new Mappings(options.hires);
1259
1295
 
1260
- if (magicString.intro) {
1261
- mappings.advance(magicString.intro);
1296
+ if (this.intro) {
1297
+ mappings.advance(this.intro);
1262
1298
  }
1263
1299
 
1264
- magicString.firstChunk.eachNext(function (chunk) {
1265
- var loc = locate(chunk.start);
1300
+ this.sources.forEach((source, i) => {
1301
+ if (i > 0) {
1302
+ mappings.advance(this.separator);
1303
+ }
1266
1304
 
1267
- if (chunk.intro.length) { mappings.advance(chunk.intro); }
1305
+ const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
1306
+ const magicString = source.content;
1307
+ const locate = getLocator$1(magicString.original);
1268
1308
 
1269
- if (source.filename) {
1270
- if (chunk.edited) {
1271
- mappings.addEdit(
1272
- sourceIndex,
1273
- chunk.content,
1274
- loc,
1275
- chunk.storeName ? names.indexOf(chunk.original) : -1
1276
- );
1309
+ if (magicString.intro) {
1310
+ mappings.advance(magicString.intro);
1311
+ }
1312
+
1313
+ magicString.firstChunk.eachNext((chunk) => {
1314
+ const loc = locate(chunk.start);
1315
+
1316
+ if (chunk.intro.length) mappings.advance(chunk.intro);
1317
+
1318
+ if (source.filename) {
1319
+ if (chunk.edited) {
1320
+ mappings.addEdit(
1321
+ sourceIndex,
1322
+ chunk.content,
1323
+ loc,
1324
+ chunk.storeName ? names.indexOf(chunk.original) : -1
1325
+ );
1326
+ } else {
1327
+ mappings.addUneditedChunk(
1328
+ sourceIndex,
1329
+ chunk,
1330
+ magicString.original,
1331
+ loc,
1332
+ magicString.sourcemapLocations
1333
+ );
1334
+ }
1277
1335
  } else {
1278
- mappings.addUneditedChunk(
1279
- sourceIndex,
1280
- chunk,
1281
- magicString.original,
1282
- loc,
1283
- magicString.sourcemapLocations
1284
- );
1336
+ mappings.advance(chunk.content);
1285
1337
  }
1286
- } else {
1287
- mappings.advance(chunk.content);
1288
- }
1289
1338
 
1290
- if (chunk.outro.length) { mappings.advance(chunk.outro); }
1291
- });
1339
+ if (chunk.outro.length) mappings.advance(chunk.outro);
1340
+ });
1292
1341
 
1293
- if (magicString.outro) {
1294
- mappings.advance(magicString.outro);
1295
- }
1296
- });
1342
+ if (magicString.outro) {
1343
+ mappings.advance(magicString.outro);
1344
+ }
1345
+ });
1297
1346
 
1298
- return {
1299
- file: options.file ? options.file.split(/[/\\]/).pop() : null,
1300
- sources: this.uniqueSources.map(function (source) {
1301
- return options.file ? getRelativePath(options.file, source.filename) : source.filename;
1302
- }),
1303
- sourcesContent: this.uniqueSources.map(function (source) {
1304
- return options.includeContent ? source.content : null;
1305
- }),
1306
- names: names,
1307
- mappings: mappings.raw
1308
- };
1309
- };
1347
+ return {
1348
+ file: options.file ? options.file.split(/[/\\]/).pop() : null,
1349
+ sources: this.uniqueSources.map((source) => {
1350
+ return options.file ? getRelativePath(options.file, source.filename) : source.filename;
1351
+ }),
1352
+ sourcesContent: this.uniqueSources.map((source) => {
1353
+ return options.includeContent ? source.content : null;
1354
+ }),
1355
+ names,
1356
+ mappings: mappings.raw,
1357
+ };
1358
+ }
1310
1359
 
1311
- Bundle$1.prototype.generateMap = function generateMap (options) {
1312
- return new SourceMap(this.generateDecodedMap(options));
1313
- };
1360
+ generateMap(options) {
1361
+ return new SourceMap(this.generateDecodedMap(options));
1362
+ }
1314
1363
 
1315
- Bundle$1.prototype.getIndentString = function getIndentString () {
1316
- var indentStringCounts = {};
1364
+ getIndentString() {
1365
+ const indentStringCounts = {};
1317
1366
 
1318
- this.sources.forEach(function (source) {
1319
- var indentStr = source.content.indentStr;
1367
+ this.sources.forEach((source) => {
1368
+ const indentStr = source.content.indentStr;
1320
1369
 
1321
- if (indentStr === null) { return; }
1370
+ if (indentStr === null) return;
1322
1371
 
1323
- if (!indentStringCounts[indentStr]) { indentStringCounts[indentStr] = 0; }
1324
- indentStringCounts[indentStr] += 1;
1325
- });
1372
+ if (!indentStringCounts[indentStr]) indentStringCounts[indentStr] = 0;
1373
+ indentStringCounts[indentStr] += 1;
1374
+ });
1326
1375
 
1327
- return (
1328
- Object.keys(indentStringCounts).sort(function (a, b) {
1329
- return indentStringCounts[a] - indentStringCounts[b];
1330
- })[0] || '\t'
1331
- );
1332
- };
1376
+ return (
1377
+ Object.keys(indentStringCounts).sort((a, b) => {
1378
+ return indentStringCounts[a] - indentStringCounts[b];
1379
+ })[0] || '\t'
1380
+ );
1381
+ }
1333
1382
 
1334
- Bundle$1.prototype.indent = function indent (indentStr) {
1335
- var this$1$1 = this;
1383
+ indent(indentStr) {
1384
+ if (!arguments.length) {
1385
+ indentStr = this.getIndentString();
1386
+ }
1336
1387
 
1337
- if (!arguments.length) {
1338
- indentStr = this.getIndentString();
1339
- }
1388
+ if (indentStr === '') return this; // noop
1340
1389
 
1341
- if (indentStr === '') { return this; } // noop
1390
+ let trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
1342
1391
 
1343
- var trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
1392
+ this.sources.forEach((source, i) => {
1393
+ const separator = source.separator !== undefined ? source.separator : this.separator;
1394
+ const indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator));
1344
1395
 
1345
- this.sources.forEach(function (source, i) {
1346
- var separator = source.separator !== undefined ? source.separator : this$1$1.separator;
1347
- var indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator));
1396
+ source.content.indent(indentStr, {
1397
+ exclude: source.indentExclusionRanges,
1398
+ indentStart, //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
1399
+ });
1348
1400
 
1349
- source.content.indent(indentStr, {
1350
- exclude: source.indentExclusionRanges,
1351
- indentStart: indentStart //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
1401
+ trailingNewline = source.content.lastChar() === '\n';
1352
1402
  });
1353
1403
 
1354
- trailingNewline = source.content.lastChar() === '\n';
1355
- });
1404
+ if (this.intro) {
1405
+ this.intro =
1406
+ indentStr +
1407
+ this.intro.replace(/^[^\n]/gm, (match, index) => {
1408
+ return index > 0 ? indentStr + match : match;
1409
+ });
1410
+ }
1356
1411
 
1357
- if (this.intro) {
1358
- this.intro =
1359
- indentStr +
1360
- this.intro.replace(/^[^\n]/gm, function (match, index) {
1361
- return index > 0 ? indentStr + match : match;
1362
- });
1412
+ return this;
1363
1413
  }
1364
1414
 
1365
- return this;
1366
- };
1415
+ prepend(str) {
1416
+ this.intro = str + this.intro;
1417
+ return this;
1418
+ }
1367
1419
 
1368
- Bundle$1.prototype.prepend = function prepend (str) {
1369
- this.intro = str + this.intro;
1370
- return this;
1371
- };
1420
+ toString() {
1421
+ const body = this.sources
1422
+ .map((source, i) => {
1423
+ const separator = source.separator !== undefined ? source.separator : this.separator;
1424
+ const str = (i > 0 ? separator : '') + source.content.toString();
1372
1425
 
1373
- Bundle$1.prototype.toString = function toString () {
1374
- var this$1$1 = this;
1426
+ return str;
1427
+ })
1428
+ .join('');
1375
1429
 
1376
- var body = this.sources
1377
- .map(function (source, i) {
1378
- var separator = source.separator !== undefined ? source.separator : this$1$1.separator;
1379
- var str = (i > 0 ? separator : '') + source.content.toString();
1430
+ return this.intro + body;
1431
+ }
1380
1432
 
1381
- return str;
1382
- })
1383
- .join('');
1433
+ isEmpty() {
1434
+ if (this.intro.length && this.intro.trim()) return false;
1435
+ if (this.sources.some((source) => !source.content.isEmpty())) return false;
1436
+ return true;
1437
+ }
1384
1438
 
1385
- return this.intro + body;
1386
- };
1439
+ length() {
1440
+ return this.sources.reduce(
1441
+ (length, source) => length + source.content.length(),
1442
+ this.intro.length
1443
+ );
1444
+ }
1387
1445
 
1388
- Bundle$1.prototype.isEmpty = function isEmpty () {
1389
- if (this.intro.length && this.intro.trim())
1390
- { return false; }
1391
- if (this.sources.some(function (source) { return !source.content.isEmpty(); }))
1392
- { return false; }
1393
- return true;
1394
- };
1446
+ trimLines() {
1447
+ return this.trim('[\\r\\n]');
1448
+ }
1395
1449
 
1396
- Bundle$1.prototype.length = function length () {
1397
- return this.sources.reduce(function (length, source) { return length + source.content.length(); }, this.intro.length);
1398
- };
1450
+ trim(charType) {
1451
+ return this.trimStart(charType).trimEnd(charType);
1452
+ }
1399
1453
 
1400
- Bundle$1.prototype.trimLines = function trimLines () {
1401
- return this.trim('[\\r\\n]');
1402
- };
1454
+ trimStart(charType) {
1455
+ const rx = new RegExp('^' + (charType || '\\s') + '+');
1456
+ this.intro = this.intro.replace(rx, '');
1403
1457
 
1404
- Bundle$1.prototype.trim = function trim (charType) {
1405
- return this.trimStart(charType).trimEnd(charType);
1406
- };
1458
+ if (!this.intro) {
1459
+ let source;
1460
+ let i = 0;
1461
+
1462
+ do {
1463
+ source = this.sources[i++];
1464
+ if (!source) {
1465
+ break;
1466
+ }
1467
+ } while (!source.content.trimStartAborted(charType));
1468
+ }
1469
+
1470
+ return this;
1471
+ }
1407
1472
 
1408
- Bundle$1.prototype.trimStart = function trimStart (charType) {
1409
- var rx = new RegExp('^' + (charType || '\\s') + '+');
1410
- this.intro = this.intro.replace(rx, '');
1473
+ trimEnd(charType) {
1474
+ const rx = new RegExp((charType || '\\s') + '+$');
1411
1475
 
1412
- if (!this.intro) {
1413
- var source;
1414
- var i = 0;
1476
+ let source;
1477
+ let i = this.sources.length - 1;
1415
1478
 
1416
1479
  do {
1417
- source = this.sources[i++];
1480
+ source = this.sources[i--];
1418
1481
  if (!source) {
1482
+ this.intro = this.intro.replace(rx, '');
1419
1483
  break;
1420
1484
  }
1421
- } while (!source.content.trimStartAborted(charType));
1422
- }
1423
-
1424
- return this;
1425
- };
1485
+ } while (!source.content.trimEndAborted(charType));
1426
1486
 
1427
- Bundle$1.prototype.trimEnd = function trimEnd (charType) {
1428
- var rx = new RegExp((charType || '\\s') + '+$');
1429
-
1430
- var source;
1431
- var i = this.sources.length - 1;
1432
-
1433
- do {
1434
- source = this.sources[i--];
1435
- if (!source) {
1436
- this.intro = this.intro.replace(rx, '');
1437
- break;
1438
- }
1439
- } while (!source.content.trimEndAborted(charType));
1440
-
1441
- return this;
1442
- };
1443
-
1444
- const MagicString$1 = MagicString;
1487
+ return this;
1488
+ }
1489
+ }
1445
1490
 
1446
1491
  const ANY_SLASH_REGEX = /[/\\]/;
1447
1492
  function relative(from, to) {
@@ -4428,7 +4473,7 @@ const normalizePath = function normalizePath(filename) {
4428
4473
 
4429
4474
  function getMatcherString(id, resolutionBase) {
4430
4475
  if (resolutionBase === false || isAbsolute$1(id) || id.startsWith('*')) {
4431
- return id;
4476
+ return normalizePath(id);
4432
4477
  }
4433
4478
  // resolve('') is valid and will default to process.cwd()
4434
4479
  const basePath = normalizePath(resolve(resolutionBase || ''))
@@ -4438,7 +4483,7 @@ function getMatcherString(id, resolutionBase) {
4438
4483
  // 1. the basePath has been normalized to use /
4439
4484
  // 2. the incoming glob (id) matcher, also uses /
4440
4485
  // otherwise Node will force backslash (\) on windows
4441
- return posix.join(basePath, id);
4486
+ return posix.join(basePath, normalizePath(id));
4442
4487
  }
4443
4488
  const createFilter = function createFilter(include, exclude, options) {
4444
4489
  const resolutionBase = options && options.resolve;
@@ -12628,7 +12673,7 @@ class Module {
12628
12673
  // By default, `id` is the file name. Custom resolvers and loaders
12629
12674
  // can change that, but it makes sense to use it for the source file name
12630
12675
  const fileName = this.id;
12631
- this.magicString = new MagicString$1(code, {
12676
+ this.magicString = new MagicString(code, {
12632
12677
  filename: (this.excludeFromSourcemap ? null : fileName),
12633
12678
  indentExclusionRanges: []
12634
12679
  });
@@ -14664,7 +14709,7 @@ class Chunk {
14664
14709
  if (namespace.renderFirst())
14665
14710
  hoistedSource += n + rendered;
14666
14711
  else
14667
- magicString.addSource(new MagicString$1(rendered));
14712
+ magicString.addSource(new MagicString(rendered));
14668
14713
  }
14669
14714
  }
14670
14715
  const { renderedExports, removedExports } = module.getRenderedExports();
@@ -21894,7 +21939,7 @@ async function transform(source, module, pluginDriver, warn) {
21894
21939
  getCombinedSourcemap() {
21895
21940
  const combinedMap = collapseSourcemap(id, originalCode, originalSourcemap, sourcemapChain, warn);
21896
21941
  if (!combinedMap) {
21897
- const magicString = new MagicString$1(originalCode);
21942
+ const magicString = new MagicString(originalCode);
21898
21943
  return magicString.generateMap({ hires: true, includeContent: true, source: id });
21899
21944
  }
21900
21945
  if (originalSourcemap !== combinedMap) {
@@ -23026,8 +23071,7 @@ const objectifyOptionWithPresets = (presets, optionName, additionalValues) => (v
23026
23071
  return objectifyOption(value);
23027
23072
  };
23028
23073
  const getOptionWithPreset = (value, presets, optionName, additionalValues) => {
23029
- var _a;
23030
- const presetName = (_a = value) === null || _a === void 0 ? void 0 : _a.preset;
23074
+ const presetName = value === null || value === void 0 ? void 0 : value.preset;
23031
23075
  if (presetName) {
23032
23076
  const preset = presets[presetName];
23033
23077
  if (preset) {