rollup 2.69.2 → 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 +42 -0
- package/dist/bin/rollup +2 -3
- package/dist/es/rollup.browser.js +3 -4
- package/dist/es/rollup.js +2 -3
- package/dist/es/shared/rollup.js +1098 -1043
- package/dist/es/shared/watch.js +22 -11
- package/dist/loadConfigFile.js +2 -3
- package/dist/rollup.browser.js +3 -4
- package/dist/rollup.browser.js.map +1 -1
- package/dist/rollup.d.ts +46 -33
- package/dist/rollup.js +2 -3
- package/dist/shared/index.js +2 -3
- package/dist/shared/loadConfigFile.js +2 -3
- package/dist/shared/mergeOptions.js +2 -3
- package/dist/shared/rollup.js +1090 -1035
- package/dist/shared/watch-cli.js +5 -6
- package/dist/shared/watch.js +22 -11
- package/package.json +23 -25
package/dist/es/shared/rollup.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
/*
|
|
2
2
|
@license
|
|
3
|
-
Rollup.js v2.
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
Rollup.js v2.70.2
|
|
4
|
+
Fri, 15 Apr 2022 05:14:21 GMT - commit 030c56fd6b186a0ddfd57d143ad703f34fd2c17a
|
|
6
5
|
|
|
7
6
|
https://github.com/rollup/rollup
|
|
8
7
|
|
|
@@ -15,7 +14,7 @@ import { createHash as createHash$1 } from 'crypto';
|
|
|
15
14
|
import { promises } from 'fs';
|
|
16
15
|
import { EventEmitter } from 'events';
|
|
17
16
|
|
|
18
|
-
var version$1 = "2.
|
|
17
|
+
var version$1 = "2.70.2";
|
|
19
18
|
|
|
20
19
|
var charToInteger = {};
|
|
21
20
|
var chars$1 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
|
|
@@ -139,204 +138,208 @@ function encodeInteger(num) {
|
|
|
139
138
|
return result;
|
|
140
139
|
}
|
|
141
140
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
BitSet.prototype.add = function add (n) {
|
|
147
|
-
this.bits[n >> 5] |= 1 << (n & 31);
|
|
148
|
-
};
|
|
141
|
+
class BitSet {
|
|
142
|
+
constructor(arg) {
|
|
143
|
+
this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
|
144
|
+
}
|
|
149
145
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
146
|
+
add(n) {
|
|
147
|
+
this.bits[n >> 5] |= 1 << (n & 31);
|
|
148
|
+
}
|
|
153
149
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
150
|
+
has(n) {
|
|
151
|
+
return !!(this.bits[n >> 5] & (1 << (n & 31)));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
158
154
|
|
|
159
|
-
|
|
160
|
-
|
|
155
|
+
class Chunk$1 {
|
|
156
|
+
constructor(start, end, content) {
|
|
157
|
+
this.start = start;
|
|
158
|
+
this.end = end;
|
|
159
|
+
this.original = content;
|
|
161
160
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
this.edited = false;
|
|
161
|
+
this.intro = '';
|
|
162
|
+
this.outro = '';
|
|
165
163
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
next: { writable: true, value: null }
|
|
170
|
-
});
|
|
171
|
-
};
|
|
164
|
+
this.content = content;
|
|
165
|
+
this.storeName = false;
|
|
166
|
+
this.edited = false;
|
|
172
167
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
}
|
|
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
|
+
}
|
|
176
174
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
175
|
+
appendLeft(content) {
|
|
176
|
+
this.outro += content;
|
|
177
|
+
}
|
|
180
178
|
|
|
181
|
-
|
|
182
|
-
|
|
179
|
+
appendRight(content) {
|
|
180
|
+
this.intro = this.intro + content;
|
|
181
|
+
}
|
|
183
182
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
chunk.content = this.content;
|
|
187
|
-
chunk.storeName = this.storeName;
|
|
188
|
-
chunk.edited = this.edited;
|
|
183
|
+
clone() {
|
|
184
|
+
const chunk = new Chunk$1(this.start, this.end, this.original);
|
|
189
185
|
|
|
190
|
-
|
|
191
|
-
|
|
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;
|
|
192
191
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
};
|
|
192
|
+
return chunk;
|
|
193
|
+
}
|
|
196
194
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
while (chunk) {
|
|
200
|
-
fn(chunk);
|
|
201
|
-
chunk = chunk.next;
|
|
195
|
+
contains(index) {
|
|
196
|
+
return this.start < index && index < this.end;
|
|
202
197
|
}
|
|
203
|
-
};
|
|
204
198
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
199
|
+
eachNext(fn) {
|
|
200
|
+
let chunk = this;
|
|
201
|
+
while (chunk) {
|
|
202
|
+
fn(chunk);
|
|
203
|
+
chunk = chunk.next;
|
|
204
|
+
}
|
|
210
205
|
}
|
|
211
|
-
};
|
|
212
206
|
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
207
|
+
eachPrevious(fn) {
|
|
208
|
+
let chunk = this;
|
|
209
|
+
while (chunk) {
|
|
210
|
+
fn(chunk);
|
|
211
|
+
chunk = chunk.previous;
|
|
212
|
+
}
|
|
218
213
|
}
|
|
219
|
-
this.storeName = storeName;
|
|
220
214
|
|
|
221
|
-
|
|
215
|
+
edit(content, storeName, contentOnly) {
|
|
216
|
+
this.content = content;
|
|
217
|
+
if (!contentOnly) {
|
|
218
|
+
this.intro = '';
|
|
219
|
+
this.outro = '';
|
|
220
|
+
}
|
|
221
|
+
this.storeName = storeName;
|
|
222
222
|
|
|
223
|
-
|
|
224
|
-
};
|
|
223
|
+
this.edited = true;
|
|
225
224
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
};
|
|
225
|
+
return this;
|
|
226
|
+
}
|
|
229
227
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
}
|
|
228
|
+
prependLeft(content) {
|
|
229
|
+
this.outro = content + this.outro;
|
|
230
|
+
}
|
|
233
231
|
|
|
234
|
-
|
|
235
|
-
|
|
232
|
+
prependRight(content) {
|
|
233
|
+
this.intro = content + this.intro;
|
|
234
|
+
}
|
|
236
235
|
|
|
237
|
-
|
|
238
|
-
|
|
236
|
+
split(index) {
|
|
237
|
+
const sliceIndex = index - this.start;
|
|
239
238
|
|
|
240
|
-
|
|
239
|
+
const originalBefore = this.original.slice(0, sliceIndex);
|
|
240
|
+
const originalAfter = this.original.slice(sliceIndex);
|
|
241
241
|
|
|
242
|
-
|
|
243
|
-
newChunk.outro = this.outro;
|
|
244
|
-
this.outro = '';
|
|
242
|
+
this.original = originalBefore;
|
|
245
243
|
|
|
246
|
-
|
|
244
|
+
const newChunk = new Chunk$1(index, this.end, originalAfter);
|
|
245
|
+
newChunk.outro = this.outro;
|
|
246
|
+
this.outro = '';
|
|
247
247
|
|
|
248
|
-
|
|
249
|
-
// TODO is this block necessary?...
|
|
250
|
-
newChunk.edit('', false);
|
|
251
|
-
this.content = '';
|
|
252
|
-
} else {
|
|
253
|
-
this.content = originalBefore;
|
|
254
|
-
}
|
|
248
|
+
this.end = index;
|
|
255
249
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
250
|
+
if (this.edited) {
|
|
251
|
+
// TODO is this block necessary?...
|
|
252
|
+
newChunk.edit('', false);
|
|
253
|
+
this.content = '';
|
|
254
|
+
} else {
|
|
255
|
+
this.content = originalBefore;
|
|
256
|
+
}
|
|
260
257
|
|
|
261
|
-
|
|
262
|
-
|
|
258
|
+
newChunk.next = this.next;
|
|
259
|
+
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
260
|
+
newChunk.previous = this;
|
|
261
|
+
this.next = newChunk;
|
|
263
262
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
};
|
|
263
|
+
return newChunk;
|
|
264
|
+
}
|
|
267
265
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
266
|
+
toString() {
|
|
267
|
+
return this.intro + this.content + this.outro;
|
|
268
|
+
}
|
|
271
269
|
|
|
272
|
-
|
|
270
|
+
trimEnd(rx) {
|
|
271
|
+
this.outro = this.outro.replace(rx, '');
|
|
272
|
+
if (this.outro.length) return true;
|
|
273
273
|
|
|
274
|
-
|
|
275
|
-
if (trimmed !== this.content) {
|
|
276
|
-
this.split(this.start + trimmed.length).edit('', undefined, true);
|
|
277
|
-
}
|
|
278
|
-
return true;
|
|
274
|
+
const trimmed = this.content.replace(rx, '');
|
|
279
275
|
|
|
280
|
-
|
|
281
|
-
|
|
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);
|
|
282
283
|
|
|
283
|
-
|
|
284
|
-
|
|
284
|
+
this.intro = this.intro.replace(rx, '');
|
|
285
|
+
if (this.intro.length) return true;
|
|
286
|
+
}
|
|
285
287
|
}
|
|
286
|
-
};
|
|
287
288
|
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
289
|
+
trimStart(rx) {
|
|
290
|
+
this.intro = this.intro.replace(rx, '');
|
|
291
|
+
if (this.intro.length) return true;
|
|
291
292
|
|
|
292
|
-
|
|
293
|
+
const trimmed = this.content.replace(rx, '');
|
|
293
294
|
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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 {
|
|
297
302
|
this.edit('', undefined, true);
|
|
298
|
-
}
|
|
299
|
-
return true;
|
|
300
303
|
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
this.outro = this.outro.replace(rx, '');
|
|
305
|
-
if (this.outro.length) { return true; }
|
|
304
|
+
this.outro = this.outro.replace(rx, '');
|
|
305
|
+
if (this.outro.length) return true;
|
|
306
|
+
}
|
|
306
307
|
}
|
|
307
|
-
}
|
|
308
|
+
}
|
|
308
309
|
|
|
309
|
-
|
|
310
|
+
let btoa = () => {
|
|
310
311
|
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
|
|
311
312
|
};
|
|
312
313
|
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
|
313
|
-
btoa =
|
|
314
|
+
btoa = (str) => window.btoa(unescape(encodeURIComponent(str)));
|
|
314
315
|
} else if (typeof Buffer === 'function') {
|
|
315
|
-
btoa =
|
|
316
|
+
btoa = (str) => Buffer.from(str, 'utf-8').toString('base64');
|
|
316
317
|
}
|
|
317
318
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
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
|
+
}
|
|
326
328
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
329
|
+
toString() {
|
|
330
|
+
return JSON.stringify(this);
|
|
331
|
+
}
|
|
330
332
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
}
|
|
333
|
+
toUrl() {
|
|
334
|
+
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
|
|
335
|
+
}
|
|
336
|
+
}
|
|
334
337
|
|
|
335
338
|
function guessIndent(code) {
|
|
336
|
-
|
|
339
|
+
const lines = code.split('\n');
|
|
337
340
|
|
|
338
|
-
|
|
339
|
-
|
|
341
|
+
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
342
|
+
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
340
343
|
|
|
341
344
|
if (tabbed.length === 0 && spaced.length === 0) {
|
|
342
345
|
return null;
|
|
@@ -350,8 +353,8 @@ function guessIndent(code) {
|
|
|
350
353
|
}
|
|
351
354
|
|
|
352
355
|
// Otherwise, we need to guess the multiple
|
|
353
|
-
|
|
354
|
-
|
|
356
|
+
const min = spaced.reduce((previous, current) => {
|
|
357
|
+
const numSpaces = /^ +/.exec(current)[0].length;
|
|
355
358
|
return Math.min(numSpaces, previous);
|
|
356
359
|
}, Infinity);
|
|
357
360
|
|
|
@@ -359,8 +362,8 @@ function guessIndent(code) {
|
|
|
359
362
|
}
|
|
360
363
|
|
|
361
364
|
function getRelativePath(from, to) {
|
|
362
|
-
|
|
363
|
-
|
|
365
|
+
const fromParts = from.split(/[/\\]/);
|
|
366
|
+
const toParts = to.split(/[/\\]/);
|
|
364
367
|
|
|
365
368
|
fromParts.pop(); // get dirname
|
|
366
369
|
|
|
@@ -370,1079 +373,1120 @@ function getRelativePath(from, to) {
|
|
|
370
373
|
}
|
|
371
374
|
|
|
372
375
|
if (fromParts.length) {
|
|
373
|
-
|
|
374
|
-
while (i--)
|
|
376
|
+
let i = fromParts.length;
|
|
377
|
+
while (i--) fromParts[i] = '..';
|
|
375
378
|
}
|
|
376
379
|
|
|
377
380
|
return fromParts.concat(toParts).join('/');
|
|
378
381
|
}
|
|
379
382
|
|
|
380
|
-
|
|
383
|
+
const toString$1 = Object.prototype.toString;
|
|
381
384
|
|
|
382
385
|
function isObject$1(thing) {
|
|
383
386
|
return toString$1.call(thing) === '[object Object]';
|
|
384
387
|
}
|
|
385
388
|
|
|
386
389
|
function getLocator$1(source) {
|
|
387
|
-
|
|
388
|
-
|
|
390
|
+
const originalLines = source.split('\n');
|
|
391
|
+
const lineOffsets = [];
|
|
389
392
|
|
|
390
|
-
for (
|
|
393
|
+
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
391
394
|
lineOffsets.push(pos);
|
|
392
395
|
pos += originalLines[i].length + 1;
|
|
393
396
|
}
|
|
394
397
|
|
|
395
398
|
return function locate(index) {
|
|
396
|
-
|
|
397
|
-
|
|
399
|
+
let i = 0;
|
|
400
|
+
let j = lineOffsets.length;
|
|
398
401
|
while (i < j) {
|
|
399
|
-
|
|
402
|
+
const m = (i + j) >> 1;
|
|
400
403
|
if (index < lineOffsets[m]) {
|
|
401
404
|
j = m;
|
|
402
405
|
} else {
|
|
403
406
|
i = m + 1;
|
|
404
407
|
}
|
|
405
408
|
}
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
return { line
|
|
409
|
+
const line = i - 1;
|
|
410
|
+
const column = index - lineOffsets[line];
|
|
411
|
+
return { line, column };
|
|
409
412
|
};
|
|
410
413
|
}
|
|
411
414
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
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
|
+
}
|
|
420
424
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
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);
|
|
426
434
|
}
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
this.
|
|
435
|
+
|
|
436
|
+
this.advance(content);
|
|
437
|
+
this.pending = null;
|
|
430
438
|
}
|
|
431
439
|
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
440
|
+
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
441
|
+
let originalCharIndex = chunk.start;
|
|
442
|
+
let first = true;
|
|
435
443
|
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
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
|
+
}
|
|
439
448
|
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
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
|
+
}
|
|
444
461
|
|
|
445
|
-
|
|
446
|
-
loc.line += 1;
|
|
447
|
-
loc.column = 0;
|
|
448
|
-
this.generatedCodeLine += 1;
|
|
449
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
450
|
-
this.generatedCodeColumn = 0;
|
|
451
|
-
first = true;
|
|
452
|
-
} else {
|
|
453
|
-
loc.column += 1;
|
|
454
|
-
this.generatedCodeColumn += 1;
|
|
455
|
-
first = false;
|
|
462
|
+
originalCharIndex += 1;
|
|
456
463
|
}
|
|
457
464
|
|
|
458
|
-
|
|
465
|
+
this.pending = null;
|
|
459
466
|
}
|
|
460
467
|
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
Mappings.prototype.advance = function advance (str) {
|
|
465
|
-
if (!str) { return; }
|
|
468
|
+
advance(str) {
|
|
469
|
+
if (!str) return;
|
|
466
470
|
|
|
467
|
-
|
|
471
|
+
const lines = str.split('\n');
|
|
468
472
|
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
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;
|
|
473
479
|
}
|
|
474
|
-
this.generatedCodeColumn = 0;
|
|
475
|
-
}
|
|
476
480
|
|
|
477
|
-
|
|
478
|
-
}
|
|
481
|
+
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
482
|
+
}
|
|
483
|
+
}
|
|
479
484
|
|
|
480
|
-
|
|
485
|
+
const n = '\n';
|
|
481
486
|
|
|
482
|
-
|
|
487
|
+
const warned = {
|
|
483
488
|
insertLeft: false,
|
|
484
489
|
insertRight: false,
|
|
485
|
-
storeName: false
|
|
486
|
-
};
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
});
|
|
508
|
-
|
|
509
|
-
this.byStart[0] = chunk;
|
|
510
|
-
this.byEnd[string.length] = chunk;
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
MagicString.prototype.addSourcemapLocation = function addSourcemapLocation (char) {
|
|
514
|
-
this.sourcemapLocations.add(char);
|
|
515
|
-
};
|
|
516
|
-
|
|
517
|
-
MagicString.prototype.append = function append (content) {
|
|
518
|
-
if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
|
|
519
|
-
|
|
520
|
-
this.outro += content;
|
|
521
|
-
return this;
|
|
522
|
-
};
|
|
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
|
+
});
|
|
523
512
|
|
|
524
|
-
|
|
525
|
-
|
|
513
|
+
this.byStart[0] = chunk;
|
|
514
|
+
this.byEnd[string.length] = chunk;
|
|
515
|
+
}
|
|
526
516
|
|
|
527
|
-
|
|
517
|
+
addSourcemapLocation(char) {
|
|
518
|
+
this.sourcemapLocations.add(char);
|
|
519
|
+
}
|
|
528
520
|
|
|
529
|
-
|
|
521
|
+
append(content) {
|
|
522
|
+
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
530
523
|
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
} else {
|
|
534
|
-
this.intro += content;
|
|
524
|
+
this.outro += content;
|
|
525
|
+
return this;
|
|
535
526
|
}
|
|
536
|
-
return this;
|
|
537
|
-
};
|
|
538
527
|
|
|
539
|
-
|
|
540
|
-
|
|
528
|
+
appendLeft(index, content) {
|
|
529
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
541
530
|
|
|
542
|
-
|
|
531
|
+
this._split(index);
|
|
543
532
|
|
|
544
|
-
|
|
533
|
+
const chunk = this.byEnd[index];
|
|
545
534
|
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
535
|
+
if (chunk) {
|
|
536
|
+
chunk.appendLeft(content);
|
|
537
|
+
} else {
|
|
538
|
+
this.intro += content;
|
|
539
|
+
}
|
|
540
|
+
return this;
|
|
550
541
|
}
|
|
551
|
-
return this;
|
|
552
|
-
};
|
|
553
|
-
|
|
554
|
-
MagicString.prototype.clone = function clone () {
|
|
555
|
-
var cloned = new MagicString(this.original, { filename: this.filename });
|
|
556
542
|
|
|
557
|
-
|
|
558
|
-
|
|
543
|
+
appendRight(index, content) {
|
|
544
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
559
545
|
|
|
560
|
-
|
|
561
|
-
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
562
|
-
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
546
|
+
this._split(index);
|
|
563
547
|
|
|
564
|
-
|
|
565
|
-
var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
548
|
+
const chunk = this.byStart[index];
|
|
566
549
|
|
|
567
|
-
if (
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
clonedChunk = nextClonedChunk;
|
|
550
|
+
if (chunk) {
|
|
551
|
+
chunk.appendRight(content);
|
|
552
|
+
} else {
|
|
553
|
+
this.outro += content;
|
|
572
554
|
}
|
|
573
|
-
|
|
574
|
-
originalChunk = nextOriginalChunk;
|
|
555
|
+
return this;
|
|
575
556
|
}
|
|
576
557
|
|
|
577
|
-
|
|
558
|
+
clone() {
|
|
559
|
+
const cloned = new MagicString(this.original, { filename: this.filename });
|
|
578
560
|
|
|
579
|
-
|
|
580
|
-
cloned.
|
|
581
|
-
}
|
|
561
|
+
let originalChunk = this.firstChunk;
|
|
562
|
+
let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
|
|
582
563
|
|
|
583
|
-
|
|
564
|
+
while (originalChunk) {
|
|
565
|
+
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
566
|
+
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
584
567
|
|
|
585
|
-
|
|
586
|
-
|
|
568
|
+
const nextOriginalChunk = originalChunk.next;
|
|
569
|
+
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
587
570
|
|
|
588
|
-
|
|
589
|
-
|
|
571
|
+
if (nextClonedChunk) {
|
|
572
|
+
clonedChunk.next = nextClonedChunk;
|
|
573
|
+
nextClonedChunk.previous = clonedChunk;
|
|
590
574
|
|
|
591
|
-
|
|
592
|
-
|
|
575
|
+
clonedChunk = nextClonedChunk;
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
originalChunk = nextOriginalChunk;
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
cloned.lastChunk = clonedChunk;
|
|
593
582
|
|
|
594
|
-
|
|
583
|
+
if (this.indentExclusionRanges) {
|
|
584
|
+
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
585
|
+
}
|
|
595
586
|
|
|
596
|
-
|
|
597
|
-
var names = Object.keys(this.storedNames);
|
|
598
|
-
var mappings = new Mappings(options.hires);
|
|
587
|
+
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
599
588
|
|
|
600
|
-
|
|
589
|
+
cloned.intro = this.intro;
|
|
590
|
+
cloned.outro = this.outro;
|
|
601
591
|
|
|
602
|
-
|
|
603
|
-
mappings.advance(this.intro);
|
|
592
|
+
return cloned;
|
|
604
593
|
}
|
|
605
594
|
|
|
606
|
-
|
|
607
|
-
|
|
595
|
+
generateDecodedMap(options) {
|
|
596
|
+
options = options || {};
|
|
608
597
|
|
|
609
|
-
|
|
598
|
+
const sourceIndex = 0;
|
|
599
|
+
const names = Object.keys(this.storedNames);
|
|
600
|
+
const mappings = new Mappings(options.hires);
|
|
610
601
|
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
loc,
|
|
616
|
-
chunk.storeName ? names.indexOf(chunk.original) : -1
|
|
617
|
-
);
|
|
618
|
-
} else {
|
|
619
|
-
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);
|
|
620
606
|
}
|
|
621
607
|
|
|
622
|
-
|
|
623
|
-
|
|
608
|
+
this.firstChunk.eachNext((chunk) => {
|
|
609
|
+
const loc = locate(chunk.start);
|
|
624
610
|
|
|
625
|
-
|
|
626
|
-
file: options.file ? options.file.split(/[/\\]/).pop() : null,
|
|
627
|
-
sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
|
|
628
|
-
sourcesContent: options.includeContent ? [this.original] : [null],
|
|
629
|
-
names: names,
|
|
630
|
-
mappings: mappings.raw
|
|
631
|
-
};
|
|
632
|
-
};
|
|
611
|
+
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
633
612
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
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
|
+
}
|
|
637
623
|
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
};
|
|
624
|
+
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
625
|
+
});
|
|
641
626
|
|
|
642
|
-
|
|
643
|
-
|
|
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
|
+
}
|
|
644
635
|
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
indentStr = undefined;
|
|
636
|
+
generateMap(options) {
|
|
637
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
648
638
|
}
|
|
649
639
|
|
|
650
|
-
|
|
640
|
+
getIndentString() {
|
|
641
|
+
return this.indentStr === null ? '\t' : this.indentStr;
|
|
642
|
+
}
|
|
651
643
|
|
|
652
|
-
|
|
644
|
+
indent(indentStr, options) {
|
|
645
|
+
const pattern = /^[^\r\n]/gm;
|
|
653
646
|
|
|
654
|
-
|
|
647
|
+
if (isObject$1(indentStr)) {
|
|
648
|
+
options = indentStr;
|
|
649
|
+
indentStr = undefined;
|
|
650
|
+
}
|
|
655
651
|
|
|
656
|
-
|
|
657
|
-
var isExcluded = {};
|
|
652
|
+
indentStr = indentStr !== undefined ? indentStr : this.indentStr || '\t';
|
|
658
653
|
|
|
659
|
-
|
|
660
|
-
var exclusions =
|
|
661
|
-
typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
|
|
662
|
-
exclusions.forEach(function (exclusion) {
|
|
663
|
-
for (var i = exclusion[0]; i < exclusion[1]; i += 1) {
|
|
664
|
-
isExcluded[i] = true;
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
}
|
|
654
|
+
if (indentStr === '') return this; // noop
|
|
668
655
|
|
|
669
|
-
|
|
670
|
-
var replacer = function (match) {
|
|
671
|
-
if (shouldIndentNextCharacter) { return ("" + indentStr + match); }
|
|
672
|
-
shouldIndentNextCharacter = true;
|
|
673
|
-
return match;
|
|
674
|
-
};
|
|
656
|
+
options = options || {};
|
|
675
657
|
|
|
676
|
-
|
|
658
|
+
// Process exclusion ranges
|
|
659
|
+
const isExcluded = {};
|
|
677
660
|
|
|
678
|
-
|
|
679
|
-
|
|
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
|
+
}
|
|
680
670
|
|
|
681
|
-
|
|
682
|
-
|
|
671
|
+
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
672
|
+
const replacer = (match) => {
|
|
673
|
+
if (shouldIndentNextCharacter) return `${indentStr}${match}`;
|
|
674
|
+
shouldIndentNextCharacter = true;
|
|
675
|
+
return match;
|
|
676
|
+
};
|
|
683
677
|
|
|
684
|
-
|
|
685
|
-
if (!isExcluded[charIndex]) {
|
|
686
|
-
chunk.content = chunk.content.replace(pattern, replacer);
|
|
678
|
+
this.intro = this.intro.replace(pattern, replacer);
|
|
687
679
|
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
}
|
|
691
|
-
}
|
|
692
|
-
} else {
|
|
693
|
-
charIndex = chunk.start;
|
|
680
|
+
let charIndex = 0;
|
|
681
|
+
let chunk = this.firstChunk;
|
|
694
682
|
|
|
695
|
-
|
|
683
|
+
while (chunk) {
|
|
684
|
+
const end = chunk.end;
|
|
685
|
+
|
|
686
|
+
if (chunk.edited) {
|
|
696
687
|
if (!isExcluded[charIndex]) {
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
if (
|
|
700
|
-
shouldIndentNextCharacter =
|
|
701
|
-
} else if (char !== '\r' && shouldIndentNextCharacter) {
|
|
702
|
-
shouldIndentNextCharacter = false;
|
|
703
|
-
|
|
704
|
-
if (charIndex === chunk.start) {
|
|
705
|
-
chunk.prependRight(indentStr);
|
|
706
|
-
} else {
|
|
707
|
-
this._splitChunk(chunk, charIndex);
|
|
708
|
-
chunk = chunk.next;
|
|
709
|
-
chunk.prependRight(indentStr);
|
|
710
|
-
}
|
|
688
|
+
chunk.content = chunk.content.replace(pattern, replacer);
|
|
689
|
+
|
|
690
|
+
if (chunk.content.length) {
|
|
691
|
+
shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
|
|
711
692
|
}
|
|
712
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
|
+
}
|
|
713
715
|
|
|
714
|
-
|
|
716
|
+
charIndex += 1;
|
|
717
|
+
}
|
|
715
718
|
}
|
|
719
|
+
|
|
720
|
+
charIndex = chunk.end;
|
|
721
|
+
chunk = chunk.next;
|
|
716
722
|
}
|
|
717
723
|
|
|
718
|
-
|
|
719
|
-
chunk = chunk.next;
|
|
720
|
-
}
|
|
724
|
+
this.outro = this.outro.replace(pattern, replacer);
|
|
721
725
|
|
|
722
|
-
|
|
726
|
+
return this;
|
|
727
|
+
}
|
|
723
728
|
|
|
724
|
-
|
|
725
|
-
|
|
729
|
+
insert() {
|
|
730
|
+
throw new Error(
|
|
731
|
+
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
|
|
732
|
+
);
|
|
733
|
+
}
|
|
726
734
|
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
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
|
+
}
|
|
730
742
|
|
|
731
|
-
|
|
732
|
-
if (!warned.insertLeft) {
|
|
733
|
-
console.warn('magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'); // eslint-disable-line no-console
|
|
734
|
-
warned.insertLeft = true;
|
|
743
|
+
return this.appendLeft(index, content);
|
|
735
744
|
}
|
|
736
745
|
|
|
737
|
-
|
|
738
|
-
|
|
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
|
+
}
|
|
739
753
|
|
|
740
|
-
|
|
741
|
-
if (!warned.insertRight) {
|
|
742
|
-
console.warn('magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'); // eslint-disable-line no-console
|
|
743
|
-
warned.insertRight = true;
|
|
754
|
+
return this.prependRight(index, content);
|
|
744
755
|
}
|
|
745
756
|
|
|
746
|
-
|
|
747
|
-
|
|
757
|
+
move(start, end, index) {
|
|
758
|
+
if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
|
|
748
759
|
|
|
749
|
-
|
|
750
|
-
|
|
760
|
+
this._split(start);
|
|
761
|
+
this._split(end);
|
|
762
|
+
this._split(index);
|
|
751
763
|
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
this._split(index);
|
|
764
|
+
const first = this.byStart[start];
|
|
765
|
+
const last = this.byEnd[end];
|
|
755
766
|
|
|
756
|
-
|
|
757
|
-
|
|
767
|
+
const oldLeft = first.previous;
|
|
768
|
+
const oldRight = last.next;
|
|
758
769
|
|
|
759
|
-
|
|
760
|
-
|
|
770
|
+
const newRight = this.byStart[index];
|
|
771
|
+
if (!newRight && last === this.lastChunk) return this;
|
|
772
|
+
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
761
773
|
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
var newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
774
|
+
if (oldLeft) oldLeft.next = oldRight;
|
|
775
|
+
if (oldRight) oldRight.previous = oldLeft;
|
|
765
776
|
|
|
766
|
-
|
|
767
|
-
|
|
777
|
+
if (newLeft) newLeft.next = first;
|
|
778
|
+
if (newRight) newRight.previous = last;
|
|
768
779
|
|
|
769
|
-
|
|
770
|
-
|
|
780
|
+
if (!first.previous) this.firstChunk = last.next;
|
|
781
|
+
if (!last.next) {
|
|
782
|
+
this.lastChunk = first.previous;
|
|
783
|
+
this.lastChunk.next = null;
|
|
784
|
+
}
|
|
771
785
|
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
this.lastChunk = first.previous;
|
|
775
|
-
this.lastChunk.next = null;
|
|
776
|
-
}
|
|
786
|
+
first.previous = newLeft;
|
|
787
|
+
last.next = newRight || null;
|
|
777
788
|
|
|
778
|
-
|
|
779
|
-
|
|
789
|
+
if (!newLeft) this.firstChunk = first;
|
|
790
|
+
if (!newRight) this.lastChunk = last;
|
|
791
|
+
return this;
|
|
792
|
+
}
|
|
780
793
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
return this;
|
|
784
|
-
};
|
|
794
|
+
overwrite(start, end, content, options) {
|
|
795
|
+
if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
|
|
785
796
|
|
|
786
|
-
|
|
787
|
-
|
|
797
|
+
while (start < 0) start += this.original.length;
|
|
798
|
+
while (end < 0) end += this.original.length;
|
|
788
799
|
|
|
789
|
-
|
|
790
|
-
|
|
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
|
+
);
|
|
791
805
|
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
{ throw new Error('Cannot overwrite a zero-length range – use appendLeft or prependRight instead'); }
|
|
806
|
+
this._split(start);
|
|
807
|
+
this._split(end);
|
|
795
808
|
|
|
796
|
-
|
|
797
|
-
|
|
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
|
+
}
|
|
798
816
|
|
|
799
|
-
|
|
800
|
-
if (!warned.storeName) {
|
|
801
|
-
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
|
|
802
|
-
warned.storeName = true;
|
|
817
|
+
options = { storeName: true };
|
|
803
818
|
}
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
var first = this.byStart[start];
|
|
816
|
-
var last = this.byEnd[end];
|
|
817
|
-
|
|
818
|
-
if (first) {
|
|
819
|
-
if (end > first.end && first.next !== this.byStart[first.end]) {
|
|
820
|
-
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
|
+
});
|
|
821
829
|
}
|
|
822
830
|
|
|
823
|
-
first
|
|
831
|
+
const first = this.byStart[start];
|
|
832
|
+
const last = this.byEnd[end];
|
|
824
833
|
|
|
825
|
-
if (first
|
|
826
|
-
|
|
834
|
+
if (first) {
|
|
835
|
+
let chunk = first;
|
|
827
836
|
while (chunk !== last) {
|
|
828
|
-
chunk.
|
|
837
|
+
if (chunk.next !== this.byStart[chunk.end]) {
|
|
838
|
+
throw new Error('Cannot overwrite across a split point');
|
|
839
|
+
}
|
|
829
840
|
chunk = chunk.next;
|
|
841
|
+
chunk.edit('', false);
|
|
830
842
|
}
|
|
831
843
|
|
|
832
|
-
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
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);
|
|
837
848
|
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
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;
|
|
841
854
|
}
|
|
842
|
-
return this;
|
|
843
|
-
};
|
|
844
|
-
|
|
845
|
-
MagicString.prototype.prepend = function prepend (content) {
|
|
846
|
-
if (typeof content !== 'string') { throw new TypeError('outro content must be a string'); }
|
|
847
|
-
|
|
848
|
-
this.intro = content + this.intro;
|
|
849
|
-
return this;
|
|
850
|
-
};
|
|
851
|
-
|
|
852
|
-
MagicString.prototype.prependLeft = function prependLeft (index, content) {
|
|
853
|
-
if (typeof content !== 'string') { throw new TypeError('inserted content must be a string'); }
|
|
854
|
-
|
|
855
|
-
this._split(index);
|
|
856
855
|
|
|
857
|
-
|
|
856
|
+
prepend(content) {
|
|
857
|
+
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
858
858
|
|
|
859
|
-
if (chunk) {
|
|
860
|
-
chunk.prependLeft(content);
|
|
861
|
-
} else {
|
|
862
859
|
this.intro = content + this.intro;
|
|
860
|
+
return this;
|
|
863
861
|
}
|
|
864
|
-
return this;
|
|
865
|
-
};
|
|
866
862
|
|
|
867
|
-
|
|
868
|
-
|
|
863
|
+
prependLeft(index, content) {
|
|
864
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
869
865
|
|
|
870
|
-
|
|
866
|
+
this._split(index);
|
|
871
867
|
|
|
872
|
-
|
|
868
|
+
const chunk = this.byEnd[index];
|
|
873
869
|
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
870
|
+
if (chunk) {
|
|
871
|
+
chunk.prependLeft(content);
|
|
872
|
+
} else {
|
|
873
|
+
this.intro = content + this.intro;
|
|
874
|
+
}
|
|
875
|
+
return this;
|
|
878
876
|
}
|
|
879
|
-
return this;
|
|
880
|
-
};
|
|
881
|
-
|
|
882
|
-
MagicString.prototype.remove = function remove (start, end) {
|
|
883
|
-
while (start < 0) { start += this.original.length; }
|
|
884
|
-
while (end < 0) { end += this.original.length; }
|
|
885
|
-
|
|
886
|
-
if (start === end) { return this; }
|
|
887
877
|
|
|
888
|
-
|
|
889
|
-
|
|
878
|
+
prependRight(index, content) {
|
|
879
|
+
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
890
880
|
|
|
891
|
-
|
|
892
|
-
this._split(end);
|
|
881
|
+
this._split(index);
|
|
893
882
|
|
|
894
|
-
|
|
883
|
+
const chunk = this.byStart[index];
|
|
895
884
|
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
902
|
-
}
|
|
903
|
-
return this;
|
|
904
|
-
};
|
|
905
|
-
|
|
906
|
-
MagicString.prototype.lastChar = function lastChar () {
|
|
907
|
-
if (this.outro.length)
|
|
908
|
-
{ return this.outro[this.outro.length - 1]; }
|
|
909
|
-
var chunk = this.lastChunk;
|
|
910
|
-
do {
|
|
911
|
-
if (chunk.outro.length)
|
|
912
|
-
{ return chunk.outro[chunk.outro.length - 1]; }
|
|
913
|
-
if (chunk.content.length)
|
|
914
|
-
{ return chunk.content[chunk.content.length - 1]; }
|
|
915
|
-
if (chunk.intro.length)
|
|
916
|
-
{ return chunk.intro[chunk.intro.length - 1]; }
|
|
917
|
-
} while (chunk = chunk.previous);
|
|
918
|
-
if (this.intro.length)
|
|
919
|
-
{ return this.intro[this.intro.length - 1]; }
|
|
920
|
-
return '';
|
|
921
|
-
};
|
|
922
|
-
|
|
923
|
-
MagicString.prototype.lastLine = function lastLine () {
|
|
924
|
-
var lineIndex = this.outro.lastIndexOf(n);
|
|
925
|
-
if (lineIndex !== -1)
|
|
926
|
-
{ return this.outro.substr(lineIndex + 1); }
|
|
927
|
-
var lineStr = this.outro;
|
|
928
|
-
var chunk = this.lastChunk;
|
|
929
|
-
do {
|
|
930
|
-
if (chunk.outro.length > 0) {
|
|
931
|
-
lineIndex = chunk.outro.lastIndexOf(n);
|
|
932
|
-
if (lineIndex !== -1)
|
|
933
|
-
{ return chunk.outro.substr(lineIndex + 1) + lineStr; }
|
|
934
|
-
lineStr = chunk.outro + lineStr;
|
|
885
|
+
if (chunk) {
|
|
886
|
+
chunk.prependRight(content);
|
|
887
|
+
} else {
|
|
888
|
+
this.outro = content + this.outro;
|
|
935
889
|
}
|
|
890
|
+
return this;
|
|
891
|
+
}
|
|
936
892
|
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
{ return chunk.content.substr(lineIndex + 1) + lineStr; }
|
|
941
|
-
lineStr = chunk.content + lineStr;
|
|
942
|
-
}
|
|
893
|
+
remove(start, end) {
|
|
894
|
+
while (start < 0) start += this.original.length;
|
|
895
|
+
while (end < 0) end += this.original.length;
|
|
943
896
|
|
|
944
|
-
if (
|
|
945
|
-
lineIndex = chunk.intro.lastIndexOf(n);
|
|
946
|
-
if (lineIndex !== -1)
|
|
947
|
-
{ return chunk.intro.substr(lineIndex + 1) + lineStr; }
|
|
948
|
-
lineStr = chunk.intro + lineStr;
|
|
949
|
-
}
|
|
950
|
-
} while (chunk = chunk.previous);
|
|
951
|
-
lineIndex = this.intro.lastIndexOf(n);
|
|
952
|
-
if (lineIndex !== -1)
|
|
953
|
-
{ return this.intro.substr(lineIndex + 1) + lineStr; }
|
|
954
|
-
return this.intro + lineStr;
|
|
955
|
-
};
|
|
897
|
+
if (start === end) return this;
|
|
956
898
|
|
|
957
|
-
|
|
958
|
-
if (
|
|
959
|
-
if ( end === void 0 ) end = this.original.length;
|
|
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');
|
|
960
901
|
|
|
961
|
-
|
|
962
|
-
|
|
902
|
+
this._split(start);
|
|
903
|
+
this._split(end);
|
|
963
904
|
|
|
964
|
-
|
|
905
|
+
let chunk = this.byStart[start];
|
|
965
906
|
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
907
|
+
while (chunk) {
|
|
908
|
+
chunk.intro = '';
|
|
909
|
+
chunk.outro = '';
|
|
910
|
+
chunk.edit('');
|
|
911
|
+
|
|
912
|
+
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
972
913
|
}
|
|
914
|
+
return this;
|
|
915
|
+
}
|
|
973
916
|
|
|
974
|
-
|
|
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 '';
|
|
975
927
|
}
|
|
976
928
|
|
|
977
|
-
|
|
978
|
-
|
|
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
|
+
}
|
|
979
940
|
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
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
|
+
}
|
|
985
946
|
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
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
|
+
}
|
|
989
957
|
|
|
990
|
-
|
|
991
|
-
|
|
958
|
+
slice(start = 0, end = this.original.length) {
|
|
959
|
+
while (start < 0) start += this.original.length;
|
|
960
|
+
while (end < 0) end += this.original.length;
|
|
992
961
|
|
|
993
|
-
result
|
|
962
|
+
let result = '';
|
|
994
963
|
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
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
|
+
}
|
|
998
971
|
|
|
999
|
-
|
|
1000
|
-
break;
|
|
972
|
+
chunk = chunk.next;
|
|
1001
973
|
}
|
|
1002
974
|
|
|
1003
|
-
chunk
|
|
1004
|
-
|
|
975
|
+
if (chunk && chunk.edited && chunk.start !== start)
|
|
976
|
+
throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
1005
977
|
|
|
1006
|
-
|
|
1007
|
-
|
|
978
|
+
const startChunk = chunk;
|
|
979
|
+
while (chunk) {
|
|
980
|
+
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
|
|
981
|
+
result += chunk.intro;
|
|
982
|
+
}
|
|
1008
983
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
clone.remove(0, start);
|
|
1013
|
-
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.`);
|
|
1014
987
|
|
|
1015
|
-
|
|
1016
|
-
|
|
988
|
+
const sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
989
|
+
const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
1017
990
|
|
|
1018
|
-
|
|
1019
|
-
if (this.byStart[index] || this.byEnd[index]) { return; }
|
|
991
|
+
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
1020
992
|
|
|
1021
|
-
|
|
1022
|
-
|
|
993
|
+
if (chunk.outro && (!containsEnd || chunk.end === end)) {
|
|
994
|
+
result += chunk.outro;
|
|
995
|
+
}
|
|
1023
996
|
|
|
1024
|
-
|
|
1025
|
-
|
|
997
|
+
if (containsEnd) {
|
|
998
|
+
break;
|
|
999
|
+
}
|
|
1026
1000
|
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
};
|
|
1001
|
+
chunk = chunk.next;
|
|
1002
|
+
}
|
|
1030
1003
|
|
|
1031
|
-
|
|
1032
|
-
if (chunk.edited && chunk.content.length) {
|
|
1033
|
-
// zero-length edited chunks are a special case (overlapping replacements)
|
|
1034
|
-
var loc = getLocator$1(this.original)(index);
|
|
1035
|
-
throw new Error(
|
|
1036
|
-
("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")")
|
|
1037
|
-
);
|
|
1004
|
+
return result;
|
|
1038
1005
|
}
|
|
1039
1006
|
|
|
1040
|
-
|
|
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);
|
|
1041
1012
|
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
this.byEnd[newChunk.end] = newChunk;
|
|
1013
|
+
return clone;
|
|
1014
|
+
}
|
|
1045
1015
|
|
|
1046
|
-
|
|
1016
|
+
_split(index) {
|
|
1017
|
+
if (this.byStart[index] || this.byEnd[index]) return;
|
|
1047
1018
|
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
};
|
|
1019
|
+
let chunk = this.lastSearchedChunk;
|
|
1020
|
+
const searchForward = index > chunk.end;
|
|
1051
1021
|
|
|
1052
|
-
|
|
1053
|
-
|
|
1022
|
+
while (chunk) {
|
|
1023
|
+
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
1054
1024
|
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
str += chunk.toString();
|
|
1058
|
-
chunk = chunk.next;
|
|
1025
|
+
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
1026
|
+
}
|
|
1059
1027
|
}
|
|
1060
1028
|
|
|
1061
|
-
|
|
1062
|
-
|
|
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
|
+
}
|
|
1063
1037
|
|
|
1064
|
-
|
|
1065
|
-
var chunk = this.firstChunk;
|
|
1066
|
-
do {
|
|
1067
|
-
if (chunk.intro.length && chunk.intro.trim() ||
|
|
1068
|
-
chunk.content.length && chunk.content.trim() ||
|
|
1069
|
-
chunk.outro.length && chunk.outro.trim())
|
|
1070
|
-
{ return false; }
|
|
1071
|
-
} while (chunk = chunk.next);
|
|
1072
|
-
return true;
|
|
1073
|
-
};
|
|
1038
|
+
const newChunk = chunk.split(index);
|
|
1074
1039
|
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
do {
|
|
1079
|
-
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
1080
|
-
} while (chunk = chunk.next);
|
|
1081
|
-
return length;
|
|
1082
|
-
};
|
|
1040
|
+
this.byEnd[index] = chunk;
|
|
1041
|
+
this.byStart[index] = newChunk;
|
|
1042
|
+
this.byEnd[newChunk.end] = newChunk;
|
|
1083
1043
|
|
|
1084
|
-
|
|
1085
|
-
return this.trim('[\\r\\n]');
|
|
1086
|
-
};
|
|
1044
|
+
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
1087
1045
|
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
}
|
|
1046
|
+
this.lastSearchedChunk = chunk;
|
|
1047
|
+
return true;
|
|
1048
|
+
}
|
|
1091
1049
|
|
|
1092
|
-
|
|
1093
|
-
|
|
1050
|
+
toString() {
|
|
1051
|
+
let str = this.intro;
|
|
1094
1052
|
|
|
1095
|
-
|
|
1096
|
-
|
|
1053
|
+
let chunk = this.firstChunk;
|
|
1054
|
+
while (chunk) {
|
|
1055
|
+
str += chunk.toString();
|
|
1056
|
+
chunk = chunk.next;
|
|
1057
|
+
}
|
|
1097
1058
|
|
|
1098
|
-
|
|
1059
|
+
return str + this.outro;
|
|
1060
|
+
}
|
|
1099
1061
|
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
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
|
+
}
|
|
1103
1074
|
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
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
|
+
}
|
|
1109
1083
|
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
}
|
|
1084
|
+
trimLines() {
|
|
1085
|
+
return this.trim('[\\r\\n]');
|
|
1086
|
+
}
|
|
1114
1087
|
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
}
|
|
1088
|
+
trim(charType) {
|
|
1089
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
1090
|
+
}
|
|
1118
1091
|
|
|
1119
|
-
|
|
1120
|
-
|
|
1092
|
+
trimEndAborted(charType) {
|
|
1093
|
+
const rx = new RegExp((charType || '\\s') + '+$');
|
|
1121
1094
|
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
return this;
|
|
1125
|
-
};
|
|
1126
|
-
MagicString.prototype.trimStartAborted = function trimStartAborted (charType) {
|
|
1127
|
-
var rx = new RegExp('^' + (charType || '\\s') + '+');
|
|
1095
|
+
this.outro = this.outro.replace(rx, '');
|
|
1096
|
+
if (this.outro.length) return true;
|
|
1128
1097
|
|
|
1129
|
-
|
|
1130
|
-
if (this.intro.length) { return true; }
|
|
1098
|
+
let chunk = this.lastChunk;
|
|
1131
1099
|
|
|
1132
|
-
|
|
1100
|
+
do {
|
|
1101
|
+
const end = chunk.end;
|
|
1102
|
+
const aborted = chunk.trimEnd(rx);
|
|
1133
1103
|
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
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
|
+
}
|
|
1137
1109
|
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1110
|
+
this.byEnd[chunk.end] = chunk;
|
|
1111
|
+
this.byStart[chunk.next.start] = chunk.next;
|
|
1112
|
+
this.byEnd[chunk.next.end] = chunk.next;
|
|
1113
|
+
}
|
|
1141
1114
|
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
}
|
|
1115
|
+
if (aborted) return true;
|
|
1116
|
+
chunk = chunk.previous;
|
|
1117
|
+
} while (chunk);
|
|
1146
1118
|
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
} while (chunk);
|
|
1119
|
+
return false;
|
|
1120
|
+
}
|
|
1150
1121
|
|
|
1151
|
-
|
|
1152
|
-
|
|
1122
|
+
trimEnd(charType) {
|
|
1123
|
+
this.trimEndAborted(charType);
|
|
1124
|
+
return this;
|
|
1125
|
+
}
|
|
1126
|
+
trimStartAborted(charType) {
|
|
1127
|
+
const rx = new RegExp('^' + (charType || '\\s') + '+');
|
|
1153
1128
|
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
return this;
|
|
1157
|
-
};
|
|
1129
|
+
this.intro = this.intro.replace(rx, '');
|
|
1130
|
+
if (this.intro.length) return true;
|
|
1158
1131
|
|
|
1159
|
-
|
|
1132
|
+
let chunk = this.firstChunk;
|
|
1160
1133
|
|
|
1161
|
-
|
|
1162
|
-
|
|
1134
|
+
do {
|
|
1135
|
+
const end = chunk.end;
|
|
1136
|
+
const aborted = chunk.trimStart(rx);
|
|
1163
1137
|
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
this.uniqueSources = [];
|
|
1168
|
-
this.uniqueSourceIndexByFilename = {};
|
|
1169
|
-
};
|
|
1138
|
+
if (chunk.end !== end) {
|
|
1139
|
+
// special case...
|
|
1140
|
+
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
1170
1141
|
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
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);
|
|
1179
1150
|
|
|
1180
|
-
|
|
1181
|
-
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;
|
|
1182
1152
|
}
|
|
1183
1153
|
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1154
|
+
trimStart(charType) {
|
|
1155
|
+
this.trimStartAborted(charType);
|
|
1156
|
+
return this;
|
|
1157
|
+
}
|
|
1187
1158
|
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
source.separator = this.separator;
|
|
1159
|
+
hasChanged() {
|
|
1160
|
+
return this.original !== this.toString();
|
|
1191
1161
|
}
|
|
1192
1162
|
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
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);
|
|
1201
1176
|
}
|
|
1202
1177
|
}
|
|
1178
|
+
function matchAll(re, str) {
|
|
1179
|
+
let match;
|
|
1180
|
+
const matches = [];
|
|
1181
|
+
while ((match = re.exec(str))) {
|
|
1182
|
+
matches.push(match);
|
|
1183
|
+
}
|
|
1184
|
+
return matches;
|
|
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;
|
|
1203
1206
|
}
|
|
1207
|
+
}
|
|
1204
1208
|
|
|
1205
|
-
|
|
1206
|
-
return this;
|
|
1207
|
-
};
|
|
1209
|
+
const hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1208
1210
|
|
|
1209
|
-
Bundle$1
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
separator
|
|
1213
|
-
|
|
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
|
+
}
|
|
1214
1219
|
|
|
1215
|
-
|
|
1216
|
-
|
|
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
|
+
}
|
|
1217
1228
|
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
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
|
+
}
|
|
1223
1234
|
|
|
1224
|
-
|
|
1225
|
-
|
|
1226
|
-
filename: source.filename,
|
|
1227
|
-
content: source.content.clone(),
|
|
1228
|
-
separator: source.separator
|
|
1235
|
+
['filename', 'indentExclusionRanges', 'separator'].forEach((option) => {
|
|
1236
|
+
if (!hasOwnProp.call(source, option)) source[option] = source.content[option];
|
|
1229
1237
|
});
|
|
1230
|
-
});
|
|
1231
1238
|
|
|
1232
|
-
|
|
1233
|
-
|
|
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
|
+
}
|
|
1243
|
+
|
|
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
|
+
}
|
|
1234
1255
|
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1256
|
+
this.sources.push(source);
|
|
1257
|
+
return this;
|
|
1258
|
+
}
|
|
1238
1259
|
|
|
1239
|
-
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
|
|
1260
|
+
append(str, options) {
|
|
1261
|
+
this.addSource({
|
|
1262
|
+
content: new MagicString(str),
|
|
1263
|
+
separator: (options && options.separator) || '',
|
|
1243
1264
|
});
|
|
1244
|
-
});
|
|
1245
1265
|
|
|
1246
|
-
|
|
1266
|
+
return this;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
clone() {
|
|
1270
|
+
const bundle = new Bundle$1({
|
|
1271
|
+
intro: this.intro,
|
|
1272
|
+
separator: this.separator,
|
|
1273
|
+
});
|
|
1274
|
+
|
|
1275
|
+
this.sources.forEach((source) => {
|
|
1276
|
+
bundle.addSource({
|
|
1277
|
+
filename: source.filename,
|
|
1278
|
+
content: source.content.clone(),
|
|
1279
|
+
separator: source.separator,
|
|
1280
|
+
});
|
|
1281
|
+
});
|
|
1247
1282
|
|
|
1248
|
-
|
|
1249
|
-
mappings.advance(this.intro);
|
|
1283
|
+
return bundle;
|
|
1250
1284
|
}
|
|
1251
1285
|
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
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
|
+
});
|
|
1256
1293
|
|
|
1257
|
-
|
|
1258
|
-
var magicString = source.content;
|
|
1259
|
-
var locate = getLocator$1(magicString.original);
|
|
1294
|
+
const mappings = new Mappings(options.hires);
|
|
1260
1295
|
|
|
1261
|
-
if (
|
|
1262
|
-
mappings.advance(
|
|
1296
|
+
if (this.intro) {
|
|
1297
|
+
mappings.advance(this.intro);
|
|
1263
1298
|
}
|
|
1264
1299
|
|
|
1265
|
-
|
|
1266
|
-
|
|
1300
|
+
this.sources.forEach((source, i) => {
|
|
1301
|
+
if (i > 0) {
|
|
1302
|
+
mappings.advance(this.separator);
|
|
1303
|
+
}
|
|
1267
1304
|
|
|
1268
|
-
|
|
1305
|
+
const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
|
|
1306
|
+
const magicString = source.content;
|
|
1307
|
+
const locate = getLocator$1(magicString.original);
|
|
1269
1308
|
|
|
1270
|
-
if (
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
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
|
+
}
|
|
1278
1335
|
} else {
|
|
1279
|
-
mappings.
|
|
1280
|
-
sourceIndex,
|
|
1281
|
-
chunk,
|
|
1282
|
-
magicString.original,
|
|
1283
|
-
loc,
|
|
1284
|
-
magicString.sourcemapLocations
|
|
1285
|
-
);
|
|
1336
|
+
mappings.advance(chunk.content);
|
|
1286
1337
|
}
|
|
1287
|
-
} else {
|
|
1288
|
-
mappings.advance(chunk.content);
|
|
1289
|
-
}
|
|
1290
1338
|
|
|
1291
|
-
|
|
1292
|
-
|
|
1339
|
+
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
1340
|
+
});
|
|
1293
1341
|
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1342
|
+
if (magicString.outro) {
|
|
1343
|
+
mappings.advance(magicString.outro);
|
|
1344
|
+
}
|
|
1345
|
+
});
|
|
1298
1346
|
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
}
|
|
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
|
+
}
|
|
1311
1359
|
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
}
|
|
1360
|
+
generateMap(options) {
|
|
1361
|
+
return new SourceMap(this.generateDecodedMap(options));
|
|
1362
|
+
}
|
|
1315
1363
|
|
|
1316
|
-
|
|
1317
|
-
|
|
1364
|
+
getIndentString() {
|
|
1365
|
+
const indentStringCounts = {};
|
|
1318
1366
|
|
|
1319
|
-
|
|
1320
|
-
|
|
1367
|
+
this.sources.forEach((source) => {
|
|
1368
|
+
const indentStr = source.content.indentStr;
|
|
1321
1369
|
|
|
1322
|
-
|
|
1370
|
+
if (indentStr === null) return;
|
|
1323
1371
|
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1372
|
+
if (!indentStringCounts[indentStr]) indentStringCounts[indentStr] = 0;
|
|
1373
|
+
indentStringCounts[indentStr] += 1;
|
|
1374
|
+
});
|
|
1327
1375
|
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
}
|
|
1376
|
+
return (
|
|
1377
|
+
Object.keys(indentStringCounts).sort((a, b) => {
|
|
1378
|
+
return indentStringCounts[a] - indentStringCounts[b];
|
|
1379
|
+
})[0] || '\t'
|
|
1380
|
+
);
|
|
1381
|
+
}
|
|
1334
1382
|
|
|
1335
|
-
|
|
1336
|
-
|
|
1383
|
+
indent(indentStr) {
|
|
1384
|
+
if (!arguments.length) {
|
|
1385
|
+
indentStr = this.getIndentString();
|
|
1386
|
+
}
|
|
1337
1387
|
|
|
1338
|
-
|
|
1339
|
-
indentStr = this.getIndentString();
|
|
1340
|
-
}
|
|
1388
|
+
if (indentStr === '') return this; // noop
|
|
1341
1389
|
|
|
1342
|
-
|
|
1390
|
+
let trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
|
|
1343
1391
|
|
|
1344
|
-
|
|
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));
|
|
1345
1395
|
|
|
1346
|
-
|
|
1347
|
-
|
|
1348
|
-
|
|
1396
|
+
source.content.indent(indentStr, {
|
|
1397
|
+
exclude: source.indentExclusionRanges,
|
|
1398
|
+
indentStart, //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
|
|
1399
|
+
});
|
|
1349
1400
|
|
|
1350
|
-
|
|
1351
|
-
exclude: source.indentExclusionRanges,
|
|
1352
|
-
indentStart: indentStart //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
|
|
1401
|
+
trailingNewline = source.content.lastChar() === '\n';
|
|
1353
1402
|
});
|
|
1354
1403
|
|
|
1355
|
-
|
|
1356
|
-
|
|
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
|
+
}
|
|
1357
1411
|
|
|
1358
|
-
|
|
1359
|
-
this.intro =
|
|
1360
|
-
indentStr +
|
|
1361
|
-
this.intro.replace(/^[^\n]/gm, function (match, index) {
|
|
1362
|
-
return index > 0 ? indentStr + match : match;
|
|
1363
|
-
});
|
|
1412
|
+
return this;
|
|
1364
1413
|
}
|
|
1365
1414
|
|
|
1366
|
-
|
|
1367
|
-
|
|
1415
|
+
prepend(str) {
|
|
1416
|
+
this.intro = str + this.intro;
|
|
1417
|
+
return this;
|
|
1418
|
+
}
|
|
1368
1419
|
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
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();
|
|
1373
1425
|
|
|
1374
|
-
|
|
1375
|
-
|
|
1426
|
+
return str;
|
|
1427
|
+
})
|
|
1428
|
+
.join('');
|
|
1376
1429
|
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
var separator = source.separator !== undefined ? source.separator : this$1$1.separator;
|
|
1380
|
-
var str = (i > 0 ? separator : '') + source.content.toString();
|
|
1430
|
+
return this.intro + body;
|
|
1431
|
+
}
|
|
1381
1432
|
|
|
1382
|
-
|
|
1383
|
-
|
|
1384
|
-
.
|
|
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
|
+
}
|
|
1385
1438
|
|
|
1386
|
-
|
|
1387
|
-
|
|
1439
|
+
length() {
|
|
1440
|
+
return this.sources.reduce(
|
|
1441
|
+
(length, source) => length + source.content.length(),
|
|
1442
|
+
this.intro.length
|
|
1443
|
+
);
|
|
1444
|
+
}
|
|
1388
1445
|
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
|
|
1392
|
-
if (this.sources.some(function (source) { return !source.content.isEmpty(); }))
|
|
1393
|
-
{ return false; }
|
|
1394
|
-
return true;
|
|
1395
|
-
};
|
|
1446
|
+
trimLines() {
|
|
1447
|
+
return this.trim('[\\r\\n]');
|
|
1448
|
+
}
|
|
1396
1449
|
|
|
1397
|
-
|
|
1398
|
-
|
|
1399
|
-
}
|
|
1450
|
+
trim(charType) {
|
|
1451
|
+
return this.trimStart(charType).trimEnd(charType);
|
|
1452
|
+
}
|
|
1400
1453
|
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
|
|
1454
|
+
trimStart(charType) {
|
|
1455
|
+
const rx = new RegExp('^' + (charType || '\\s') + '+');
|
|
1456
|
+
this.intro = this.intro.replace(rx, '');
|
|
1404
1457
|
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1458
|
+
if (!this.intro) {
|
|
1459
|
+
let source;
|
|
1460
|
+
let i = 0;
|
|
1408
1461
|
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1462
|
+
do {
|
|
1463
|
+
source = this.sources[i++];
|
|
1464
|
+
if (!source) {
|
|
1465
|
+
break;
|
|
1466
|
+
}
|
|
1467
|
+
} while (!source.content.trimStartAborted(charType));
|
|
1468
|
+
}
|
|
1412
1469
|
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1470
|
+
return this;
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
trimEnd(charType) {
|
|
1474
|
+
const rx = new RegExp((charType || '\\s') + '+$');
|
|
1475
|
+
|
|
1476
|
+
let source;
|
|
1477
|
+
let i = this.sources.length - 1;
|
|
1416
1478
|
|
|
1417
1479
|
do {
|
|
1418
|
-
source = this.sources[i
|
|
1480
|
+
source = this.sources[i--];
|
|
1419
1481
|
if (!source) {
|
|
1482
|
+
this.intro = this.intro.replace(rx, '');
|
|
1420
1483
|
break;
|
|
1421
1484
|
}
|
|
1422
|
-
} while (!source.content.
|
|
1423
|
-
}
|
|
1424
|
-
|
|
1425
|
-
return this;
|
|
1426
|
-
};
|
|
1427
|
-
|
|
1428
|
-
Bundle$1.prototype.trimEnd = function trimEnd (charType) {
|
|
1429
|
-
var rx = new RegExp((charType || '\\s') + '+$');
|
|
1485
|
+
} while (!source.content.trimEndAborted(charType));
|
|
1430
1486
|
|
|
1431
|
-
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
do {
|
|
1435
|
-
source = this.sources[i--];
|
|
1436
|
-
if (!source) {
|
|
1437
|
-
this.intro = this.intro.replace(rx, '');
|
|
1438
|
-
break;
|
|
1439
|
-
}
|
|
1440
|
-
} while (!source.content.trimEndAborted(charType));
|
|
1441
|
-
|
|
1442
|
-
return this;
|
|
1443
|
-
};
|
|
1444
|
-
|
|
1445
|
-
const MagicString$1 = MagicString;
|
|
1487
|
+
return this;
|
|
1488
|
+
}
|
|
1489
|
+
}
|
|
1446
1490
|
|
|
1447
1491
|
const ANY_SLASH_REGEX = /[/\\]/;
|
|
1448
1492
|
function relative(from, to) {
|
|
@@ -4429,7 +4473,7 @@ const normalizePath = function normalizePath(filename) {
|
|
|
4429
4473
|
|
|
4430
4474
|
function getMatcherString(id, resolutionBase) {
|
|
4431
4475
|
if (resolutionBase === false || isAbsolute$1(id) || id.startsWith('*')) {
|
|
4432
|
-
return id;
|
|
4476
|
+
return normalizePath(id);
|
|
4433
4477
|
}
|
|
4434
4478
|
// resolve('') is valid and will default to process.cwd()
|
|
4435
4479
|
const basePath = normalizePath(resolve(resolutionBase || ''))
|
|
@@ -4439,7 +4483,7 @@ function getMatcherString(id, resolutionBase) {
|
|
|
4439
4483
|
// 1. the basePath has been normalized to use /
|
|
4440
4484
|
// 2. the incoming glob (id) matcher, also uses /
|
|
4441
4485
|
// otherwise Node will force backslash (\) on windows
|
|
4442
|
-
return posix.join(basePath, id);
|
|
4486
|
+
return posix.join(basePath, normalizePath(id));
|
|
4443
4487
|
}
|
|
4444
4488
|
const createFilter = function createFilter(include, exclude, options) {
|
|
4445
4489
|
const resolutionBase = options && options.resolve;
|
|
@@ -12629,7 +12673,7 @@ class Module {
|
|
|
12629
12673
|
// By default, `id` is the file name. Custom resolvers and loaders
|
|
12630
12674
|
// can change that, but it makes sense to use it for the source file name
|
|
12631
12675
|
const fileName = this.id;
|
|
12632
|
-
this.magicString = new MagicString
|
|
12676
|
+
this.magicString = new MagicString(code, {
|
|
12633
12677
|
filename: (this.excludeFromSourcemap ? null : fileName),
|
|
12634
12678
|
indentExclusionRanges: []
|
|
12635
12679
|
});
|
|
@@ -14665,7 +14709,7 @@ class Chunk {
|
|
|
14665
14709
|
if (namespace.renderFirst())
|
|
14666
14710
|
hoistedSource += n + rendered;
|
|
14667
14711
|
else
|
|
14668
|
-
magicString.addSource(new MagicString
|
|
14712
|
+
magicString.addSource(new MagicString(rendered));
|
|
14669
14713
|
}
|
|
14670
14714
|
}
|
|
14671
14715
|
const { renderedExports, removedExports } = module.getRenderedExports();
|
|
@@ -21895,7 +21939,7 @@ async function transform(source, module, pluginDriver, warn) {
|
|
|
21895
21939
|
getCombinedSourcemap() {
|
|
21896
21940
|
const combinedMap = collapseSourcemap(id, originalCode, originalSourcemap, sourcemapChain, warn);
|
|
21897
21941
|
if (!combinedMap) {
|
|
21898
|
-
const magicString = new MagicString
|
|
21942
|
+
const magicString = new MagicString(originalCode);
|
|
21899
21943
|
return magicString.generateMap({ hires: true, includeContent: true, source: id });
|
|
21900
21944
|
}
|
|
21901
21945
|
if (originalSourcemap !== combinedMap) {
|
|
@@ -22485,41 +22529,6 @@ function getPluginContext(plugin, pluginCache, graph, options, fileEmitter, exis
|
|
|
22485
22529
|
return context;
|
|
22486
22530
|
}
|
|
22487
22531
|
|
|
22488
|
-
const unfulfilledActions = new Set();
|
|
22489
|
-
function addUnresolvedAction(actionTuple) {
|
|
22490
|
-
unfulfilledActions.add(actionTuple);
|
|
22491
|
-
}
|
|
22492
|
-
function resolveAction(actionTuple) {
|
|
22493
|
-
unfulfilledActions.delete(actionTuple);
|
|
22494
|
-
}
|
|
22495
|
-
function formatAction([pluginName, hookName, args]) {
|
|
22496
|
-
const action = `(${pluginName}) ${hookName}`;
|
|
22497
|
-
const s = JSON.stringify;
|
|
22498
|
-
switch (hookName) {
|
|
22499
|
-
case 'resolveId':
|
|
22500
|
-
return `${action} ${s(args[0])} ${s(args[1])}`;
|
|
22501
|
-
case 'load':
|
|
22502
|
-
return `${action} ${s(args[0])}`;
|
|
22503
|
-
case 'transform':
|
|
22504
|
-
return `${action} ${s(args[1])}`;
|
|
22505
|
-
case 'shouldTransformCachedModule':
|
|
22506
|
-
return `${action} ${s(args[0].id)}`;
|
|
22507
|
-
case 'moduleParsed':
|
|
22508
|
-
return `${action} ${s(args[0].id)}`;
|
|
22509
|
-
}
|
|
22510
|
-
return action;
|
|
22511
|
-
}
|
|
22512
|
-
process$1.on('exit', () => {
|
|
22513
|
-
if (unfulfilledActions.size) {
|
|
22514
|
-
let err = '[!] Error: unfinished hook action(s) on exit:\n';
|
|
22515
|
-
for (const action of unfulfilledActions) {
|
|
22516
|
-
err += formatAction(action) + '\n';
|
|
22517
|
-
}
|
|
22518
|
-
console.error('%s', err);
|
|
22519
|
-
process$1.exitCode = 1;
|
|
22520
|
-
}
|
|
22521
|
-
});
|
|
22522
|
-
|
|
22523
22532
|
const inputHookNames = {
|
|
22524
22533
|
buildEnd: 1,
|
|
22525
22534
|
buildStart: 1,
|
|
@@ -22545,6 +22554,7 @@ class PluginDriver {
|
|
|
22545
22554
|
constructor(graph, options, userPlugins, pluginCache, basePluginDriver) {
|
|
22546
22555
|
this.graph = graph;
|
|
22547
22556
|
this.options = options;
|
|
22557
|
+
this.unfulfilledActions = new Set();
|
|
22548
22558
|
warnDeprecatedHooks(userPlugins, options);
|
|
22549
22559
|
this.pluginCache = pluginCache;
|
|
22550
22560
|
this.fileEmitter = new FileEmitter(graph, options, basePluginDriver && basePluginDriver.fileEmitter);
|
|
@@ -22571,6 +22581,9 @@ class PluginDriver {
|
|
|
22571
22581
|
createOutputPluginDriver(plugins) {
|
|
22572
22582
|
return new PluginDriver(this.graph, this.options, plugins, this.pluginCache, this);
|
|
22573
22583
|
}
|
|
22584
|
+
getUnfulfilledHookActions() {
|
|
22585
|
+
return this.unfulfilledActions;
|
|
22586
|
+
}
|
|
22574
22587
|
// chains, first non-null result stops and returns
|
|
22575
22588
|
hookFirst(hookName, args, replaceContext, skipped) {
|
|
22576
22589
|
let promise = Promise.resolve(undefined);
|
|
@@ -22658,12 +22671,6 @@ class PluginDriver {
|
|
|
22658
22671
|
}
|
|
22659
22672
|
return promise;
|
|
22660
22673
|
}
|
|
22661
|
-
// chains synchronously, ignores returns
|
|
22662
|
-
hookSeqSync(hookName, args, replaceContext) {
|
|
22663
|
-
for (const plugin of this.plugins) {
|
|
22664
|
-
this.runHookSync(hookName, args, plugin, replaceContext);
|
|
22665
|
-
}
|
|
22666
|
-
}
|
|
22667
22674
|
runHook(hookName, args, plugin, permitValues, hookContext) {
|
|
22668
22675
|
const hook = plugin[hookName];
|
|
22669
22676
|
if (!hook)
|
|
@@ -22692,22 +22699,21 @@ class PluginDriver {
|
|
|
22692
22699
|
// exit with a successful 0 return code but without producing any
|
|
22693
22700
|
// output, errors or warnings.
|
|
22694
22701
|
action = [plugin.name, hookName, args];
|
|
22695
|
-
|
|
22702
|
+
this.unfulfilledActions.add(action);
|
|
22696
22703
|
// Although it would be more elegant to just return hookResult here
|
|
22697
22704
|
// and put the .then() handler just above the .catch() handler below,
|
|
22698
22705
|
// doing so would subtly change the defacto async event dispatch order
|
|
22699
22706
|
// which at least one test and some plugins in the wild may depend on.
|
|
22700
|
-
|
|
22701
|
-
return promise.then(() => {
|
|
22707
|
+
return Promise.resolve(hookResult).then(result => {
|
|
22702
22708
|
// action was fulfilled
|
|
22703
|
-
|
|
22704
|
-
return
|
|
22709
|
+
this.unfulfilledActions.delete(action);
|
|
22710
|
+
return result;
|
|
22705
22711
|
});
|
|
22706
22712
|
})
|
|
22707
22713
|
.catch(err => {
|
|
22708
22714
|
if (action !== null) {
|
|
22709
22715
|
// action considered to be fulfilled since error being handled
|
|
22710
|
-
|
|
22716
|
+
this.unfulfilledActions.delete(action);
|
|
22711
22717
|
}
|
|
22712
22718
|
return throwPluginError(err, plugin.name, { hook: hookName });
|
|
22713
22719
|
});
|
|
@@ -22796,14 +22802,10 @@ class Graph {
|
|
|
22796
22802
|
}
|
|
22797
22803
|
if (watcher) {
|
|
22798
22804
|
this.watchMode = true;
|
|
22799
|
-
const handleChange = (...args) => this.pluginDriver.
|
|
22800
|
-
const handleClose = () => this.pluginDriver.
|
|
22801
|
-
watcher.
|
|
22802
|
-
watcher.
|
|
22803
|
-
watcher.once('restart', () => {
|
|
22804
|
-
watcher.removeListener('change', handleChange);
|
|
22805
|
-
watcher.removeListener('close', handleClose);
|
|
22806
|
-
});
|
|
22805
|
+
const handleChange = (...args) => this.pluginDriver.hookParallel('watchChange', args);
|
|
22806
|
+
const handleClose = () => this.pluginDriver.hookParallel('closeWatcher', []);
|
|
22807
|
+
watcher.onCurrentAwaited('change', handleChange);
|
|
22808
|
+
watcher.onCurrentAwaited('close', handleClose);
|
|
22807
22809
|
}
|
|
22808
22810
|
this.pluginDriver = new PluginDriver(this, options, options.plugins, this.pluginCache);
|
|
22809
22811
|
this.acornParser = Parser.extend(...options.acornInjectPlugins);
|
|
@@ -22968,6 +22970,38 @@ function ensureArray(items) {
|
|
|
22968
22970
|
return [];
|
|
22969
22971
|
}
|
|
22970
22972
|
|
|
22973
|
+
function formatAction([pluginName, hookName, args]) {
|
|
22974
|
+
const action = `(${pluginName}) ${hookName}`;
|
|
22975
|
+
const s = JSON.stringify;
|
|
22976
|
+
switch (hookName) {
|
|
22977
|
+
case 'resolveId':
|
|
22978
|
+
return `${action} ${s(args[0])} ${s(args[1])}`;
|
|
22979
|
+
case 'load':
|
|
22980
|
+
return `${action} ${s(args[0])}`;
|
|
22981
|
+
case 'transform':
|
|
22982
|
+
return `${action} ${s(args[1])}`;
|
|
22983
|
+
case 'shouldTransformCachedModule':
|
|
22984
|
+
return `${action} ${s(args[0].id)}`;
|
|
22985
|
+
case 'moduleParsed':
|
|
22986
|
+
return `${action} ${s(args[0].id)}`;
|
|
22987
|
+
}
|
|
22988
|
+
return action;
|
|
22989
|
+
}
|
|
22990
|
+
async function catchUnfinishedHookActions(pluginDriver, callback) {
|
|
22991
|
+
let handleEmptyEventLoop;
|
|
22992
|
+
const emptyEventLoopPromise = new Promise((_, reject) => {
|
|
22993
|
+
handleEmptyEventLoop = () => {
|
|
22994
|
+
const unfulfilledActions = pluginDriver.getUnfulfilledHookActions();
|
|
22995
|
+
reject(new Error(`Unexpected early exit. This happens when Promises returned by plugins cannot resolve. Unfinished hook action(s) on exit:\n` +
|
|
22996
|
+
[...unfulfilledActions].map(formatAction).join('\n')));
|
|
22997
|
+
};
|
|
22998
|
+
process$1.once('beforeExit', handleEmptyEventLoop);
|
|
22999
|
+
});
|
|
23000
|
+
const result = await Promise.race([callback(), emptyEventLoopPromise]);
|
|
23001
|
+
process$1.off('beforeExit', handleEmptyEventLoop);
|
|
23002
|
+
return result;
|
|
23003
|
+
}
|
|
23004
|
+
|
|
22971
23005
|
const defaultOnWarn = warning => console.warn(warning.message || warning);
|
|
22972
23006
|
function warnUnknownOptions(passedOptions, validOptions, optionType, warn, ignoredKeys = /$./) {
|
|
22973
23007
|
const validOptionSet = new Set(validOptions);
|
|
@@ -23037,8 +23071,7 @@ const objectifyOptionWithPresets = (presets, optionName, additionalValues) => (v
|
|
|
23037
23071
|
return objectifyOption(value);
|
|
23038
23072
|
};
|
|
23039
23073
|
const getOptionWithPreset = (value, presets, optionName, additionalValues) => {
|
|
23040
|
-
|
|
23041
|
-
const presetName = (_a = value) === null || _a === void 0 ? void 0 : _a.preset;
|
|
23074
|
+
const presetName = value === null || value === void 0 ? void 0 : value.preset;
|
|
23042
23075
|
if (presetName) {
|
|
23043
23076
|
const preset = presets[presetName];
|
|
23044
23077
|
if (preset) {
|
|
@@ -23535,20 +23568,22 @@ async function rollupInternal(rawInputOptions, watcher) {
|
|
|
23535
23568
|
delete inputOptions.cache;
|
|
23536
23569
|
delete rawInputOptions.cache;
|
|
23537
23570
|
timeStart('BUILD', 1);
|
|
23538
|
-
|
|
23539
|
-
|
|
23540
|
-
|
|
23541
|
-
|
|
23542
|
-
catch (err) {
|
|
23543
|
-
const watchFiles = Object.keys(graph.watchFiles);
|
|
23544
|
-
if (watchFiles.length > 0) {
|
|
23545
|
-
err.watchFiles = watchFiles;
|
|
23571
|
+
await catchUnfinishedHookActions(graph.pluginDriver, async () => {
|
|
23572
|
+
try {
|
|
23573
|
+
await graph.pluginDriver.hookParallel('buildStart', [inputOptions]);
|
|
23574
|
+
await graph.build();
|
|
23546
23575
|
}
|
|
23547
|
-
|
|
23548
|
-
|
|
23549
|
-
|
|
23550
|
-
|
|
23551
|
-
|
|
23576
|
+
catch (err) {
|
|
23577
|
+
const watchFiles = Object.keys(graph.watchFiles);
|
|
23578
|
+
if (watchFiles.length > 0) {
|
|
23579
|
+
err.watchFiles = watchFiles;
|
|
23580
|
+
}
|
|
23581
|
+
await graph.pluginDriver.hookParallel('buildEnd', [err]);
|
|
23582
|
+
await graph.pluginDriver.hookParallel('closeBundle', []);
|
|
23583
|
+
throw err;
|
|
23584
|
+
}
|
|
23585
|
+
await graph.pluginDriver.hookParallel('buildEnd', []);
|
|
23586
|
+
});
|
|
23552
23587
|
timeEnd('BUILD', 1);
|
|
23553
23588
|
const result = {
|
|
23554
23589
|
cache: useCache ? graph.getCache() : undefined,
|
|
@@ -23599,21 +23634,23 @@ function normalizePlugins(plugins, anonymousPrefix) {
|
|
|
23599
23634
|
}
|
|
23600
23635
|
});
|
|
23601
23636
|
}
|
|
23602
|
-
|
|
23637
|
+
function handleGenerateWrite(isWrite, inputOptions, unsetInputOptions, rawOutputOptions, graph) {
|
|
23603
23638
|
const { options: outputOptions, outputPluginDriver, unsetOptions } = getOutputOptionsAndPluginDriver(rawOutputOptions, graph.pluginDriver, inputOptions, unsetInputOptions);
|
|
23604
|
-
|
|
23605
|
-
|
|
23606
|
-
|
|
23607
|
-
if (
|
|
23608
|
-
|
|
23609
|
-
|
|
23610
|
-
|
|
23611
|
-
|
|
23639
|
+
return catchUnfinishedHookActions(outputPluginDriver, async () => {
|
|
23640
|
+
const bundle = new Bundle(outputOptions, unsetOptions, inputOptions, outputPluginDriver, graph);
|
|
23641
|
+
const generated = await bundle.generate(isWrite);
|
|
23642
|
+
if (isWrite) {
|
|
23643
|
+
if (!outputOptions.dir && !outputOptions.file) {
|
|
23644
|
+
return error({
|
|
23645
|
+
code: 'MISSING_OPTION',
|
|
23646
|
+
message: 'You must specify "output.file" or "output.dir" for the build.'
|
|
23647
|
+
});
|
|
23648
|
+
}
|
|
23649
|
+
await Promise.all(Object.values(generated).map(chunk => writeOutputFile(chunk, outputOptions)));
|
|
23650
|
+
await outputPluginDriver.hookParallel('writeBundle', [outputOptions, generated]);
|
|
23612
23651
|
}
|
|
23613
|
-
|
|
23614
|
-
|
|
23615
|
-
}
|
|
23616
|
-
return createOutput(generated);
|
|
23652
|
+
return createOutput(generated);
|
|
23653
|
+
});
|
|
23617
23654
|
}
|
|
23618
23655
|
function getOutputOptionsAndPluginDriver(rawOutputOptions, inputPluginDriver, inputOptions, unsetInputOptions) {
|
|
23619
23656
|
if (!rawOutputOptions) {
|
|
@@ -23699,6 +23736,33 @@ function defineConfig(options) {
|
|
|
23699
23736
|
return options;
|
|
23700
23737
|
}
|
|
23701
23738
|
|
|
23739
|
+
class WatchEmitter extends EventEmitter {
|
|
23740
|
+
constructor() {
|
|
23741
|
+
super();
|
|
23742
|
+
this.awaitedHandlers = Object.create(null);
|
|
23743
|
+
// Allows more than 10 bundles to be watched without
|
|
23744
|
+
// showing the `MaxListenersExceededWarning` to the user.
|
|
23745
|
+
this.setMaxListeners(Infinity);
|
|
23746
|
+
}
|
|
23747
|
+
// Will be overwritten by Rollup
|
|
23748
|
+
async close() { }
|
|
23749
|
+
emitAndAwait(event, ...args) {
|
|
23750
|
+
this.emit(event, ...args);
|
|
23751
|
+
return Promise.all(this.getHandlers(event).map(handler => handler(...args)));
|
|
23752
|
+
}
|
|
23753
|
+
onCurrentAwaited(event, listener) {
|
|
23754
|
+
this.getHandlers(event).push(listener);
|
|
23755
|
+
return this;
|
|
23756
|
+
}
|
|
23757
|
+
removeAwaited() {
|
|
23758
|
+
this.awaitedHandlers = {};
|
|
23759
|
+
return this;
|
|
23760
|
+
}
|
|
23761
|
+
getHandlers(event) {
|
|
23762
|
+
return this.awaitedHandlers[event] || (this.awaitedHandlers[event] = []);
|
|
23763
|
+
}
|
|
23764
|
+
}
|
|
23765
|
+
|
|
23702
23766
|
let fsEvents;
|
|
23703
23767
|
let fsEventsImportError;
|
|
23704
23768
|
async function loadFsEvents() {
|
|
@@ -23722,15 +23786,6 @@ const fseventsImporter = /*#__PURE__*/Object.defineProperty({
|
|
|
23722
23786
|
getFsEvents
|
|
23723
23787
|
}, Symbol.toStringTag, { value: 'Module' });
|
|
23724
23788
|
|
|
23725
|
-
class WatchEmitter extends EventEmitter {
|
|
23726
|
-
constructor() {
|
|
23727
|
-
super();
|
|
23728
|
-
// Allows more than 10 bundles to be watched without
|
|
23729
|
-
// showing the `MaxListenersExceededWarning` to the user.
|
|
23730
|
-
this.setMaxListeners(Infinity);
|
|
23731
|
-
}
|
|
23732
|
-
close() { }
|
|
23733
|
-
}
|
|
23734
23789
|
function watch(configs) {
|
|
23735
23790
|
const emitter = new WatchEmitter();
|
|
23736
23791
|
const configArray = ensureArray(configs);
|