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.
- package/CHANGELOG.md +12 -0
- package/dist/bin/rollup +2 -2
- package/dist/es/rollup.browser.js +3 -3
- package/dist/es/rollup.js +2 -2
- package/dist/es/shared/rollup.js +996 -952
- package/dist/es/shared/watch.js +2 -2
- package/dist/loadConfigFile.js +2 -2
- package/dist/rollup.browser.js +3 -3
- package/dist/rollup.browser.js.map +1 -1
- package/dist/rollup.d.ts +13 -17
- package/dist/rollup.js +2 -2
- package/dist/shared/index.js +2 -2
- package/dist/shared/loadConfigFile.js +2 -2
- package/dist/shared/mergeOptions.js +2 -2
- package/dist/shared/rollup.js +996 -952
- package/dist/shared/watch-cli.js +2 -2
- package/dist/shared/watch.js +2 -2
- package/package.json +19 -19
package/dist/es/shared/rollup.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v2.70.
|
|
4
|
-
|
|
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.
|
|
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
|
-
|
|
142
|
-
|
|
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
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
146
|
+
add(n) {
|
|
147
|
+
this.bits[n >> 5] |= 1 << (n & 31);
|
|
148
|
+
}
|
|
152
149
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
150
|
+
has(n) {
|
|
151
|
+
return !!(this.bits[n >> 5] & (1 << (n & 31)));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
157
154
|
|
|
158
|
-
|
|
159
|
-
|
|
155
|
+
class Chunk$1 {
|
|
156
|
+
constructor(start, end, content) {
|
|
157
|
+
this.start = start;
|
|
158
|
+
this.end = end;
|
|
159
|
+
this.original = content;
|
|
160
160
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
this.edited = false;
|
|
161
|
+
this.intro = '';
|
|
162
|
+
this.outro = '';
|
|
164
163
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
next: { writable: true, value: null }
|
|
169
|
-
});
|
|
170
|
-
};
|
|
164
|
+
this.content = content;
|
|
165
|
+
this.storeName = false;
|
|
166
|
+
this.edited = false;
|
|
171
167
|
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
177
|
-
|
|
178
|
-
}
|
|
175
|
+
appendLeft(content) {
|
|
176
|
+
this.outro += content;
|
|
177
|
+
}
|
|
179
178
|
|
|
180
|
-
|
|
181
|
-
|
|
179
|
+
appendRight(content) {
|
|
180
|
+
this.intro = this.intro + content;
|
|
181
|
+
}
|
|
182
182
|
|
|
183
|
-
|
|
184
|
-
|
|
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
|
-
|
|
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
|
-
|
|
193
|
-
|
|
194
|
-
};
|
|
192
|
+
return chunk;
|
|
193
|
+
}
|
|
195
194
|
|
|
196
|
-
|
|
197
|
-
|
|
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
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
199
|
+
eachNext(fn) {
|
|
200
|
+
let chunk = this;
|
|
201
|
+
while (chunk) {
|
|
202
|
+
fn(chunk);
|
|
203
|
+
chunk = chunk.next;
|
|
204
|
+
}
|
|
209
205
|
}
|
|
210
|
-
};
|
|
211
206
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
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
|
-
|
|
223
|
-
};
|
|
223
|
+
this.edited = true;
|
|
224
224
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
};
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
228
227
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
228
|
+
prependLeft(content) {
|
|
229
|
+
this.outro = content + this.outro;
|
|
230
|
+
}
|
|
232
231
|
|
|
233
|
-
|
|
234
|
-
|
|
232
|
+
prependRight(content) {
|
|
233
|
+
this.intro = content + this.intro;
|
|
234
|
+
}
|
|
235
235
|
|
|
236
|
-
|
|
237
|
-
|
|
236
|
+
split(index) {
|
|
237
|
+
const sliceIndex = index - this.start;
|
|
238
238
|
|
|
239
|
-
|
|
239
|
+
const originalBefore = this.original.slice(0, sliceIndex);
|
|
240
|
+
const originalAfter = this.original.slice(sliceIndex);
|
|
240
241
|
|
|
241
|
-
|
|
242
|
-
newChunk.outro = this.outro;
|
|
243
|
-
this.outro = '';
|
|
242
|
+
this.original = originalBefore;
|
|
244
243
|
|
|
245
|
-
|
|
244
|
+
const newChunk = new Chunk$1(index, this.end, originalAfter);
|
|
245
|
+
newChunk.outro = this.outro;
|
|
246
|
+
this.outro = '';
|
|
246
247
|
|
|
247
|
-
|
|
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
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
-
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
};
|
|
263
|
+
return newChunk;
|
|
264
|
+
}
|
|
266
265
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
266
|
+
toString() {
|
|
267
|
+
return this.intro + this.content + this.outro;
|
|
268
|
+
}
|
|
270
269
|
|
|
271
|
-
|
|
270
|
+
trimEnd(rx) {
|
|
271
|
+
this.outro = this.outro.replace(rx, '');
|
|
272
|
+
if (this.outro.length) return true;
|
|
272
273
|
|
|
273
|
-
|
|
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
|
-
|
|
280
|
-
|
|
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
|
-
|
|
283
|
-
|
|
284
|
+
this.intro = this.intro.replace(rx, '');
|
|
285
|
+
if (this.intro.length) return true;
|
|
286
|
+
}
|
|
284
287
|
}
|
|
285
|
-
};
|
|
286
288
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
289
|
+
trimStart(rx) {
|
|
290
|
+
this.intro = this.intro.replace(rx, '');
|
|
291
|
+
if (this.intro.length) return true;
|
|
290
292
|
|
|
291
|
-
|
|
293
|
+
const trimmed = this.content.replace(rx, '');
|
|
292
294
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
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
|
-
|
|
304
|
-
|
|
304
|
+
this.outro = this.outro.replace(rx, '');
|
|
305
|
+
if (this.outro.length) return true;
|
|
306
|
+
}
|
|
305
307
|
}
|
|
306
|
-
}
|
|
308
|
+
}
|
|
307
309
|
|
|
308
|
-
|
|
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 =
|
|
314
|
+
btoa = (str) => window.btoa(unescape(encodeURIComponent(str)));
|
|
313
315
|
} else if (typeof Buffer === 'function') {
|
|
314
|
-
btoa =
|
|
316
|
+
btoa = (str) => Buffer.from(str, 'utf-8').toString('base64');
|
|
315
317
|
}
|
|
316
318
|
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
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
|
-
|
|
327
|
-
|
|
328
|
-
}
|
|
329
|
+
toString() {
|
|
330
|
+
return JSON.stringify(this);
|
|
331
|
+
}
|
|
329
332
|
|
|
330
|
-
|
|
331
|
-
|
|
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
|
-
|
|
339
|
+
const lines = code.split('\n');
|
|
336
340
|
|
|
337
|
-
|
|
338
|
-
|
|
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
|
-
|
|
353
|
-
|
|
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
|
-
|
|
362
|
-
|
|
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
|
-
|
|
373
|
-
while (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
|
-
|
|
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
|
-
|
|
387
|
-
|
|
390
|
+
const originalLines = source.split('\n');
|
|
391
|
+
const lineOffsets = [];
|
|
388
392
|
|
|
389
|
-
for (
|
|
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
|
-
|
|
396
|
-
|
|
399
|
+
let i = 0;
|
|
400
|
+
let j = lineOffsets.length;
|
|
397
401
|
while (i < j) {
|
|
398
|
-
|
|
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
|
-
|
|
406
|
-
|
|
407
|
-
return { line
|
|
409
|
+
const line = i - 1;
|
|
410
|
+
const column = index - lineOffsets[line];
|
|
411
|
+
return { line, column };
|
|
408
412
|
};
|
|
409
413
|
}
|
|
410
414
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
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
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
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
|
-
|
|
427
|
-
|
|
428
|
-
this.
|
|
435
|
+
|
|
436
|
+
this.advance(content);
|
|
437
|
+
this.pending = null;
|
|
429
438
|
}
|
|
430
439
|
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
440
|
+
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
441
|
+
let originalCharIndex = chunk.start;
|
|
442
|
+
let first = true;
|
|
434
443
|
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
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
|
-
|
|
440
|
-
|
|
441
|
-
|
|
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
|
-
|
|
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
|
-
|
|
465
|
+
this.pending = null;
|
|
458
466
|
}
|
|
459
467
|
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
Mappings.prototype.advance = function advance (str) {
|
|
464
|
-
if (!str) { return; }
|
|
468
|
+
advance(str) {
|
|
469
|
+
if (!str) return;
|
|
465
470
|
|
|
466
|
-
|
|
471
|
+
const lines = str.split('\n');
|
|
467
472
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
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
|
-
|
|
477
|
-
}
|
|
481
|
+
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
478
484
|
|
|
479
|
-
|
|
485
|
+
const n = '\n';
|
|
480
486
|
|
|
481
|
-
|
|
487
|
+
const warned = {
|
|
482
488
|
insertLeft: false,
|
|
483
489
|
insertRight: false,
|
|
484
|
-
storeName: false
|
|
485
|
-
};
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
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
|
-
|
|
524
|
-
|
|
513
|
+
this.byStart[0] = chunk;
|
|
514
|
+
this.byEnd[string.length] = chunk;
|
|
515
|
+
}
|
|
525
516
|
|
|
526
|
-
|
|
517
|
+
addSourcemapLocation(char) {
|
|
518
|
+
this.sourcemapLocations.add(char);
|
|
519
|
+
}
|
|
527
520
|
|
|
528
|
-
|
|
521
|
+
append(content) {
|
|
522
|
+
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
529
523
|
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
} else {
|
|
533
|
-
this.intro += content;
|
|
524
|
+
this.outro += content;
|
|
525
|
+
return this;
|
|
534
526
|
}
|
|
535
|
-
return this;
|
|
536
|
-
};
|
|
537
527
|
|
|
538
|
-
|
|
539
|
-
|
|
528
|
+
appendLeft(index, content) {
|
|
529
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
540
530
|
|
|
541
|
-
|
|
531
|
+
this._split(index);
|
|
542
532
|
|
|
543
|
-
|
|
533
|
+
const chunk = this.byEnd[index];
|
|
544
534
|
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
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
|
-
|
|
560
|
-
|
|
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
|
-
|
|
564
|
-
var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
546
|
+
this._split(index);
|
|
565
547
|
|
|
566
|
-
|
|
567
|
-
clonedChunk.next = nextClonedChunk;
|
|
568
|
-
nextClonedChunk.previous = clonedChunk;
|
|
548
|
+
const chunk = this.byStart[index];
|
|
569
549
|
|
|
570
|
-
|
|
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
|
-
|
|
558
|
+
clone() {
|
|
559
|
+
const cloned = new MagicString(this.original, { filename: this.filename });
|
|
577
560
|
|
|
578
|
-
|
|
579
|
-
cloned.
|
|
580
|
-
}
|
|
561
|
+
let originalChunk = this.firstChunk;
|
|
562
|
+
let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
|
|
581
563
|
|
|
582
|
-
|
|
564
|
+
while (originalChunk) {
|
|
565
|
+
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
566
|
+
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
583
567
|
|
|
584
|
-
|
|
585
|
-
|
|
568
|
+
const nextOriginalChunk = originalChunk.next;
|
|
569
|
+
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
586
570
|
|
|
587
|
-
|
|
588
|
-
|
|
571
|
+
if (nextClonedChunk) {
|
|
572
|
+
clonedChunk.next = nextClonedChunk;
|
|
573
|
+
nextClonedChunk.previous = clonedChunk;
|
|
589
574
|
|
|
590
|
-
|
|
591
|
-
|
|
575
|
+
clonedChunk = nextClonedChunk;
|
|
576
|
+
}
|
|
592
577
|
|
|
593
|
-
|
|
578
|
+
originalChunk = nextOriginalChunk;
|
|
579
|
+
}
|
|
594
580
|
|
|
595
|
-
|
|
596
|
-
var names = Object.keys(this.storedNames);
|
|
597
|
-
var mappings = new Mappings(options.hires);
|
|
581
|
+
cloned.lastChunk = clonedChunk;
|
|
598
582
|
|
|
599
|
-
|
|
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
|
-
|
|
602
|
-
mappings.advance(this.intro);
|
|
592
|
+
return cloned;
|
|
603
593
|
}
|
|
604
594
|
|
|
605
|
-
|
|
606
|
-
|
|
595
|
+
generateDecodedMap(options) {
|
|
596
|
+
options = options || {};
|
|
607
597
|
|
|
608
|
-
|
|
598
|
+
const sourceIndex = 0;
|
|
599
|
+
const names = Object.keys(this.storedNames);
|
|
600
|
+
const mappings = new Mappings(options.hires);
|
|
609
601
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
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
|
-
|
|
622
|
-
|
|
608
|
+
this.firstChunk.eachNext((chunk) => {
|
|
609
|
+
const loc = locate(chunk.start);
|
|
623
610
|
|
|
624
|
-
|
|
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
|
-
|
|
634
|
-
|
|
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
|
-
|
|
638
|
-
|
|
639
|
-
};
|
|
624
|
+
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
625
|
+
});
|
|
640
626
|
|
|
641
|
-
|
|
642
|
-
|
|
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
|
-
|
|
645
|
-
|
|
646
|
-
indentStr = undefined;
|
|
636
|
+
generateMap(options) {
|
|
637
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
647
638
|
}
|
|
648
639
|
|
|
649
|
-
|
|
640
|
+
getIndentString() {
|
|
641
|
+
return this.indentStr === null ? '\t' : this.indentStr;
|
|
642
|
+
}
|
|
650
643
|
|
|
651
|
-
|
|
644
|
+
indent(indentStr, options) {
|
|
645
|
+
const pattern = /^[^\r\n]/gm;
|
|
652
646
|
|
|
653
|
-
|
|
647
|
+
if (isObject$1(indentStr)) {
|
|
648
|
+
options = indentStr;
|
|
649
|
+
indentStr = undefined;
|
|
650
|
+
}
|
|
654
651
|
|
|
655
|
-
|
|
656
|
-
var isExcluded = {};
|
|
652
|
+
indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
|
|
657
653
|
|
|
658
|
-
|
|
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
|
-
|
|
669
|
-
var replacer = function (match) {
|
|
670
|
-
if (shouldIndentNextCharacter) { return ("" + indentStr + match); }
|
|
671
|
-
shouldIndentNextCharacter = true;
|
|
672
|
-
return match;
|
|
673
|
-
};
|
|
656
|
+
options = options || {};
|
|
674
657
|
|
|
675
|
-
|
|
658
|
+
// Process exclusion ranges
|
|
659
|
+
const isExcluded = {};
|
|
676
660
|
|
|
677
|
-
|
|
678
|
-
|
|
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
|
-
|
|
681
|
-
|
|
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
|
-
|
|
684
|
-
if (!isExcluded[charIndex]) {
|
|
685
|
-
chunk.content = chunk.content.replace(pattern, replacer);
|
|
678
|
+
this.intro = this.intro.replace(pattern, replacer);
|
|
686
679
|
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
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
|
-
|
|
686
|
+
if (chunk.edited) {
|
|
695
687
|
if (!isExcluded[charIndex]) {
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
if (
|
|
699
|
-
shouldIndentNextCharacter =
|
|
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
|
-
|
|
716
|
+
charIndex += 1;
|
|
717
|
+
}
|
|
714
718
|
}
|
|
719
|
+
|
|
720
|
+
charIndex = chunk.end;
|
|
721
|
+
chunk = chunk.next;
|
|
715
722
|
}
|
|
716
723
|
|
|
717
|
-
|
|
718
|
-
chunk = chunk.next;
|
|
719
|
-
}
|
|
724
|
+
this.outro = this.outro.replace(pattern, replacer);
|
|
720
725
|
|
|
721
|
-
|
|
726
|
+
return this;
|
|
727
|
+
}
|
|
722
728
|
|
|
723
|
-
|
|
724
|
-
|
|
729
|
+
insert() {
|
|
730
|
+
throw new Error(
|
|
731
|
+
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
|
|
732
|
+
);
|
|
733
|
+
}
|
|
725
734
|
|
|
726
|
-
|
|
727
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
746
|
-
|
|
757
|
+
move(start, end, index) {
|
|
758
|
+
if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
|
|
747
759
|
|
|
748
|
-
|
|
749
|
-
|
|
760
|
+
this._split(start);
|
|
761
|
+
this._split(end);
|
|
762
|
+
this._split(index);
|
|
750
763
|
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
this._split(index);
|
|
764
|
+
const first = this.byStart[start];
|
|
765
|
+
const last = this.byEnd[end];
|
|
754
766
|
|
|
755
|
-
|
|
756
|
-
|
|
767
|
+
const oldLeft = first.previous;
|
|
768
|
+
const oldRight = last.next;
|
|
757
769
|
|
|
758
|
-
|
|
759
|
-
|
|
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
|
-
|
|
762
|
-
|
|
763
|
-
var newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
774
|
+
if (oldLeft) oldLeft.next = oldRight;
|
|
775
|
+
if (oldRight) oldRight.previous = oldLeft;
|
|
764
776
|
|
|
765
|
-
|
|
766
|
-
|
|
777
|
+
if (newLeft) newLeft.next = first;
|
|
778
|
+
if (newRight) newRight.previous = last;
|
|
767
779
|
|
|
768
|
-
|
|
769
|
-
|
|
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
|
-
|
|
772
|
-
|
|
773
|
-
this.lastChunk = first.previous;
|
|
774
|
-
this.lastChunk.next = null;
|
|
775
|
-
}
|
|
786
|
+
first.previous = newLeft;
|
|
787
|
+
last.next = newRight || null;
|
|
776
788
|
|
|
777
|
-
|
|
778
|
-
|
|
789
|
+
if (!newLeft) this.firstChunk = first;
|
|
790
|
+
if (!newRight) this.lastChunk = last;
|
|
791
|
+
return this;
|
|
792
|
+
}
|
|
779
793
|
|
|
780
|
-
|
|
781
|
-
|
|
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
|
-
|
|
786
|
-
|
|
797
|
+
while (start < 0) start += this.original.length;
|
|
798
|
+
while (end < 0) end += this.original.length;
|
|
787
799
|
|
|
788
|
-
|
|
789
|
-
|
|
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
|
-
|
|
792
|
-
|
|
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
|
-
|
|
796
|
-
|
|
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
|
-
|
|
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
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
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
|
|
831
|
+
const first = this.byStart[start];
|
|
832
|
+
const last = this.byEnd[end];
|
|
823
833
|
|
|
824
|
-
if (first
|
|
825
|
-
|
|
834
|
+
if (first) {
|
|
835
|
+
let chunk = first;
|
|
826
836
|
while (chunk !== last) {
|
|
827
|
-
chunk.
|
|
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
|
-
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
|
|
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
|
-
|
|
838
|
-
|
|
839
|
-
|
|
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
|
-
|
|
852
|
-
|
|
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
|
-
|
|
867
|
-
|
|
863
|
+
prependLeft(index, content) {
|
|
864
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
868
865
|
|
|
869
|
-
|
|
866
|
+
this._split(index);
|
|
870
867
|
|
|
871
|
-
|
|
868
|
+
const chunk = this.byEnd[index];
|
|
872
869
|
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
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
|
-
|
|
888
|
-
|
|
878
|
+
prependRight(index, content) {
|
|
879
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
889
880
|
|
|
890
|
-
|
|
891
|
-
this._split(end);
|
|
881
|
+
this._split(index);
|
|
892
882
|
|
|
893
|
-
|
|
883
|
+
const chunk = this.byStart[index];
|
|
894
884
|
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
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
|
-
|
|
937
|
-
|
|
938
|
-
|
|
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 (
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
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
|
-
|
|
957
|
-
|
|
958
|
-
if ( end === void 0 ) end = this.original.length;
|
|
902
|
+
this._split(start);
|
|
903
|
+
this._split(end);
|
|
959
904
|
|
|
960
|
-
|
|
961
|
-
while (end < 0) { end += this.original.length; }
|
|
905
|
+
let chunk = this.byStart[start];
|
|
962
906
|
|
|
963
|
-
|
|
907
|
+
while (chunk) {
|
|
908
|
+
chunk.intro = '';
|
|
909
|
+
chunk.outro = '';
|
|
910
|
+
chunk.edit('');
|
|
964
911
|
|
|
965
|
-
|
|
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
|
-
|
|
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
|
-
|
|
977
|
-
|
|
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
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
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
|
-
|
|
986
|
-
|
|
987
|
-
|
|
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
|
-
|
|
990
|
-
|
|
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
|
|
962
|
+
let result = '';
|
|
993
963
|
|
|
994
|
-
|
|
995
|
-
|
|
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
|
-
|
|
999
|
-
break;
|
|
972
|
+
chunk = chunk.next;
|
|
1000
973
|
}
|
|
1001
974
|
|
|
1002
|
-
chunk
|
|
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
|
-
|
|
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
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1018
|
-
if (this.byStart[index] || this.byEnd[index]) { return; }
|
|
991
|
+
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
1019
992
|
|
|
1020
|
-
|
|
1021
|
-
|
|
993
|
+
if (chunk.outro && (!containsEnd || chunk.end === end)) {
|
|
994
|
+
result += chunk.outro;
|
|
995
|
+
}
|
|
1022
996
|
|
|
1023
|
-
|
|
1024
|
-
|
|
997
|
+
if (containsEnd) {
|
|
998
|
+
break;
|
|
999
|
+
}
|
|
1025
1000
|
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
};
|
|
1001
|
+
chunk = chunk.next;
|
|
1002
|
+
}
|
|
1029
1003
|
|
|
1030
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1042
|
-
|
|
1043
|
-
this.byEnd[newChunk.end] = newChunk;
|
|
1013
|
+
return clone;
|
|
1014
|
+
}
|
|
1044
1015
|
|
|
1045
|
-
|
|
1016
|
+
_split(index) {
|
|
1017
|
+
if (this.byStart[index] || this.byEnd[index]) return;
|
|
1046
1018
|
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
};
|
|
1019
|
+
let chunk = this.lastSearchedChunk;
|
|
1020
|
+
const searchForward = index > chunk.end;
|
|
1050
1021
|
|
|
1051
|
-
|
|
1052
|
-
|
|
1022
|
+
while (chunk) {
|
|
1023
|
+
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
1053
1024
|
|
|
1054
|
-
|
|
1055
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
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
|
-
|
|
1084
|
-
return this.trim('[\\r\\n]');
|
|
1085
|
-
};
|
|
1044
|
+
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
1086
1045
|
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
}
|
|
1046
|
+
this.lastSearchedChunk = chunk;
|
|
1047
|
+
return true;
|
|
1048
|
+
}
|
|
1090
1049
|
|
|
1091
|
-
|
|
1092
|
-
|
|
1050
|
+
toString() {
|
|
1051
|
+
let str = this.intro;
|
|
1093
1052
|
|
|
1094
|
-
|
|
1095
|
-
|
|
1053
|
+
let chunk = this.firstChunk;
|
|
1054
|
+
while (chunk) {
|
|
1055
|
+
str += chunk.toString();
|
|
1056
|
+
chunk = chunk.next;
|
|
1057
|
+
}
|
|
1096
1058
|
|
|
1097
|
-
|
|
1059
|
+
return str + this.outro;
|
|
1060
|
+
}
|
|
1098
1061
|
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
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
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
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
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
}
|
|
1084
|
+
trimLines() {
|
|
1085
|
+
return this.trim('[\\r\\n]');
|
|
1086
|
+
}
|
|
1113
1087
|
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
}
|
|
1088
|
+
trim(charType) {
|
|
1089
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
1090
|
+
}
|
|
1117
1091
|
|
|
1118
|
-
|
|
1119
|
-
|
|
1092
|
+
trimEndAborted(charType) {
|
|
1093
|
+
const rx = new RegExp((charType || '\\s') + '+$');
|
|
1120
1094
|
|
|
1121
|
-
|
|
1122
|
-
|
|
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
|
-
|
|
1129
|
-
if (this.intro.length) { return true; }
|
|
1098
|
+
let chunk = this.lastChunk;
|
|
1130
1099
|
|
|
1131
|
-
|
|
1100
|
+
do {
|
|
1101
|
+
const end = chunk.end;
|
|
1102
|
+
const aborted = chunk.trimEnd(rx);
|
|
1132
1103
|
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
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
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
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
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
}
|
|
1115
|
+
if (aborted) return true;
|
|
1116
|
+
chunk = chunk.previous;
|
|
1117
|
+
} while (chunk);
|
|
1145
1118
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
} while (chunk);
|
|
1119
|
+
return false;
|
|
1120
|
+
}
|
|
1149
1121
|
|
|
1150
|
-
|
|
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
|
-
|
|
1154
|
-
|
|
1155
|
-
return this;
|
|
1156
|
-
};
|
|
1129
|
+
this.intro = this.intro.replace(rx, '');
|
|
1130
|
+
if (this.intro.length) return true;
|
|
1157
1131
|
|
|
1158
|
-
|
|
1132
|
+
let chunk = this.firstChunk;
|
|
1159
1133
|
|
|
1160
|
-
|
|
1161
|
-
|
|
1134
|
+
do {
|
|
1135
|
+
const end = chunk.end;
|
|
1136
|
+
const aborted = chunk.trimStart(rx);
|
|
1162
1137
|
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
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
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1154
|
+
trimStart(charType) {
|
|
1155
|
+
this.trimStartAborted(charType);
|
|
1156
|
+
return this;
|
|
1157
|
+
}
|
|
1186
1158
|
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
source.separator = this.separator;
|
|
1159
|
+
hasChanged() {
|
|
1160
|
+
return this.original !== this.toString();
|
|
1190
1161
|
}
|
|
1191
1162
|
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
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
|
-
|
|
1205
|
-
return this;
|
|
1206
|
-
};
|
|
1209
|
+
const hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1207
1210
|
|
|
1208
|
-
Bundle$1
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
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
|
-
|
|
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
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
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
|
-
|
|
1224
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
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
|
-
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1260
|
+
append(str, options) {
|
|
1261
|
+
this.addSource({
|
|
1262
|
+
content: new MagicString(str),
|
|
1263
|
+
separator: (options && options.separator) || '',
|
|
1242
1264
|
});
|
|
1243
|
-
});
|
|
1244
1265
|
|
|
1245
|
-
|
|
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
|
-
|
|
1248
|
-
|
|
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
|
-
|
|
1252
|
-
|
|
1253
|
-
|
|
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
|
-
|
|
1257
|
-
var magicString = source.content;
|
|
1258
|
-
var locate = getLocator$1(magicString.original);
|
|
1294
|
+
const mappings = new Mappings(options.hires);
|
|
1259
1295
|
|
|
1260
|
-
if (
|
|
1261
|
-
mappings.advance(
|
|
1296
|
+
if (this.intro) {
|
|
1297
|
+
mappings.advance(this.intro);
|
|
1262
1298
|
}
|
|
1263
1299
|
|
|
1264
|
-
|
|
1265
|
-
|
|
1300
|
+
this.sources.forEach((source, i) => {
|
|
1301
|
+
if (i > 0) {
|
|
1302
|
+
mappings.advance(this.separator);
|
|
1303
|
+
}
|
|
1266
1304
|
|
|
1267
|
-
|
|
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 (
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
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.
|
|
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
|
-
|
|
1291
|
-
|
|
1339
|
+
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
1340
|
+
});
|
|
1292
1341
|
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1342
|
+
if (magicString.outro) {
|
|
1343
|
+
mappings.advance(magicString.outro);
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1297
1346
|
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
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
|
-
|
|
1312
|
-
|
|
1313
|
-
}
|
|
1360
|
+
generateMap(options) {
|
|
1361
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
1362
|
+
}
|
|
1314
1363
|
|
|
1315
|
-
|
|
1316
|
-
|
|
1364
|
+
getIndentString() {
|
|
1365
|
+
const indentStringCounts = {};
|
|
1317
1366
|
|
|
1318
|
-
|
|
1319
|
-
|
|
1367
|
+
this.sources.forEach((source) => {
|
|
1368
|
+
const indentStr = source.content.indentStr;
|
|
1320
1369
|
|
|
1321
|
-
|
|
1370
|
+
if (indentStr === null) return;
|
|
1322
1371
|
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1372
|
+
if (!indentStringCounts[indentStr]) indentStringCounts[indentStr] = 0;
|
|
1373
|
+
indentStringCounts[indentStr] += 1;
|
|
1374
|
+
});
|
|
1326
1375
|
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
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
|
-
|
|
1335
|
-
|
|
1383
|
+
indent(indentStr) {
|
|
1384
|
+
if (!arguments.length) {
|
|
1385
|
+
indentStr = this.getIndentString();
|
|
1386
|
+
}
|
|
1336
1387
|
|
|
1337
|
-
|
|
1338
|
-
indentStr = this.getIndentString();
|
|
1339
|
-
}
|
|
1388
|
+
if (indentStr === '') return this; // noop
|
|
1340
1389
|
|
|
1341
|
-
|
|
1390
|
+
let trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
|
|
1342
1391
|
|
|
1343
|
-
|
|
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
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1366
|
-
|
|
1415
|
+
prepend(str) {
|
|
1416
|
+
this.intro = str + this.intro;
|
|
1417
|
+
return this;
|
|
1418
|
+
}
|
|
1367
1419
|
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
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
|
-
|
|
1374
|
-
|
|
1426
|
+
return str;
|
|
1427
|
+
})
|
|
1428
|
+
.join('');
|
|
1375
1429
|
|
|
1376
|
-
|
|
1377
|
-
|
|
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
|
-
|
|
1382
|
-
|
|
1383
|
-
.
|
|
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
|
-
|
|
1386
|
-
|
|
1439
|
+
length() {
|
|
1440
|
+
return this.sources.reduce(
|
|
1441
|
+
(length, source) => length + source.content.length(),
|
|
1442
|
+
this.intro.length
|
|
1443
|
+
);
|
|
1444
|
+
}
|
|
1387
1445
|
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
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
|
-
|
|
1397
|
-
|
|
1398
|
-
}
|
|
1450
|
+
trim(charType) {
|
|
1451
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
1452
|
+
}
|
|
1399
1453
|
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1454
|
+
trimStart(charType) {
|
|
1455
|
+
const rx = new RegExp('^' + (charType || '\\s') + '+');
|
|
1456
|
+
this.intro = this.intro.replace(rx, '');
|
|
1403
1457
|
|
|
1404
|
-
|
|
1405
|
-
|
|
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
|
-
|
|
1409
|
-
|
|
1410
|
-
this.intro = this.intro.replace(rx, '');
|
|
1473
|
+
trimEnd(charType) {
|
|
1474
|
+
const rx = new RegExp((charType || '\\s') + '+$');
|
|
1411
1475
|
|
|
1412
|
-
|
|
1413
|
-
|
|
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.
|
|
1422
|
-
}
|
|
1423
|
-
|
|
1424
|
-
return this;
|
|
1425
|
-
};
|
|
1485
|
+
} while (!source.content.trimEndAborted(charType));
|
|
1426
1486
|
|
|
1427
|
-
|
|
1428
|
-
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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) {
|