vitest 0.29.7 → 0.30.0
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/LICENSE.md +3 -266
- package/dist/browser.d.ts +16 -4
- package/dist/browser.js +5 -4
- package/dist/child.js +12 -17
- package/dist/{chunk-api-setup.ac7748ac.js → chunk-api-setup.6662587e.js} +65 -51
- package/dist/{chunk-install-pkg.863031f2.js → chunk-install-pkg.6450b372.js} +33 -32
- package/dist/chunk-integrations-globals.d419838f.js +26 -0
- package/dist/{chunk-node-git.ed5bded8.js → chunk-node-git.4c43bd73.js} +4 -2
- package/dist/cli-wrapper.js +6 -5
- package/dist/cli.js +27 -26
- package/dist/config.cjs +15 -7
- package/dist/config.d.ts +15 -8
- package/dist/config.js +10 -6
- package/dist/coverage.d.ts +5 -2
- package/dist/coverage.js +6 -0
- package/dist/entry.js +35 -34
- package/dist/environments.d.ts +5 -2
- package/dist/environments.js +1 -1
- package/dist/index.d.ts +17 -21
- package/dist/index.js +9 -10
- package/dist/loader.js +396 -12
- package/dist/node.d.ts +9 -7
- package/dist/node.js +28 -30
- package/dist/runners.d.ts +5 -2
- package/dist/runners.js +34 -30
- package/dist/{types-fafda418.d.ts → types-f03c83c4.d.ts} +243 -317
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +1 -0
- package/dist/{chunk-node-pkg.f9696901.js → vendor-cli-api.c04eaa34.js} +3858 -5514
- package/dist/vendor-constants.538d9b49.js +54 -0
- package/dist/{chunk-integrations-coverage.e0a6acd2.js → vendor-coverage.a585b712.js} +5 -5
- package/dist/{chunk-runtime-mocker.344fec90.js → vendor-execute.8eaab47b.js} +9 -12
- package/dist/vendor-global.6795f91f.js +8 -0
- package/dist/vendor-index.4f82d248.js +161 -0
- package/dist/{chunk-env-node.affdd278.js → vendor-index.75f2b63d.js} +9 -2
- package/dist/{chunk-integrations-utils.d7c85bd9.js → vendor-index.81b9e499.js} +22 -21
- package/dist/{vendor-index.2cbcdd1e.js → vendor-index.c1e09929.js} +458 -373
- package/dist/vendor-index.fad2598b.js +44 -0
- package/dist/{vendor-index.534e612c.js → vendor-index.fc98d30f.js} +2 -2
- package/dist/{chunk-runtime-inspector.b1427a10.js → vendor-inspector.47fc8cbb.js} +5 -2
- package/dist/{chunk-runtime-rpc.1b5714dc.js → vendor-rpc.4d3d7a54.js} +5 -5
- package/dist/{chunk-integrations-run-once.a2b4758b.js → vendor-run-once.69ce7172.js} +3 -2
- package/dist/{chunk-runtime-setup.a49dc2f9.js → vendor-setup.common.cef38f4e.js} +2 -2
- package/dist/vendor-tasks.042d6084.js +14 -0
- package/dist/{chunk-utils-import.39ffe9c5.js → vendor-vi.a3ff54b1.js} +262 -3147
- package/dist/worker.js +13 -19
- package/package.json +40 -34
- package/utils.d.ts +1 -0
- package/dist/chunk-constants.bc18a549.js +0 -36
- package/dist/chunk-integrations-globals.a473e88a.js +0 -27
- package/dist/chunk-snapshot-env.a347d647.js +0 -11
- package/dist/chunk-utils-base.81f83dbd.js +0 -88
- package/dist/chunk-utils-env.04ffbef7.js +0 -70
- package/dist/chunk-utils-tasks.b41c8284.js +0 -107
- package/dist/env-afee91f0.d.ts +0 -10
- package/dist/vendor-index.783e7f3e.js +0 -71
- package/dist/vendor-index.bdee400f.js +0 -396
- package/dist/vendor-magic-string.es.b3bc5745.js +0 -1591
- /package/dist/{vendor-_commonjsHelpers.addc3445.js → vendor-_commonjsHelpers.76cdd49e.js} +0 -0
- /package/dist/{chunk-paths.e36446b4.js → vendor-paths.84fc7a99.js} +0 -0
|
@@ -1,1591 +0,0 @@
|
|
|
1
|
-
const comma = ','.charCodeAt(0);
|
|
2
|
-
const semicolon = ';'.charCodeAt(0);
|
|
3
|
-
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
4
|
-
const intToChar = new Uint8Array(64); // 64 possible chars.
|
|
5
|
-
const charToInt = new Uint8Array(128); // z is 122 in ASCII
|
|
6
|
-
for (let i = 0; i < chars.length; i++) {
|
|
7
|
-
const c = chars.charCodeAt(i);
|
|
8
|
-
intToChar[i] = c;
|
|
9
|
-
charToInt[c] = i;
|
|
10
|
-
}
|
|
11
|
-
// Provide a fallback for older environments.
|
|
12
|
-
const td = typeof TextDecoder !== 'undefined'
|
|
13
|
-
? /* #__PURE__ */ new TextDecoder()
|
|
14
|
-
: typeof Buffer !== 'undefined'
|
|
15
|
-
? {
|
|
16
|
-
decode(buf) {
|
|
17
|
-
const out = Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
18
|
-
return out.toString();
|
|
19
|
-
},
|
|
20
|
-
}
|
|
21
|
-
: {
|
|
22
|
-
decode(buf) {
|
|
23
|
-
let out = '';
|
|
24
|
-
for (let i = 0; i < buf.length; i++) {
|
|
25
|
-
out += String.fromCharCode(buf[i]);
|
|
26
|
-
}
|
|
27
|
-
return out;
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
function decode(mappings) {
|
|
31
|
-
const state = new Int32Array(5);
|
|
32
|
-
const decoded = [];
|
|
33
|
-
let index = 0;
|
|
34
|
-
do {
|
|
35
|
-
const semi = indexOf(mappings, index);
|
|
36
|
-
const line = [];
|
|
37
|
-
let sorted = true;
|
|
38
|
-
let lastCol = 0;
|
|
39
|
-
state[0] = 0;
|
|
40
|
-
for (let i = index; i < semi; i++) {
|
|
41
|
-
let seg;
|
|
42
|
-
i = decodeInteger(mappings, i, state, 0); // genColumn
|
|
43
|
-
const col = state[0];
|
|
44
|
-
if (col < lastCol)
|
|
45
|
-
sorted = false;
|
|
46
|
-
lastCol = col;
|
|
47
|
-
if (hasMoreVlq(mappings, i, semi)) {
|
|
48
|
-
i = decodeInteger(mappings, i, state, 1); // sourcesIndex
|
|
49
|
-
i = decodeInteger(mappings, i, state, 2); // sourceLine
|
|
50
|
-
i = decodeInteger(mappings, i, state, 3); // sourceColumn
|
|
51
|
-
if (hasMoreVlq(mappings, i, semi)) {
|
|
52
|
-
i = decodeInteger(mappings, i, state, 4); // namesIndex
|
|
53
|
-
seg = [col, state[1], state[2], state[3], state[4]];
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
seg = [col, state[1], state[2], state[3]];
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
else {
|
|
60
|
-
seg = [col];
|
|
61
|
-
}
|
|
62
|
-
line.push(seg);
|
|
63
|
-
}
|
|
64
|
-
if (!sorted)
|
|
65
|
-
sort(line);
|
|
66
|
-
decoded.push(line);
|
|
67
|
-
index = semi + 1;
|
|
68
|
-
} while (index <= mappings.length);
|
|
69
|
-
return decoded;
|
|
70
|
-
}
|
|
71
|
-
function indexOf(mappings, index) {
|
|
72
|
-
const idx = mappings.indexOf(';', index);
|
|
73
|
-
return idx === -1 ? mappings.length : idx;
|
|
74
|
-
}
|
|
75
|
-
function decodeInteger(mappings, pos, state, j) {
|
|
76
|
-
let value = 0;
|
|
77
|
-
let shift = 0;
|
|
78
|
-
let integer = 0;
|
|
79
|
-
do {
|
|
80
|
-
const c = mappings.charCodeAt(pos++);
|
|
81
|
-
integer = charToInt[c];
|
|
82
|
-
value |= (integer & 31) << shift;
|
|
83
|
-
shift += 5;
|
|
84
|
-
} while (integer & 32);
|
|
85
|
-
const shouldNegate = value & 1;
|
|
86
|
-
value >>>= 1;
|
|
87
|
-
if (shouldNegate) {
|
|
88
|
-
value = -0x80000000 | -value;
|
|
89
|
-
}
|
|
90
|
-
state[j] += value;
|
|
91
|
-
return pos;
|
|
92
|
-
}
|
|
93
|
-
function hasMoreVlq(mappings, i, length) {
|
|
94
|
-
if (i >= length)
|
|
95
|
-
return false;
|
|
96
|
-
return mappings.charCodeAt(i) !== comma;
|
|
97
|
-
}
|
|
98
|
-
function sort(line) {
|
|
99
|
-
line.sort(sortComparator);
|
|
100
|
-
}
|
|
101
|
-
function sortComparator(a, b) {
|
|
102
|
-
return a[0] - b[0];
|
|
103
|
-
}
|
|
104
|
-
function encode(decoded) {
|
|
105
|
-
const state = new Int32Array(5);
|
|
106
|
-
const bufLength = 1024 * 16;
|
|
107
|
-
const subLength = bufLength - 36;
|
|
108
|
-
const buf = new Uint8Array(bufLength);
|
|
109
|
-
const sub = buf.subarray(0, subLength);
|
|
110
|
-
let pos = 0;
|
|
111
|
-
let out = '';
|
|
112
|
-
for (let i = 0; i < decoded.length; i++) {
|
|
113
|
-
const line = decoded[i];
|
|
114
|
-
if (i > 0) {
|
|
115
|
-
if (pos === bufLength) {
|
|
116
|
-
out += td.decode(buf);
|
|
117
|
-
pos = 0;
|
|
118
|
-
}
|
|
119
|
-
buf[pos++] = semicolon;
|
|
120
|
-
}
|
|
121
|
-
if (line.length === 0)
|
|
122
|
-
continue;
|
|
123
|
-
state[0] = 0;
|
|
124
|
-
for (let j = 0; j < line.length; j++) {
|
|
125
|
-
const segment = line[j];
|
|
126
|
-
// We can push up to 5 ints, each int can take at most 7 chars, and we
|
|
127
|
-
// may push a comma.
|
|
128
|
-
if (pos > subLength) {
|
|
129
|
-
out += td.decode(sub);
|
|
130
|
-
buf.copyWithin(0, subLength, pos);
|
|
131
|
-
pos -= subLength;
|
|
132
|
-
}
|
|
133
|
-
if (j > 0)
|
|
134
|
-
buf[pos++] = comma;
|
|
135
|
-
pos = encodeInteger(buf, pos, state, segment, 0); // genColumn
|
|
136
|
-
if (segment.length === 1)
|
|
137
|
-
continue;
|
|
138
|
-
pos = encodeInteger(buf, pos, state, segment, 1); // sourcesIndex
|
|
139
|
-
pos = encodeInteger(buf, pos, state, segment, 2); // sourceLine
|
|
140
|
-
pos = encodeInteger(buf, pos, state, segment, 3); // sourceColumn
|
|
141
|
-
if (segment.length === 4)
|
|
142
|
-
continue;
|
|
143
|
-
pos = encodeInteger(buf, pos, state, segment, 4); // namesIndex
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return out + td.decode(buf.subarray(0, pos));
|
|
147
|
-
}
|
|
148
|
-
function encodeInteger(buf, pos, state, segment, j) {
|
|
149
|
-
const next = segment[j];
|
|
150
|
-
let num = next - state[j];
|
|
151
|
-
state[j] = next;
|
|
152
|
-
num = num < 0 ? (-num << 1) | 1 : num << 1;
|
|
153
|
-
do {
|
|
154
|
-
let clamped = num & 0b011111;
|
|
155
|
-
num >>>= 5;
|
|
156
|
-
if (num > 0)
|
|
157
|
-
clamped |= 0b100000;
|
|
158
|
-
buf[pos++] = intToChar[clamped];
|
|
159
|
-
} while (num > 0);
|
|
160
|
-
return pos;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
class BitSet {
|
|
164
|
-
constructor(arg) {
|
|
165
|
-
this.bits = arg instanceof BitSet ? arg.bits.slice() : [];
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
add(n) {
|
|
169
|
-
this.bits[n >> 5] |= 1 << (n & 31);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
has(n) {
|
|
173
|
-
return !!(this.bits[n >> 5] & (1 << (n & 31)));
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
class Chunk {
|
|
178
|
-
constructor(start, end, content) {
|
|
179
|
-
this.start = start;
|
|
180
|
-
this.end = end;
|
|
181
|
-
this.original = content;
|
|
182
|
-
|
|
183
|
-
this.intro = '';
|
|
184
|
-
this.outro = '';
|
|
185
|
-
|
|
186
|
-
this.content = content;
|
|
187
|
-
this.storeName = false;
|
|
188
|
-
this.edited = false;
|
|
189
|
-
|
|
190
|
-
{
|
|
191
|
-
this.previous = null;
|
|
192
|
-
this.next = null;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
appendLeft(content) {
|
|
197
|
-
this.outro += content;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
appendRight(content) {
|
|
201
|
-
this.intro = this.intro + content;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
clone() {
|
|
205
|
-
const chunk = new Chunk(this.start, this.end, this.original);
|
|
206
|
-
|
|
207
|
-
chunk.intro = this.intro;
|
|
208
|
-
chunk.outro = this.outro;
|
|
209
|
-
chunk.content = this.content;
|
|
210
|
-
chunk.storeName = this.storeName;
|
|
211
|
-
chunk.edited = this.edited;
|
|
212
|
-
|
|
213
|
-
return chunk;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
contains(index) {
|
|
217
|
-
return this.start < index && index < this.end;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
eachNext(fn) {
|
|
221
|
-
let chunk = this;
|
|
222
|
-
while (chunk) {
|
|
223
|
-
fn(chunk);
|
|
224
|
-
chunk = chunk.next;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
eachPrevious(fn) {
|
|
229
|
-
let chunk = this;
|
|
230
|
-
while (chunk) {
|
|
231
|
-
fn(chunk);
|
|
232
|
-
chunk = chunk.previous;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
edit(content, storeName, contentOnly) {
|
|
237
|
-
this.content = content;
|
|
238
|
-
if (!contentOnly) {
|
|
239
|
-
this.intro = '';
|
|
240
|
-
this.outro = '';
|
|
241
|
-
}
|
|
242
|
-
this.storeName = storeName;
|
|
243
|
-
|
|
244
|
-
this.edited = true;
|
|
245
|
-
|
|
246
|
-
return this;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
prependLeft(content) {
|
|
250
|
-
this.outro = content + this.outro;
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
prependRight(content) {
|
|
254
|
-
this.intro = content + this.intro;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
split(index) {
|
|
258
|
-
const sliceIndex = index - this.start;
|
|
259
|
-
|
|
260
|
-
const originalBefore = this.original.slice(0, sliceIndex);
|
|
261
|
-
const originalAfter = this.original.slice(sliceIndex);
|
|
262
|
-
|
|
263
|
-
this.original = originalBefore;
|
|
264
|
-
|
|
265
|
-
const newChunk = new Chunk(index, this.end, originalAfter);
|
|
266
|
-
newChunk.outro = this.outro;
|
|
267
|
-
this.outro = '';
|
|
268
|
-
|
|
269
|
-
this.end = index;
|
|
270
|
-
|
|
271
|
-
if (this.edited) {
|
|
272
|
-
// TODO is this block necessary?...
|
|
273
|
-
newChunk.edit('', false);
|
|
274
|
-
this.content = '';
|
|
275
|
-
} else {
|
|
276
|
-
this.content = originalBefore;
|
|
277
|
-
}
|
|
278
|
-
|
|
279
|
-
newChunk.next = this.next;
|
|
280
|
-
if (newChunk.next) newChunk.next.previous = newChunk;
|
|
281
|
-
newChunk.previous = this;
|
|
282
|
-
this.next = newChunk;
|
|
283
|
-
|
|
284
|
-
return newChunk;
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
toString() {
|
|
288
|
-
return this.intro + this.content + this.outro;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
trimEnd(rx) {
|
|
292
|
-
this.outro = this.outro.replace(rx, '');
|
|
293
|
-
if (this.outro.length) return true;
|
|
294
|
-
|
|
295
|
-
const trimmed = this.content.replace(rx, '');
|
|
296
|
-
|
|
297
|
-
if (trimmed.length) {
|
|
298
|
-
if (trimmed !== this.content) {
|
|
299
|
-
this.split(this.start + trimmed.length).edit('', undefined, true);
|
|
300
|
-
}
|
|
301
|
-
return true;
|
|
302
|
-
} else {
|
|
303
|
-
this.edit('', undefined, true);
|
|
304
|
-
|
|
305
|
-
this.intro = this.intro.replace(rx, '');
|
|
306
|
-
if (this.intro.length) return true;
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
trimStart(rx) {
|
|
311
|
-
this.intro = this.intro.replace(rx, '');
|
|
312
|
-
if (this.intro.length) return true;
|
|
313
|
-
|
|
314
|
-
const trimmed = this.content.replace(rx, '');
|
|
315
|
-
|
|
316
|
-
if (trimmed.length) {
|
|
317
|
-
if (trimmed !== this.content) {
|
|
318
|
-
this.split(this.end - trimmed.length);
|
|
319
|
-
this.edit('', undefined, true);
|
|
320
|
-
}
|
|
321
|
-
return true;
|
|
322
|
-
} else {
|
|
323
|
-
this.edit('', undefined, true);
|
|
324
|
-
|
|
325
|
-
this.outro = this.outro.replace(rx, '');
|
|
326
|
-
if (this.outro.length) return true;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
function getBtoa () {
|
|
332
|
-
if (typeof window !== 'undefined' && typeof window.btoa === 'function') {
|
|
333
|
-
return (str) => window.btoa(unescape(encodeURIComponent(str)));
|
|
334
|
-
} else if (typeof Buffer === 'function') {
|
|
335
|
-
return (str) => Buffer.from(str, 'utf-8').toString('base64');
|
|
336
|
-
} else {
|
|
337
|
-
return () => {
|
|
338
|
-
throw new Error('Unsupported environment: `window.btoa` or `Buffer` should be supported.');
|
|
339
|
-
};
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
const btoa = /*#__PURE__*/ getBtoa();
|
|
344
|
-
|
|
345
|
-
class SourceMap {
|
|
346
|
-
constructor(properties) {
|
|
347
|
-
this.version = 3;
|
|
348
|
-
this.file = properties.file;
|
|
349
|
-
this.sources = properties.sources;
|
|
350
|
-
this.sourcesContent = properties.sourcesContent;
|
|
351
|
-
this.names = properties.names;
|
|
352
|
-
this.mappings = encode(properties.mappings);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
toString() {
|
|
356
|
-
return JSON.stringify(this);
|
|
357
|
-
}
|
|
358
|
-
|
|
359
|
-
toUrl() {
|
|
360
|
-
return 'data:application/json;charset=utf-8;base64,' + btoa(this.toString());
|
|
361
|
-
}
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
function guessIndent(code) {
|
|
365
|
-
const lines = code.split('\n');
|
|
366
|
-
|
|
367
|
-
const tabbed = lines.filter((line) => /^\t+/.test(line));
|
|
368
|
-
const spaced = lines.filter((line) => /^ {2,}/.test(line));
|
|
369
|
-
|
|
370
|
-
if (tabbed.length === 0 && spaced.length === 0) {
|
|
371
|
-
return null;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// More lines tabbed than spaced? Assume tabs, and
|
|
375
|
-
// default to tabs in the case of a tie (or nothing
|
|
376
|
-
// to go on)
|
|
377
|
-
if (tabbed.length >= spaced.length) {
|
|
378
|
-
return '\t';
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
// Otherwise, we need to guess the multiple
|
|
382
|
-
const min = spaced.reduce((previous, current) => {
|
|
383
|
-
const numSpaces = /^ +/.exec(current)[0].length;
|
|
384
|
-
return Math.min(numSpaces, previous);
|
|
385
|
-
}, Infinity);
|
|
386
|
-
|
|
387
|
-
return new Array(min + 1).join(' ');
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
function getRelativePath(from, to) {
|
|
391
|
-
const fromParts = from.split(/[/\\]/);
|
|
392
|
-
const toParts = to.split(/[/\\]/);
|
|
393
|
-
|
|
394
|
-
fromParts.pop(); // get dirname
|
|
395
|
-
|
|
396
|
-
while (fromParts[0] === toParts[0]) {
|
|
397
|
-
fromParts.shift();
|
|
398
|
-
toParts.shift();
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
if (fromParts.length) {
|
|
402
|
-
let i = fromParts.length;
|
|
403
|
-
while (i--) fromParts[i] = '..';
|
|
404
|
-
}
|
|
405
|
-
|
|
406
|
-
return fromParts.concat(toParts).join('/');
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
const toString = Object.prototype.toString;
|
|
410
|
-
|
|
411
|
-
function isObject(thing) {
|
|
412
|
-
return toString.call(thing) === '[object Object]';
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
function getLocator(source) {
|
|
416
|
-
const originalLines = source.split('\n');
|
|
417
|
-
const lineOffsets = [];
|
|
418
|
-
|
|
419
|
-
for (let i = 0, pos = 0; i < originalLines.length; i++) {
|
|
420
|
-
lineOffsets.push(pos);
|
|
421
|
-
pos += originalLines[i].length + 1;
|
|
422
|
-
}
|
|
423
|
-
|
|
424
|
-
return function locate(index) {
|
|
425
|
-
let i = 0;
|
|
426
|
-
let j = lineOffsets.length;
|
|
427
|
-
while (i < j) {
|
|
428
|
-
const m = (i + j) >> 1;
|
|
429
|
-
if (index < lineOffsets[m]) {
|
|
430
|
-
j = m;
|
|
431
|
-
} else {
|
|
432
|
-
i = m + 1;
|
|
433
|
-
}
|
|
434
|
-
}
|
|
435
|
-
const line = i - 1;
|
|
436
|
-
const column = index - lineOffsets[line];
|
|
437
|
-
return { line, column };
|
|
438
|
-
};
|
|
439
|
-
}
|
|
440
|
-
|
|
441
|
-
class Mappings {
|
|
442
|
-
constructor(hires) {
|
|
443
|
-
this.hires = hires;
|
|
444
|
-
this.generatedCodeLine = 0;
|
|
445
|
-
this.generatedCodeColumn = 0;
|
|
446
|
-
this.raw = [];
|
|
447
|
-
this.rawSegments = this.raw[this.generatedCodeLine] = [];
|
|
448
|
-
this.pending = null;
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
addEdit(sourceIndex, content, loc, nameIndex) {
|
|
452
|
-
if (content.length) {
|
|
453
|
-
const segment = [this.generatedCodeColumn, sourceIndex, loc.line, loc.column];
|
|
454
|
-
if (nameIndex >= 0) {
|
|
455
|
-
segment.push(nameIndex);
|
|
456
|
-
}
|
|
457
|
-
this.rawSegments.push(segment);
|
|
458
|
-
} else if (this.pending) {
|
|
459
|
-
this.rawSegments.push(this.pending);
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
this.advance(content);
|
|
463
|
-
this.pending = null;
|
|
464
|
-
}
|
|
465
|
-
|
|
466
|
-
addUneditedChunk(sourceIndex, chunk, original, loc, sourcemapLocations) {
|
|
467
|
-
let originalCharIndex = chunk.start;
|
|
468
|
-
let first = true;
|
|
469
|
-
|
|
470
|
-
while (originalCharIndex < chunk.end) {
|
|
471
|
-
if (this.hires || first || sourcemapLocations.has(originalCharIndex)) {
|
|
472
|
-
this.rawSegments.push([this.generatedCodeColumn, sourceIndex, loc.line, loc.column]);
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
if (original[originalCharIndex] === '\n') {
|
|
476
|
-
loc.line += 1;
|
|
477
|
-
loc.column = 0;
|
|
478
|
-
this.generatedCodeLine += 1;
|
|
479
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
480
|
-
this.generatedCodeColumn = 0;
|
|
481
|
-
first = true;
|
|
482
|
-
} else {
|
|
483
|
-
loc.column += 1;
|
|
484
|
-
this.generatedCodeColumn += 1;
|
|
485
|
-
first = false;
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
originalCharIndex += 1;
|
|
489
|
-
}
|
|
490
|
-
|
|
491
|
-
this.pending = null;
|
|
492
|
-
}
|
|
493
|
-
|
|
494
|
-
advance(str) {
|
|
495
|
-
if (!str) return;
|
|
496
|
-
|
|
497
|
-
const lines = str.split('\n');
|
|
498
|
-
|
|
499
|
-
if (lines.length > 1) {
|
|
500
|
-
for (let i = 0; i < lines.length - 1; i++) {
|
|
501
|
-
this.generatedCodeLine++;
|
|
502
|
-
this.raw[this.generatedCodeLine] = this.rawSegments = [];
|
|
503
|
-
}
|
|
504
|
-
this.generatedCodeColumn = 0;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
this.generatedCodeColumn += lines[lines.length - 1].length;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
|
|
511
|
-
const n = '\n';
|
|
512
|
-
|
|
513
|
-
const warned = {
|
|
514
|
-
insertLeft: false,
|
|
515
|
-
insertRight: false,
|
|
516
|
-
storeName: false,
|
|
517
|
-
};
|
|
518
|
-
|
|
519
|
-
class MagicString {
|
|
520
|
-
constructor(string, options = {}) {
|
|
521
|
-
const chunk = new Chunk(0, string.length, string);
|
|
522
|
-
|
|
523
|
-
Object.defineProperties(this, {
|
|
524
|
-
original: { writable: true, value: string },
|
|
525
|
-
outro: { writable: true, value: '' },
|
|
526
|
-
intro: { writable: true, value: '' },
|
|
527
|
-
firstChunk: { writable: true, value: chunk },
|
|
528
|
-
lastChunk: { writable: true, value: chunk },
|
|
529
|
-
lastSearchedChunk: { writable: true, value: chunk },
|
|
530
|
-
byStart: { writable: true, value: {} },
|
|
531
|
-
byEnd: { writable: true, value: {} },
|
|
532
|
-
filename: { writable: true, value: options.filename },
|
|
533
|
-
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
|
534
|
-
sourcemapLocations: { writable: true, value: new BitSet() },
|
|
535
|
-
storedNames: { writable: true, value: {} },
|
|
536
|
-
indentStr: { writable: true, value: undefined },
|
|
537
|
-
});
|
|
538
|
-
|
|
539
|
-
this.byStart[0] = chunk;
|
|
540
|
-
this.byEnd[string.length] = chunk;
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
addSourcemapLocation(char) {
|
|
544
|
-
this.sourcemapLocations.add(char);
|
|
545
|
-
}
|
|
546
|
-
|
|
547
|
-
append(content) {
|
|
548
|
-
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
549
|
-
|
|
550
|
-
this.outro += content;
|
|
551
|
-
return this;
|
|
552
|
-
}
|
|
553
|
-
|
|
554
|
-
appendLeft(index, content) {
|
|
555
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
556
|
-
|
|
557
|
-
this._split(index);
|
|
558
|
-
|
|
559
|
-
const chunk = this.byEnd[index];
|
|
560
|
-
|
|
561
|
-
if (chunk) {
|
|
562
|
-
chunk.appendLeft(content);
|
|
563
|
-
} else {
|
|
564
|
-
this.intro += content;
|
|
565
|
-
}
|
|
566
|
-
return this;
|
|
567
|
-
}
|
|
568
|
-
|
|
569
|
-
appendRight(index, content) {
|
|
570
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
571
|
-
|
|
572
|
-
this._split(index);
|
|
573
|
-
|
|
574
|
-
const chunk = this.byStart[index];
|
|
575
|
-
|
|
576
|
-
if (chunk) {
|
|
577
|
-
chunk.appendRight(content);
|
|
578
|
-
} else {
|
|
579
|
-
this.outro += content;
|
|
580
|
-
}
|
|
581
|
-
return this;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
clone() {
|
|
585
|
-
const cloned = new MagicString(this.original, { filename: this.filename });
|
|
586
|
-
|
|
587
|
-
let originalChunk = this.firstChunk;
|
|
588
|
-
let clonedChunk = (cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone());
|
|
589
|
-
|
|
590
|
-
while (originalChunk) {
|
|
591
|
-
cloned.byStart[clonedChunk.start] = clonedChunk;
|
|
592
|
-
cloned.byEnd[clonedChunk.end] = clonedChunk;
|
|
593
|
-
|
|
594
|
-
const nextOriginalChunk = originalChunk.next;
|
|
595
|
-
const nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
|
596
|
-
|
|
597
|
-
if (nextClonedChunk) {
|
|
598
|
-
clonedChunk.next = nextClonedChunk;
|
|
599
|
-
nextClonedChunk.previous = clonedChunk;
|
|
600
|
-
|
|
601
|
-
clonedChunk = nextClonedChunk;
|
|
602
|
-
}
|
|
603
|
-
|
|
604
|
-
originalChunk = nextOriginalChunk;
|
|
605
|
-
}
|
|
606
|
-
|
|
607
|
-
cloned.lastChunk = clonedChunk;
|
|
608
|
-
|
|
609
|
-
if (this.indentExclusionRanges) {
|
|
610
|
-
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
|
611
|
-
}
|
|
612
|
-
|
|
613
|
-
cloned.sourcemapLocations = new BitSet(this.sourcemapLocations);
|
|
614
|
-
|
|
615
|
-
cloned.intro = this.intro;
|
|
616
|
-
cloned.outro = this.outro;
|
|
617
|
-
|
|
618
|
-
return cloned;
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
generateDecodedMap(options) {
|
|
622
|
-
options = options || {};
|
|
623
|
-
|
|
624
|
-
const sourceIndex = 0;
|
|
625
|
-
const names = Object.keys(this.storedNames);
|
|
626
|
-
const mappings = new Mappings(options.hires);
|
|
627
|
-
|
|
628
|
-
const locate = getLocator(this.original);
|
|
629
|
-
|
|
630
|
-
if (this.intro) {
|
|
631
|
-
mappings.advance(this.intro);
|
|
632
|
-
}
|
|
633
|
-
|
|
634
|
-
this.firstChunk.eachNext((chunk) => {
|
|
635
|
-
const loc = locate(chunk.start);
|
|
636
|
-
|
|
637
|
-
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
638
|
-
|
|
639
|
-
if (chunk.edited) {
|
|
640
|
-
mappings.addEdit(
|
|
641
|
-
sourceIndex,
|
|
642
|
-
chunk.content,
|
|
643
|
-
loc,
|
|
644
|
-
chunk.storeName ? names.indexOf(chunk.original) : -1
|
|
645
|
-
);
|
|
646
|
-
} else {
|
|
647
|
-
mappings.addUneditedChunk(sourceIndex, chunk, this.original, loc, this.sourcemapLocations);
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
651
|
-
});
|
|
652
|
-
|
|
653
|
-
return {
|
|
654
|
-
file: options.file ? options.file.split(/[/\\]/).pop() : null,
|
|
655
|
-
sources: [options.source ? getRelativePath(options.file || '', options.source) : null],
|
|
656
|
-
sourcesContent: options.includeContent ? [this.original] : [null],
|
|
657
|
-
names,
|
|
658
|
-
mappings: mappings.raw,
|
|
659
|
-
};
|
|
660
|
-
}
|
|
661
|
-
|
|
662
|
-
generateMap(options) {
|
|
663
|
-
return new SourceMap(this.generateDecodedMap(options));
|
|
664
|
-
}
|
|
665
|
-
|
|
666
|
-
_ensureindentStr() {
|
|
667
|
-
if (this.indentStr === undefined) {
|
|
668
|
-
this.indentStr = guessIndent(this.original);
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
|
|
672
|
-
_getRawIndentString() {
|
|
673
|
-
this._ensureindentStr();
|
|
674
|
-
return this.indentStr;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
getIndentString() {
|
|
678
|
-
this._ensureindentStr();
|
|
679
|
-
return this.indentStr === null ? '\t' : this.indentStr;
|
|
680
|
-
}
|
|
681
|
-
|
|
682
|
-
indent(indentStr, options) {
|
|
683
|
-
const pattern = /^[^\r\n]/gm;
|
|
684
|
-
|
|
685
|
-
if (isObject(indentStr)) {
|
|
686
|
-
options = indentStr;
|
|
687
|
-
indentStr = undefined;
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
if (indentStr === undefined) {
|
|
691
|
-
this._ensureindentStr();
|
|
692
|
-
indentStr = this.indentStr || '\t';
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
if (indentStr === '') return this; // noop
|
|
696
|
-
|
|
697
|
-
options = options || {};
|
|
698
|
-
|
|
699
|
-
// Process exclusion ranges
|
|
700
|
-
const isExcluded = {};
|
|
701
|
-
|
|
702
|
-
if (options.exclude) {
|
|
703
|
-
const exclusions =
|
|
704
|
-
typeof options.exclude[0] === 'number' ? [options.exclude] : options.exclude;
|
|
705
|
-
exclusions.forEach((exclusion) => {
|
|
706
|
-
for (let i = exclusion[0]; i < exclusion[1]; i += 1) {
|
|
707
|
-
isExcluded[i] = true;
|
|
708
|
-
}
|
|
709
|
-
});
|
|
710
|
-
}
|
|
711
|
-
|
|
712
|
-
let shouldIndentNextCharacter = options.indentStart !== false;
|
|
713
|
-
const replacer = (match) => {
|
|
714
|
-
if (shouldIndentNextCharacter) return `${indentStr}${match}`;
|
|
715
|
-
shouldIndentNextCharacter = true;
|
|
716
|
-
return match;
|
|
717
|
-
};
|
|
718
|
-
|
|
719
|
-
this.intro = this.intro.replace(pattern, replacer);
|
|
720
|
-
|
|
721
|
-
let charIndex = 0;
|
|
722
|
-
let chunk = this.firstChunk;
|
|
723
|
-
|
|
724
|
-
while (chunk) {
|
|
725
|
-
const end = chunk.end;
|
|
726
|
-
|
|
727
|
-
if (chunk.edited) {
|
|
728
|
-
if (!isExcluded[charIndex]) {
|
|
729
|
-
chunk.content = chunk.content.replace(pattern, replacer);
|
|
730
|
-
|
|
731
|
-
if (chunk.content.length) {
|
|
732
|
-
shouldIndentNextCharacter = chunk.content[chunk.content.length - 1] === '\n';
|
|
733
|
-
}
|
|
734
|
-
}
|
|
735
|
-
} else {
|
|
736
|
-
charIndex = chunk.start;
|
|
737
|
-
|
|
738
|
-
while (charIndex < end) {
|
|
739
|
-
if (!isExcluded[charIndex]) {
|
|
740
|
-
const char = this.original[charIndex];
|
|
741
|
-
|
|
742
|
-
if (char === '\n') {
|
|
743
|
-
shouldIndentNextCharacter = true;
|
|
744
|
-
} else if (char !== '\r' && shouldIndentNextCharacter) {
|
|
745
|
-
shouldIndentNextCharacter = false;
|
|
746
|
-
|
|
747
|
-
if (charIndex === chunk.start) {
|
|
748
|
-
chunk.prependRight(indentStr);
|
|
749
|
-
} else {
|
|
750
|
-
this._splitChunk(chunk, charIndex);
|
|
751
|
-
chunk = chunk.next;
|
|
752
|
-
chunk.prependRight(indentStr);
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
charIndex += 1;
|
|
758
|
-
}
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
charIndex = chunk.end;
|
|
762
|
-
chunk = chunk.next;
|
|
763
|
-
}
|
|
764
|
-
|
|
765
|
-
this.outro = this.outro.replace(pattern, replacer);
|
|
766
|
-
|
|
767
|
-
return this;
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
insert() {
|
|
771
|
-
throw new Error(
|
|
772
|
-
'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)'
|
|
773
|
-
);
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
insertLeft(index, content) {
|
|
777
|
-
if (!warned.insertLeft) {
|
|
778
|
-
console.warn(
|
|
779
|
-
'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead'
|
|
780
|
-
); // eslint-disable-line no-console
|
|
781
|
-
warned.insertLeft = true;
|
|
782
|
-
}
|
|
783
|
-
|
|
784
|
-
return this.appendLeft(index, content);
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
insertRight(index, content) {
|
|
788
|
-
if (!warned.insertRight) {
|
|
789
|
-
console.warn(
|
|
790
|
-
'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead'
|
|
791
|
-
); // eslint-disable-line no-console
|
|
792
|
-
warned.insertRight = true;
|
|
793
|
-
}
|
|
794
|
-
|
|
795
|
-
return this.prependRight(index, content);
|
|
796
|
-
}
|
|
797
|
-
|
|
798
|
-
move(start, end, index) {
|
|
799
|
-
if (index >= start && index <= end) throw new Error('Cannot move a selection inside itself');
|
|
800
|
-
|
|
801
|
-
this._split(start);
|
|
802
|
-
this._split(end);
|
|
803
|
-
this._split(index);
|
|
804
|
-
|
|
805
|
-
const first = this.byStart[start];
|
|
806
|
-
const last = this.byEnd[end];
|
|
807
|
-
|
|
808
|
-
const oldLeft = first.previous;
|
|
809
|
-
const oldRight = last.next;
|
|
810
|
-
|
|
811
|
-
const newRight = this.byStart[index];
|
|
812
|
-
if (!newRight && last === this.lastChunk) return this;
|
|
813
|
-
const newLeft = newRight ? newRight.previous : this.lastChunk;
|
|
814
|
-
|
|
815
|
-
if (oldLeft) oldLeft.next = oldRight;
|
|
816
|
-
if (oldRight) oldRight.previous = oldLeft;
|
|
817
|
-
|
|
818
|
-
if (newLeft) newLeft.next = first;
|
|
819
|
-
if (newRight) newRight.previous = last;
|
|
820
|
-
|
|
821
|
-
if (!first.previous) this.firstChunk = last.next;
|
|
822
|
-
if (!last.next) {
|
|
823
|
-
this.lastChunk = first.previous;
|
|
824
|
-
this.lastChunk.next = null;
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
first.previous = newLeft;
|
|
828
|
-
last.next = newRight || null;
|
|
829
|
-
|
|
830
|
-
if (!newLeft) this.firstChunk = first;
|
|
831
|
-
if (!newRight) this.lastChunk = last;
|
|
832
|
-
return this;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
overwrite(start, end, content, options) {
|
|
836
|
-
options = options || {};
|
|
837
|
-
return this.update(start, end, content, { ...options, overwrite: !options.contentOnly });
|
|
838
|
-
}
|
|
839
|
-
|
|
840
|
-
update(start, end, content, options) {
|
|
841
|
-
if (typeof content !== 'string') throw new TypeError('replacement content must be a string');
|
|
842
|
-
|
|
843
|
-
while (start < 0) start += this.original.length;
|
|
844
|
-
while (end < 0) end += this.original.length;
|
|
845
|
-
|
|
846
|
-
if (end > this.original.length) throw new Error('end is out of bounds');
|
|
847
|
-
if (start === end)
|
|
848
|
-
throw new Error(
|
|
849
|
-
'Cannot overwrite a zero-length range – use appendLeft or prependRight instead'
|
|
850
|
-
);
|
|
851
|
-
|
|
852
|
-
this._split(start);
|
|
853
|
-
this._split(end);
|
|
854
|
-
|
|
855
|
-
if (options === true) {
|
|
856
|
-
if (!warned.storeName) {
|
|
857
|
-
console.warn(
|
|
858
|
-
'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string'
|
|
859
|
-
); // eslint-disable-line no-console
|
|
860
|
-
warned.storeName = true;
|
|
861
|
-
}
|
|
862
|
-
|
|
863
|
-
options = { storeName: true };
|
|
864
|
-
}
|
|
865
|
-
const storeName = options !== undefined ? options.storeName : false;
|
|
866
|
-
const overwrite = options !== undefined ? options.overwrite : false;
|
|
867
|
-
|
|
868
|
-
if (storeName) {
|
|
869
|
-
const original = this.original.slice(start, end);
|
|
870
|
-
Object.defineProperty(this.storedNames, original, {
|
|
871
|
-
writable: true,
|
|
872
|
-
value: true,
|
|
873
|
-
enumerable: true,
|
|
874
|
-
});
|
|
875
|
-
}
|
|
876
|
-
|
|
877
|
-
const first = this.byStart[start];
|
|
878
|
-
const last = this.byEnd[end];
|
|
879
|
-
|
|
880
|
-
if (first) {
|
|
881
|
-
let chunk = first;
|
|
882
|
-
while (chunk !== last) {
|
|
883
|
-
if (chunk.next !== this.byStart[chunk.end]) {
|
|
884
|
-
throw new Error('Cannot overwrite across a split point');
|
|
885
|
-
}
|
|
886
|
-
chunk = chunk.next;
|
|
887
|
-
chunk.edit('', false);
|
|
888
|
-
}
|
|
889
|
-
|
|
890
|
-
first.edit(content, storeName, !overwrite);
|
|
891
|
-
} else {
|
|
892
|
-
// must be inserting at the end
|
|
893
|
-
const newChunk = new Chunk(start, end, '').edit(content, storeName);
|
|
894
|
-
|
|
895
|
-
// TODO last chunk in the array may not be the last chunk, if it's moved...
|
|
896
|
-
last.next = newChunk;
|
|
897
|
-
newChunk.previous = last;
|
|
898
|
-
}
|
|
899
|
-
return this;
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
prepend(content) {
|
|
903
|
-
if (typeof content !== 'string') throw new TypeError('outro content must be a string');
|
|
904
|
-
|
|
905
|
-
this.intro = content + this.intro;
|
|
906
|
-
return this;
|
|
907
|
-
}
|
|
908
|
-
|
|
909
|
-
prependLeft(index, content) {
|
|
910
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
911
|
-
|
|
912
|
-
this._split(index);
|
|
913
|
-
|
|
914
|
-
const chunk = this.byEnd[index];
|
|
915
|
-
|
|
916
|
-
if (chunk) {
|
|
917
|
-
chunk.prependLeft(content);
|
|
918
|
-
} else {
|
|
919
|
-
this.intro = content + this.intro;
|
|
920
|
-
}
|
|
921
|
-
return this;
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
prependRight(index, content) {
|
|
925
|
-
if (typeof content !== 'string') throw new TypeError('inserted content must be a string');
|
|
926
|
-
|
|
927
|
-
this._split(index);
|
|
928
|
-
|
|
929
|
-
const chunk = this.byStart[index];
|
|
930
|
-
|
|
931
|
-
if (chunk) {
|
|
932
|
-
chunk.prependRight(content);
|
|
933
|
-
} else {
|
|
934
|
-
this.outro = content + this.outro;
|
|
935
|
-
}
|
|
936
|
-
return this;
|
|
937
|
-
}
|
|
938
|
-
|
|
939
|
-
remove(start, end) {
|
|
940
|
-
while (start < 0) start += this.original.length;
|
|
941
|
-
while (end < 0) end += this.original.length;
|
|
942
|
-
|
|
943
|
-
if (start === end) return this;
|
|
944
|
-
|
|
945
|
-
if (start < 0 || end > this.original.length) throw new Error('Character is out of bounds');
|
|
946
|
-
if (start > end) throw new Error('end must be greater than start');
|
|
947
|
-
|
|
948
|
-
this._split(start);
|
|
949
|
-
this._split(end);
|
|
950
|
-
|
|
951
|
-
let chunk = this.byStart[start];
|
|
952
|
-
|
|
953
|
-
while (chunk) {
|
|
954
|
-
chunk.intro = '';
|
|
955
|
-
chunk.outro = '';
|
|
956
|
-
chunk.edit('');
|
|
957
|
-
|
|
958
|
-
chunk = end > chunk.end ? this.byStart[chunk.end] : null;
|
|
959
|
-
}
|
|
960
|
-
return this;
|
|
961
|
-
}
|
|
962
|
-
|
|
963
|
-
lastChar() {
|
|
964
|
-
if (this.outro.length) return this.outro[this.outro.length - 1];
|
|
965
|
-
let chunk = this.lastChunk;
|
|
966
|
-
do {
|
|
967
|
-
if (chunk.outro.length) return chunk.outro[chunk.outro.length - 1];
|
|
968
|
-
if (chunk.content.length) return chunk.content[chunk.content.length - 1];
|
|
969
|
-
if (chunk.intro.length) return chunk.intro[chunk.intro.length - 1];
|
|
970
|
-
} while ((chunk = chunk.previous));
|
|
971
|
-
if (this.intro.length) return this.intro[this.intro.length - 1];
|
|
972
|
-
return '';
|
|
973
|
-
}
|
|
974
|
-
|
|
975
|
-
lastLine() {
|
|
976
|
-
let lineIndex = this.outro.lastIndexOf(n);
|
|
977
|
-
if (lineIndex !== -1) return this.outro.substr(lineIndex + 1);
|
|
978
|
-
let lineStr = this.outro;
|
|
979
|
-
let chunk = this.lastChunk;
|
|
980
|
-
do {
|
|
981
|
-
if (chunk.outro.length > 0) {
|
|
982
|
-
lineIndex = chunk.outro.lastIndexOf(n);
|
|
983
|
-
if (lineIndex !== -1) return chunk.outro.substr(lineIndex + 1) + lineStr;
|
|
984
|
-
lineStr = chunk.outro + lineStr;
|
|
985
|
-
}
|
|
986
|
-
|
|
987
|
-
if (chunk.content.length > 0) {
|
|
988
|
-
lineIndex = chunk.content.lastIndexOf(n);
|
|
989
|
-
if (lineIndex !== -1) return chunk.content.substr(lineIndex + 1) + lineStr;
|
|
990
|
-
lineStr = chunk.content + lineStr;
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
if (chunk.intro.length > 0) {
|
|
994
|
-
lineIndex = chunk.intro.lastIndexOf(n);
|
|
995
|
-
if (lineIndex !== -1) return chunk.intro.substr(lineIndex + 1) + lineStr;
|
|
996
|
-
lineStr = chunk.intro + lineStr;
|
|
997
|
-
}
|
|
998
|
-
} while ((chunk = chunk.previous));
|
|
999
|
-
lineIndex = this.intro.lastIndexOf(n);
|
|
1000
|
-
if (lineIndex !== -1) return this.intro.substr(lineIndex + 1) + lineStr;
|
|
1001
|
-
return this.intro + lineStr;
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
|
-
slice(start = 0, end = this.original.length) {
|
|
1005
|
-
while (start < 0) start += this.original.length;
|
|
1006
|
-
while (end < 0) end += this.original.length;
|
|
1007
|
-
|
|
1008
|
-
let result = '';
|
|
1009
|
-
|
|
1010
|
-
// find start chunk
|
|
1011
|
-
let chunk = this.firstChunk;
|
|
1012
|
-
while (chunk && (chunk.start > start || chunk.end <= start)) {
|
|
1013
|
-
// found end chunk before start
|
|
1014
|
-
if (chunk.start < end && chunk.end >= end) {
|
|
1015
|
-
return result;
|
|
1016
|
-
}
|
|
1017
|
-
|
|
1018
|
-
chunk = chunk.next;
|
|
1019
|
-
}
|
|
1020
|
-
|
|
1021
|
-
if (chunk && chunk.edited && chunk.start !== start)
|
|
1022
|
-
throw new Error(`Cannot use replaced character ${start} as slice start anchor.`);
|
|
1023
|
-
|
|
1024
|
-
const startChunk = chunk;
|
|
1025
|
-
while (chunk) {
|
|
1026
|
-
if (chunk.intro && (startChunk !== chunk || chunk.start === start)) {
|
|
1027
|
-
result += chunk.intro;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
const containsEnd = chunk.start < end && chunk.end >= end;
|
|
1031
|
-
if (containsEnd && chunk.edited && chunk.end !== end)
|
|
1032
|
-
throw new Error(`Cannot use replaced character ${end} as slice end anchor.`);
|
|
1033
|
-
|
|
1034
|
-
const sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
|
1035
|
-
const sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
|
1036
|
-
|
|
1037
|
-
result += chunk.content.slice(sliceStart, sliceEnd);
|
|
1038
|
-
|
|
1039
|
-
if (chunk.outro && (!containsEnd || chunk.end === end)) {
|
|
1040
|
-
result += chunk.outro;
|
|
1041
|
-
}
|
|
1042
|
-
|
|
1043
|
-
if (containsEnd) {
|
|
1044
|
-
break;
|
|
1045
|
-
}
|
|
1046
|
-
|
|
1047
|
-
chunk = chunk.next;
|
|
1048
|
-
}
|
|
1049
|
-
|
|
1050
|
-
return result;
|
|
1051
|
-
}
|
|
1052
|
-
|
|
1053
|
-
// TODO deprecate this? not really very useful
|
|
1054
|
-
snip(start, end) {
|
|
1055
|
-
const clone = this.clone();
|
|
1056
|
-
clone.remove(0, start);
|
|
1057
|
-
clone.remove(end, clone.original.length);
|
|
1058
|
-
|
|
1059
|
-
return clone;
|
|
1060
|
-
}
|
|
1061
|
-
|
|
1062
|
-
_split(index) {
|
|
1063
|
-
if (this.byStart[index] || this.byEnd[index]) return;
|
|
1064
|
-
|
|
1065
|
-
let chunk = this.lastSearchedChunk;
|
|
1066
|
-
const searchForward = index > chunk.end;
|
|
1067
|
-
|
|
1068
|
-
while (chunk) {
|
|
1069
|
-
if (chunk.contains(index)) return this._splitChunk(chunk, index);
|
|
1070
|
-
|
|
1071
|
-
chunk = searchForward ? this.byStart[chunk.end] : this.byEnd[chunk.start];
|
|
1072
|
-
}
|
|
1073
|
-
}
|
|
1074
|
-
|
|
1075
|
-
_splitChunk(chunk, index) {
|
|
1076
|
-
if (chunk.edited && chunk.content.length) {
|
|
1077
|
-
// zero-length edited chunks are a special case (overlapping replacements)
|
|
1078
|
-
const loc = getLocator(this.original)(index);
|
|
1079
|
-
throw new Error(
|
|
1080
|
-
`Cannot split a chunk that has already been edited (${loc.line}:${loc.column} – "${chunk.original}")`
|
|
1081
|
-
);
|
|
1082
|
-
}
|
|
1083
|
-
|
|
1084
|
-
const newChunk = chunk.split(index);
|
|
1085
|
-
|
|
1086
|
-
this.byEnd[index] = chunk;
|
|
1087
|
-
this.byStart[index] = newChunk;
|
|
1088
|
-
this.byEnd[newChunk.end] = newChunk;
|
|
1089
|
-
|
|
1090
|
-
if (chunk === this.lastChunk) this.lastChunk = newChunk;
|
|
1091
|
-
|
|
1092
|
-
this.lastSearchedChunk = chunk;
|
|
1093
|
-
return true;
|
|
1094
|
-
}
|
|
1095
|
-
|
|
1096
|
-
toString() {
|
|
1097
|
-
let str = this.intro;
|
|
1098
|
-
|
|
1099
|
-
let chunk = this.firstChunk;
|
|
1100
|
-
while (chunk) {
|
|
1101
|
-
str += chunk.toString();
|
|
1102
|
-
chunk = chunk.next;
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
return str + this.outro;
|
|
1106
|
-
}
|
|
1107
|
-
|
|
1108
|
-
isEmpty() {
|
|
1109
|
-
let chunk = this.firstChunk;
|
|
1110
|
-
do {
|
|
1111
|
-
if (
|
|
1112
|
-
(chunk.intro.length && chunk.intro.trim()) ||
|
|
1113
|
-
(chunk.content.length && chunk.content.trim()) ||
|
|
1114
|
-
(chunk.outro.length && chunk.outro.trim())
|
|
1115
|
-
)
|
|
1116
|
-
return false;
|
|
1117
|
-
} while ((chunk = chunk.next));
|
|
1118
|
-
return true;
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
length() {
|
|
1122
|
-
let chunk = this.firstChunk;
|
|
1123
|
-
let length = 0;
|
|
1124
|
-
do {
|
|
1125
|
-
length += chunk.intro.length + chunk.content.length + chunk.outro.length;
|
|
1126
|
-
} while ((chunk = chunk.next));
|
|
1127
|
-
return length;
|
|
1128
|
-
}
|
|
1129
|
-
|
|
1130
|
-
trimLines() {
|
|
1131
|
-
return this.trim('[\\r\\n]');
|
|
1132
|
-
}
|
|
1133
|
-
|
|
1134
|
-
trim(charType) {
|
|
1135
|
-
return this.trimStart(charType).trimEnd(charType);
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
trimEndAborted(charType) {
|
|
1139
|
-
const rx = new RegExp((charType || '\\s') + '+$');
|
|
1140
|
-
|
|
1141
|
-
this.outro = this.outro.replace(rx, '');
|
|
1142
|
-
if (this.outro.length) return true;
|
|
1143
|
-
|
|
1144
|
-
let chunk = this.lastChunk;
|
|
1145
|
-
|
|
1146
|
-
do {
|
|
1147
|
-
const end = chunk.end;
|
|
1148
|
-
const aborted = chunk.trimEnd(rx);
|
|
1149
|
-
|
|
1150
|
-
// if chunk was trimmed, we have a new lastChunk
|
|
1151
|
-
if (chunk.end !== end) {
|
|
1152
|
-
if (this.lastChunk === chunk) {
|
|
1153
|
-
this.lastChunk = chunk.next;
|
|
1154
|
-
}
|
|
1155
|
-
|
|
1156
|
-
this.byEnd[chunk.end] = chunk;
|
|
1157
|
-
this.byStart[chunk.next.start] = chunk.next;
|
|
1158
|
-
this.byEnd[chunk.next.end] = chunk.next;
|
|
1159
|
-
}
|
|
1160
|
-
|
|
1161
|
-
if (aborted) return true;
|
|
1162
|
-
chunk = chunk.previous;
|
|
1163
|
-
} while (chunk);
|
|
1164
|
-
|
|
1165
|
-
return false;
|
|
1166
|
-
}
|
|
1167
|
-
|
|
1168
|
-
trimEnd(charType) {
|
|
1169
|
-
this.trimEndAborted(charType);
|
|
1170
|
-
return this;
|
|
1171
|
-
}
|
|
1172
|
-
trimStartAborted(charType) {
|
|
1173
|
-
const rx = new RegExp('^' + (charType || '\\s') + '+');
|
|
1174
|
-
|
|
1175
|
-
this.intro = this.intro.replace(rx, '');
|
|
1176
|
-
if (this.intro.length) return true;
|
|
1177
|
-
|
|
1178
|
-
let chunk = this.firstChunk;
|
|
1179
|
-
|
|
1180
|
-
do {
|
|
1181
|
-
const end = chunk.end;
|
|
1182
|
-
const aborted = chunk.trimStart(rx);
|
|
1183
|
-
|
|
1184
|
-
if (chunk.end !== end) {
|
|
1185
|
-
// special case...
|
|
1186
|
-
if (chunk === this.lastChunk) this.lastChunk = chunk.next;
|
|
1187
|
-
|
|
1188
|
-
this.byEnd[chunk.end] = chunk;
|
|
1189
|
-
this.byStart[chunk.next.start] = chunk.next;
|
|
1190
|
-
this.byEnd[chunk.next.end] = chunk.next;
|
|
1191
|
-
}
|
|
1192
|
-
|
|
1193
|
-
if (aborted) return true;
|
|
1194
|
-
chunk = chunk.next;
|
|
1195
|
-
} while (chunk);
|
|
1196
|
-
|
|
1197
|
-
return false;
|
|
1198
|
-
}
|
|
1199
|
-
|
|
1200
|
-
trimStart(charType) {
|
|
1201
|
-
this.trimStartAborted(charType);
|
|
1202
|
-
return this;
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
hasChanged() {
|
|
1206
|
-
return this.original !== this.toString();
|
|
1207
|
-
}
|
|
1208
|
-
|
|
1209
|
-
_replaceRegexp(searchValue, replacement) {
|
|
1210
|
-
function getReplacement(match, str) {
|
|
1211
|
-
if (typeof replacement === 'string') {
|
|
1212
|
-
return replacement.replace(/\$(\$|&|\d+)/g, (_, i) => {
|
|
1213
|
-
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace#specifying_a_string_as_a_parameter
|
|
1214
|
-
if (i === '$') return '$';
|
|
1215
|
-
if (i === '&') return match[0];
|
|
1216
|
-
const num = +i;
|
|
1217
|
-
if (num < match.length) return match[+i];
|
|
1218
|
-
return `$${i}`;
|
|
1219
|
-
});
|
|
1220
|
-
} else {
|
|
1221
|
-
return replacement(...match, match.index, str, match.groups);
|
|
1222
|
-
}
|
|
1223
|
-
}
|
|
1224
|
-
function matchAll(re, str) {
|
|
1225
|
-
let match;
|
|
1226
|
-
const matches = [];
|
|
1227
|
-
while ((match = re.exec(str))) {
|
|
1228
|
-
matches.push(match);
|
|
1229
|
-
}
|
|
1230
|
-
return matches;
|
|
1231
|
-
}
|
|
1232
|
-
if (searchValue.global) {
|
|
1233
|
-
const matches = matchAll(searchValue, this.original);
|
|
1234
|
-
matches.forEach((match) => {
|
|
1235
|
-
if (match.index != null)
|
|
1236
|
-
this.overwrite(
|
|
1237
|
-
match.index,
|
|
1238
|
-
match.index + match[0].length,
|
|
1239
|
-
getReplacement(match, this.original)
|
|
1240
|
-
);
|
|
1241
|
-
});
|
|
1242
|
-
} else {
|
|
1243
|
-
const match = this.original.match(searchValue);
|
|
1244
|
-
if (match && match.index != null)
|
|
1245
|
-
this.overwrite(
|
|
1246
|
-
match.index,
|
|
1247
|
-
match.index + match[0].length,
|
|
1248
|
-
getReplacement(match, this.original)
|
|
1249
|
-
);
|
|
1250
|
-
}
|
|
1251
|
-
return this;
|
|
1252
|
-
}
|
|
1253
|
-
|
|
1254
|
-
_replaceString(string, replacement) {
|
|
1255
|
-
const { original } = this;
|
|
1256
|
-
const index = original.indexOf(string);
|
|
1257
|
-
|
|
1258
|
-
if (index !== -1) {
|
|
1259
|
-
this.overwrite(index, index + string.length, replacement);
|
|
1260
|
-
}
|
|
1261
|
-
|
|
1262
|
-
return this;
|
|
1263
|
-
}
|
|
1264
|
-
|
|
1265
|
-
replace(searchValue, replacement) {
|
|
1266
|
-
if (typeof searchValue === 'string') {
|
|
1267
|
-
return this._replaceString(searchValue, replacement);
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
return this._replaceRegexp(searchValue, replacement);
|
|
1271
|
-
}
|
|
1272
|
-
|
|
1273
|
-
_replaceAllString(string, replacement) {
|
|
1274
|
-
const { original } = this;
|
|
1275
|
-
const stringLength = string.length;
|
|
1276
|
-
for (
|
|
1277
|
-
let index = original.indexOf(string);
|
|
1278
|
-
index !== -1;
|
|
1279
|
-
index = original.indexOf(string, index + stringLength)
|
|
1280
|
-
) {
|
|
1281
|
-
this.overwrite(index, index + stringLength, replacement);
|
|
1282
|
-
}
|
|
1283
|
-
|
|
1284
|
-
return this;
|
|
1285
|
-
}
|
|
1286
|
-
|
|
1287
|
-
replaceAll(searchValue, replacement) {
|
|
1288
|
-
if (typeof searchValue === 'string') {
|
|
1289
|
-
return this._replaceAllString(searchValue, replacement);
|
|
1290
|
-
}
|
|
1291
|
-
|
|
1292
|
-
if (!searchValue.global) {
|
|
1293
|
-
throw new TypeError(
|
|
1294
|
-
'MagicString.prototype.replaceAll called with a non-global RegExp argument'
|
|
1295
|
-
);
|
|
1296
|
-
}
|
|
1297
|
-
|
|
1298
|
-
return this._replaceRegexp(searchValue, replacement);
|
|
1299
|
-
}
|
|
1300
|
-
}
|
|
1301
|
-
|
|
1302
|
-
const hasOwnProp = Object.prototype.hasOwnProperty;
|
|
1303
|
-
|
|
1304
|
-
class Bundle {
|
|
1305
|
-
constructor(options = {}) {
|
|
1306
|
-
this.intro = options.intro || '';
|
|
1307
|
-
this.separator = options.separator !== undefined ? options.separator : '\n';
|
|
1308
|
-
this.sources = [];
|
|
1309
|
-
this.uniqueSources = [];
|
|
1310
|
-
this.uniqueSourceIndexByFilename = {};
|
|
1311
|
-
}
|
|
1312
|
-
|
|
1313
|
-
addSource(source) {
|
|
1314
|
-
if (source instanceof MagicString) {
|
|
1315
|
-
return this.addSource({
|
|
1316
|
-
content: source,
|
|
1317
|
-
filename: source.filename,
|
|
1318
|
-
separator: this.separator,
|
|
1319
|
-
});
|
|
1320
|
-
}
|
|
1321
|
-
|
|
1322
|
-
if (!isObject(source) || !source.content) {
|
|
1323
|
-
throw new Error(
|
|
1324
|
-
'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`'
|
|
1325
|
-
);
|
|
1326
|
-
}
|
|
1327
|
-
|
|
1328
|
-
['filename', 'indentExclusionRanges', 'separator'].forEach((option) => {
|
|
1329
|
-
if (!hasOwnProp.call(source, option)) source[option] = source.content[option];
|
|
1330
|
-
});
|
|
1331
|
-
|
|
1332
|
-
if (source.separator === undefined) {
|
|
1333
|
-
// TODO there's a bunch of this sort of thing, needs cleaning up
|
|
1334
|
-
source.separator = this.separator;
|
|
1335
|
-
}
|
|
1336
|
-
|
|
1337
|
-
if (source.filename) {
|
|
1338
|
-
if (!hasOwnProp.call(this.uniqueSourceIndexByFilename, source.filename)) {
|
|
1339
|
-
this.uniqueSourceIndexByFilename[source.filename] = this.uniqueSources.length;
|
|
1340
|
-
this.uniqueSources.push({ filename: source.filename, content: source.content.original });
|
|
1341
|
-
} else {
|
|
1342
|
-
const uniqueSource = this.uniqueSources[this.uniqueSourceIndexByFilename[source.filename]];
|
|
1343
|
-
if (source.content.original !== uniqueSource.content) {
|
|
1344
|
-
throw new Error(`Illegal source: same filename (${source.filename}), different contents`);
|
|
1345
|
-
}
|
|
1346
|
-
}
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
this.sources.push(source);
|
|
1350
|
-
return this;
|
|
1351
|
-
}
|
|
1352
|
-
|
|
1353
|
-
append(str, options) {
|
|
1354
|
-
this.addSource({
|
|
1355
|
-
content: new MagicString(str),
|
|
1356
|
-
separator: (options && options.separator) || '',
|
|
1357
|
-
});
|
|
1358
|
-
|
|
1359
|
-
return this;
|
|
1360
|
-
}
|
|
1361
|
-
|
|
1362
|
-
clone() {
|
|
1363
|
-
const bundle = new Bundle({
|
|
1364
|
-
intro: this.intro,
|
|
1365
|
-
separator: this.separator,
|
|
1366
|
-
});
|
|
1367
|
-
|
|
1368
|
-
this.sources.forEach((source) => {
|
|
1369
|
-
bundle.addSource({
|
|
1370
|
-
filename: source.filename,
|
|
1371
|
-
content: source.content.clone(),
|
|
1372
|
-
separator: source.separator,
|
|
1373
|
-
});
|
|
1374
|
-
});
|
|
1375
|
-
|
|
1376
|
-
return bundle;
|
|
1377
|
-
}
|
|
1378
|
-
|
|
1379
|
-
generateDecodedMap(options = {}) {
|
|
1380
|
-
const names = [];
|
|
1381
|
-
this.sources.forEach((source) => {
|
|
1382
|
-
Object.keys(source.content.storedNames).forEach((name) => {
|
|
1383
|
-
if (!~names.indexOf(name)) names.push(name);
|
|
1384
|
-
});
|
|
1385
|
-
});
|
|
1386
|
-
|
|
1387
|
-
const mappings = new Mappings(options.hires);
|
|
1388
|
-
|
|
1389
|
-
if (this.intro) {
|
|
1390
|
-
mappings.advance(this.intro);
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
this.sources.forEach((source, i) => {
|
|
1394
|
-
if (i > 0) {
|
|
1395
|
-
mappings.advance(this.separator);
|
|
1396
|
-
}
|
|
1397
|
-
|
|
1398
|
-
const sourceIndex = source.filename ? this.uniqueSourceIndexByFilename[source.filename] : -1;
|
|
1399
|
-
const magicString = source.content;
|
|
1400
|
-
const locate = getLocator(magicString.original);
|
|
1401
|
-
|
|
1402
|
-
if (magicString.intro) {
|
|
1403
|
-
mappings.advance(magicString.intro);
|
|
1404
|
-
}
|
|
1405
|
-
|
|
1406
|
-
magicString.firstChunk.eachNext((chunk) => {
|
|
1407
|
-
const loc = locate(chunk.start);
|
|
1408
|
-
|
|
1409
|
-
if (chunk.intro.length) mappings.advance(chunk.intro);
|
|
1410
|
-
|
|
1411
|
-
if (source.filename) {
|
|
1412
|
-
if (chunk.edited) {
|
|
1413
|
-
mappings.addEdit(
|
|
1414
|
-
sourceIndex,
|
|
1415
|
-
chunk.content,
|
|
1416
|
-
loc,
|
|
1417
|
-
chunk.storeName ? names.indexOf(chunk.original) : -1
|
|
1418
|
-
);
|
|
1419
|
-
} else {
|
|
1420
|
-
mappings.addUneditedChunk(
|
|
1421
|
-
sourceIndex,
|
|
1422
|
-
chunk,
|
|
1423
|
-
magicString.original,
|
|
1424
|
-
loc,
|
|
1425
|
-
magicString.sourcemapLocations
|
|
1426
|
-
);
|
|
1427
|
-
}
|
|
1428
|
-
} else {
|
|
1429
|
-
mappings.advance(chunk.content);
|
|
1430
|
-
}
|
|
1431
|
-
|
|
1432
|
-
if (chunk.outro.length) mappings.advance(chunk.outro);
|
|
1433
|
-
});
|
|
1434
|
-
|
|
1435
|
-
if (magicString.outro) {
|
|
1436
|
-
mappings.advance(magicString.outro);
|
|
1437
|
-
}
|
|
1438
|
-
});
|
|
1439
|
-
|
|
1440
|
-
return {
|
|
1441
|
-
file: options.file ? options.file.split(/[/\\]/).pop() : null,
|
|
1442
|
-
sources: this.uniqueSources.map((source) => {
|
|
1443
|
-
return options.file ? getRelativePath(options.file, source.filename) : source.filename;
|
|
1444
|
-
}),
|
|
1445
|
-
sourcesContent: this.uniqueSources.map((source) => {
|
|
1446
|
-
return options.includeContent ? source.content : null;
|
|
1447
|
-
}),
|
|
1448
|
-
names,
|
|
1449
|
-
mappings: mappings.raw,
|
|
1450
|
-
};
|
|
1451
|
-
}
|
|
1452
|
-
|
|
1453
|
-
generateMap(options) {
|
|
1454
|
-
return new SourceMap(this.generateDecodedMap(options));
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
getIndentString() {
|
|
1458
|
-
const indentStringCounts = {};
|
|
1459
|
-
|
|
1460
|
-
this.sources.forEach((source) => {
|
|
1461
|
-
const indentStr = source.content._getRawIndentString();
|
|
1462
|
-
|
|
1463
|
-
if (indentStr === null) return;
|
|
1464
|
-
|
|
1465
|
-
if (!indentStringCounts[indentStr]) indentStringCounts[indentStr] = 0;
|
|
1466
|
-
indentStringCounts[indentStr] += 1;
|
|
1467
|
-
});
|
|
1468
|
-
|
|
1469
|
-
return (
|
|
1470
|
-
Object.keys(indentStringCounts).sort((a, b) => {
|
|
1471
|
-
return indentStringCounts[a] - indentStringCounts[b];
|
|
1472
|
-
})[0] || '\t'
|
|
1473
|
-
);
|
|
1474
|
-
}
|
|
1475
|
-
|
|
1476
|
-
indent(indentStr) {
|
|
1477
|
-
if (!arguments.length) {
|
|
1478
|
-
indentStr = this.getIndentString();
|
|
1479
|
-
}
|
|
1480
|
-
|
|
1481
|
-
if (indentStr === '') return this; // noop
|
|
1482
|
-
|
|
1483
|
-
let trailingNewline = !this.intro || this.intro.slice(-1) === '\n';
|
|
1484
|
-
|
|
1485
|
-
this.sources.forEach((source, i) => {
|
|
1486
|
-
const separator = source.separator !== undefined ? source.separator : this.separator;
|
|
1487
|
-
const indentStart = trailingNewline || (i > 0 && /\r?\n$/.test(separator));
|
|
1488
|
-
|
|
1489
|
-
source.content.indent(indentStr, {
|
|
1490
|
-
exclude: source.indentExclusionRanges,
|
|
1491
|
-
indentStart, //: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
|
|
1492
|
-
});
|
|
1493
|
-
|
|
1494
|
-
trailingNewline = source.content.lastChar() === '\n';
|
|
1495
|
-
});
|
|
1496
|
-
|
|
1497
|
-
if (this.intro) {
|
|
1498
|
-
this.intro =
|
|
1499
|
-
indentStr +
|
|
1500
|
-
this.intro.replace(/^[^\n]/gm, (match, index) => {
|
|
1501
|
-
return index > 0 ? indentStr + match : match;
|
|
1502
|
-
});
|
|
1503
|
-
}
|
|
1504
|
-
|
|
1505
|
-
return this;
|
|
1506
|
-
}
|
|
1507
|
-
|
|
1508
|
-
prepend(str) {
|
|
1509
|
-
this.intro = str + this.intro;
|
|
1510
|
-
return this;
|
|
1511
|
-
}
|
|
1512
|
-
|
|
1513
|
-
toString() {
|
|
1514
|
-
const body = this.sources
|
|
1515
|
-
.map((source, i) => {
|
|
1516
|
-
const separator = source.separator !== undefined ? source.separator : this.separator;
|
|
1517
|
-
const str = (i > 0 ? separator : '') + source.content.toString();
|
|
1518
|
-
|
|
1519
|
-
return str;
|
|
1520
|
-
})
|
|
1521
|
-
.join('');
|
|
1522
|
-
|
|
1523
|
-
return this.intro + body;
|
|
1524
|
-
}
|
|
1525
|
-
|
|
1526
|
-
isEmpty() {
|
|
1527
|
-
if (this.intro.length && this.intro.trim()) return false;
|
|
1528
|
-
if (this.sources.some((source) => !source.content.isEmpty())) return false;
|
|
1529
|
-
return true;
|
|
1530
|
-
}
|
|
1531
|
-
|
|
1532
|
-
length() {
|
|
1533
|
-
return this.sources.reduce(
|
|
1534
|
-
(length, source) => length + source.content.length(),
|
|
1535
|
-
this.intro.length
|
|
1536
|
-
);
|
|
1537
|
-
}
|
|
1538
|
-
|
|
1539
|
-
trimLines() {
|
|
1540
|
-
return this.trim('[\\r\\n]');
|
|
1541
|
-
}
|
|
1542
|
-
|
|
1543
|
-
trim(charType) {
|
|
1544
|
-
return this.trimStart(charType).trimEnd(charType);
|
|
1545
|
-
}
|
|
1546
|
-
|
|
1547
|
-
trimStart(charType) {
|
|
1548
|
-
const rx = new RegExp('^' + (charType || '\\s') + '+');
|
|
1549
|
-
this.intro = this.intro.replace(rx, '');
|
|
1550
|
-
|
|
1551
|
-
if (!this.intro) {
|
|
1552
|
-
let source;
|
|
1553
|
-
let i = 0;
|
|
1554
|
-
|
|
1555
|
-
do {
|
|
1556
|
-
source = this.sources[i++];
|
|
1557
|
-
if (!source) {
|
|
1558
|
-
break;
|
|
1559
|
-
}
|
|
1560
|
-
} while (!source.content.trimStartAborted(charType));
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
return this;
|
|
1564
|
-
}
|
|
1565
|
-
|
|
1566
|
-
trimEnd(charType) {
|
|
1567
|
-
const rx = new RegExp((charType || '\\s') + '+$');
|
|
1568
|
-
|
|
1569
|
-
let source;
|
|
1570
|
-
let i = this.sources.length - 1;
|
|
1571
|
-
|
|
1572
|
-
do {
|
|
1573
|
-
source = this.sources[i--];
|
|
1574
|
-
if (!source) {
|
|
1575
|
-
this.intro = this.intro.replace(rx, '');
|
|
1576
|
-
break;
|
|
1577
|
-
}
|
|
1578
|
-
} while (!source.content.trimEndAborted(charType));
|
|
1579
|
-
|
|
1580
|
-
return this;
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
|
|
1584
|
-
var magicString_es = /*#__PURE__*/Object.freeze({
|
|
1585
|
-
__proto__: null,
|
|
1586
|
-
Bundle: Bundle,
|
|
1587
|
-
SourceMap: SourceMap,
|
|
1588
|
-
'default': MagicString
|
|
1589
|
-
});
|
|
1590
|
-
|
|
1591
|
-
export { MagicString as M, decode as d, encode as e, magicString_es as m };
|