jass-vue 0.2.1 → 0.3.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.
- checksums.yaml +4 -4
- data/lib/jass/vue/version.rb +1 -1
- data/lib/jass/vue.rb +1 -0
- data/vendor/node_modules/balanced-match/index.js +59 -0
- data/vendor/node_modules/balanced-match/package.json +49 -0
- data/vendor/node_modules/brace-expansion/index.js +201 -0
- data/vendor/node_modules/brace-expansion/package.json +47 -0
- data/vendor/node_modules/concat-map/index.js +13 -0
- data/vendor/node_modules/concat-map/package.json +43 -0
- data/vendor/node_modules/minimatch/minimatch.js +923 -0
- data/vendor/node_modules/minimatch/package.json +30 -0
- data/vendor/node_modules/rollup-plugin-replace/dist/rollup-plugin-replace.cjs.js +88 -0
- data/vendor/node_modules/rollup-plugin-replace/dist/rollup-plugin-replace.es.js +84 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/estree-walker/dist/estree-walker.es.js +57 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/estree-walker/dist/estree-walker.umd.js +68 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/estree-walker/index.d.ts +17 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/estree-walker/package.json +35 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/estree-walker/src/estree-walker.js +51 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/magic-string/dist/magic-string.cjs.js +1300 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/magic-string/dist/magic-string.es.js +1296 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/magic-string/dist/magic-string.umd.js +1352 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/magic-string/index.d.ts +83 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/magic-string/package.json +55 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/rollup-pluginutils/dist/pluginutils.cjs.js +302 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/rollup-pluginutils/dist/pluginutils.es.js +292 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/rollup-pluginutils/package.json +46 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/rollup-pluginutils/src/addExtension.js +6 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/rollup-pluginutils/src/attachScopes.js +155 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/rollup-pluginutils/src/createFilter.js +33 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/rollup-pluginutils/src/dataToEsm.js +69 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/rollup-pluginutils/src/index.js +5 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/rollup-pluginutils/src/makeLegalIdentifier.js +15 -0
- data/vendor/node_modules/rollup-plugin-replace/node_modules/rollup-pluginutils/src/utils/ensureArray.js +5 -0
- data/vendor/node_modules/rollup-plugin-replace/package.json +43 -0
- data/vendor/node_modules/rollup-plugin-replace/src/index.js +80 -0
- data/vendor/package.json +1 -0
- data/vendor/yarn.lock +47 -1
- metadata +36 -4
data/vendor/node_modules/rollup-plugin-replace/node_modules/magic-string/dist/magic-string.cjs.js
ADDED
@@ -0,0 +1,1300 @@
|
|
1
|
+
'use strict';
|
2
|
+
|
3
|
+
var vlq = require('vlq');
|
4
|
+
|
5
|
+
function Chunk ( start, end, content ) {
|
6
|
+
this.start = start;
|
7
|
+
this.end = end;
|
8
|
+
this.original = content;
|
9
|
+
|
10
|
+
this.intro = '';
|
11
|
+
this.outro = '';
|
12
|
+
|
13
|
+
this.content = content;
|
14
|
+
this.storeName = false;
|
15
|
+
this.edited = false;
|
16
|
+
|
17
|
+
// we make these non-enumerable, for sanity while debugging
|
18
|
+
Object.defineProperties( this, {
|
19
|
+
previous: { writable: true, value: null },
|
20
|
+
next: { writable: true, value: null }
|
21
|
+
});
|
22
|
+
}
|
23
|
+
|
24
|
+
Chunk.prototype = {
|
25
|
+
appendLeft: function appendLeft ( content ) {
|
26
|
+
this.outro += content;
|
27
|
+
},
|
28
|
+
|
29
|
+
appendRight: function appendRight ( content ) {
|
30
|
+
this.intro = this.intro + content;
|
31
|
+
},
|
32
|
+
|
33
|
+
clone: function clone () {
|
34
|
+
var chunk = new Chunk( this.start, this.end, this.original );
|
35
|
+
|
36
|
+
chunk.intro = this.intro;
|
37
|
+
chunk.outro = this.outro;
|
38
|
+
chunk.content = this.content;
|
39
|
+
chunk.storeName = this.storeName;
|
40
|
+
chunk.edited = this.edited;
|
41
|
+
|
42
|
+
return chunk;
|
43
|
+
},
|
44
|
+
|
45
|
+
contains: function contains ( index ) {
|
46
|
+
return this.start < index && index < this.end;
|
47
|
+
},
|
48
|
+
|
49
|
+
eachNext: function eachNext ( fn ) {
|
50
|
+
var chunk = this;
|
51
|
+
while ( chunk ) {
|
52
|
+
fn( chunk );
|
53
|
+
chunk = chunk.next;
|
54
|
+
}
|
55
|
+
},
|
56
|
+
|
57
|
+
eachPrevious: function eachPrevious ( fn ) {
|
58
|
+
var chunk = this;
|
59
|
+
while ( chunk ) {
|
60
|
+
fn( chunk );
|
61
|
+
chunk = chunk.previous;
|
62
|
+
}
|
63
|
+
},
|
64
|
+
|
65
|
+
edit: function edit ( content, storeName, contentOnly ) {
|
66
|
+
this.content = content;
|
67
|
+
if ( !contentOnly ) {
|
68
|
+
this.intro = '';
|
69
|
+
this.outro = '';
|
70
|
+
}
|
71
|
+
this.storeName = storeName;
|
72
|
+
|
73
|
+
this.edited = true;
|
74
|
+
|
75
|
+
return this;
|
76
|
+
},
|
77
|
+
|
78
|
+
prependLeft: function prependLeft ( content ) {
|
79
|
+
this.outro = content + this.outro;
|
80
|
+
},
|
81
|
+
|
82
|
+
prependRight: function prependRight ( content ) {
|
83
|
+
this.intro = content + this.intro;
|
84
|
+
},
|
85
|
+
|
86
|
+
split: function split ( index ) {
|
87
|
+
var sliceIndex = index - this.start;
|
88
|
+
|
89
|
+
var originalBefore = this.original.slice( 0, sliceIndex );
|
90
|
+
var originalAfter = this.original.slice( sliceIndex );
|
91
|
+
|
92
|
+
this.original = originalBefore;
|
93
|
+
|
94
|
+
var newChunk = new Chunk( index, this.end, originalAfter );
|
95
|
+
newChunk.outro = this.outro;
|
96
|
+
this.outro = '';
|
97
|
+
|
98
|
+
this.end = index;
|
99
|
+
|
100
|
+
if ( this.edited ) {
|
101
|
+
// TODO is this block necessary?...
|
102
|
+
newChunk.edit( '', false );
|
103
|
+
this.content = '';
|
104
|
+
} else {
|
105
|
+
this.content = originalBefore;
|
106
|
+
}
|
107
|
+
|
108
|
+
newChunk.next = this.next;
|
109
|
+
if ( newChunk.next ) { newChunk.next.previous = newChunk; }
|
110
|
+
newChunk.previous = this;
|
111
|
+
this.next = newChunk;
|
112
|
+
|
113
|
+
return newChunk;
|
114
|
+
},
|
115
|
+
|
116
|
+
toString: function toString () {
|
117
|
+
return this.intro + this.content + this.outro;
|
118
|
+
},
|
119
|
+
|
120
|
+
trimEnd: function trimEnd ( rx ) {
|
121
|
+
this.outro = this.outro.replace( rx, '' );
|
122
|
+
if ( this.outro.length ) { return true; }
|
123
|
+
|
124
|
+
var trimmed = this.content.replace( rx, '' );
|
125
|
+
|
126
|
+
if ( trimmed.length ) {
|
127
|
+
if ( trimmed !== this.content ) {
|
128
|
+
this.split( this.start + trimmed.length ).edit( '', false );
|
129
|
+
}
|
130
|
+
|
131
|
+
return true;
|
132
|
+
} else {
|
133
|
+
this.edit( '', false );
|
134
|
+
|
135
|
+
this.intro = this.intro.replace( rx, '' );
|
136
|
+
if ( this.intro.length ) { return true; }
|
137
|
+
}
|
138
|
+
},
|
139
|
+
|
140
|
+
trimStart: function trimStart ( rx ) {
|
141
|
+
this.intro = this.intro.replace( rx, '' );
|
142
|
+
if ( this.intro.length ) { return true; }
|
143
|
+
|
144
|
+
var trimmed = this.content.replace( rx, '' );
|
145
|
+
|
146
|
+
if ( trimmed.length ) {
|
147
|
+
if ( trimmed !== this.content ) {
|
148
|
+
this.split( this.end - trimmed.length );
|
149
|
+
this.edit( '', false );
|
150
|
+
}
|
151
|
+
|
152
|
+
return true;
|
153
|
+
} else {
|
154
|
+
this.edit( '', false );
|
155
|
+
|
156
|
+
this.outro = this.outro.replace( rx, '' );
|
157
|
+
if ( this.outro.length ) { return true; }
|
158
|
+
}
|
159
|
+
}
|
160
|
+
};
|
161
|
+
|
162
|
+
var _btoa;
|
163
|
+
|
164
|
+
if ( typeof window !== 'undefined' && typeof window.btoa === 'function' ) {
|
165
|
+
_btoa = window.btoa;
|
166
|
+
} else if ( typeof Buffer === 'function' ) {
|
167
|
+
_btoa = function (str) { return new Buffer( str ).toString( 'base64' ); };
|
168
|
+
} else {
|
169
|
+
_btoa = function () {
|
170
|
+
throw new Error( 'Unsupported environment: `window.btoa` or `Buffer` should be supported.' );
|
171
|
+
};
|
172
|
+
}
|
173
|
+
|
174
|
+
var btoa = _btoa;
|
175
|
+
|
176
|
+
function SourceMap ( properties ) {
|
177
|
+
this.version = 3;
|
178
|
+
|
179
|
+
this.file = properties.file;
|
180
|
+
this.sources = properties.sources;
|
181
|
+
this.sourcesContent = properties.sourcesContent;
|
182
|
+
this.names = properties.names;
|
183
|
+
this.mappings = properties.mappings;
|
184
|
+
}
|
185
|
+
|
186
|
+
SourceMap.prototype = {
|
187
|
+
toString: function toString () {
|
188
|
+
return JSON.stringify( this );
|
189
|
+
},
|
190
|
+
|
191
|
+
toUrl: function toUrl () {
|
192
|
+
return 'data:application/json;charset=utf-8;base64,' + btoa( this.toString() );
|
193
|
+
}
|
194
|
+
};
|
195
|
+
|
196
|
+
function guessIndent ( code ) {
|
197
|
+
var lines = code.split( '\n' );
|
198
|
+
|
199
|
+
var tabbed = lines.filter( function (line) { return /^\t+/.test( line ); } );
|
200
|
+
var spaced = lines.filter( function (line) { return /^ {2,}/.test( line ); } );
|
201
|
+
|
202
|
+
if ( tabbed.length === 0 && spaced.length === 0 ) {
|
203
|
+
return null;
|
204
|
+
}
|
205
|
+
|
206
|
+
// More lines tabbed than spaced? Assume tabs, and
|
207
|
+
// default to tabs in the case of a tie (or nothing
|
208
|
+
// to go on)
|
209
|
+
if ( tabbed.length >= spaced.length ) {
|
210
|
+
return '\t';
|
211
|
+
}
|
212
|
+
|
213
|
+
// Otherwise, we need to guess the multiple
|
214
|
+
var min = spaced.reduce( function ( previous, current ) {
|
215
|
+
var numSpaces = /^ +/.exec( current )[0].length;
|
216
|
+
return Math.min( numSpaces, previous );
|
217
|
+
}, Infinity );
|
218
|
+
|
219
|
+
return new Array( min + 1 ).join( ' ' );
|
220
|
+
}
|
221
|
+
|
222
|
+
function getRelativePath ( from, to ) {
|
223
|
+
var fromParts = from.split( /[\/\\]/ );
|
224
|
+
var toParts = to.split( /[\/\\]/ );
|
225
|
+
|
226
|
+
fromParts.pop(); // get dirname
|
227
|
+
|
228
|
+
while ( fromParts[0] === toParts[0] ) {
|
229
|
+
fromParts.shift();
|
230
|
+
toParts.shift();
|
231
|
+
}
|
232
|
+
|
233
|
+
if ( fromParts.length ) {
|
234
|
+
var i = fromParts.length;
|
235
|
+
while ( i-- ) { fromParts[i] = '..'; }
|
236
|
+
}
|
237
|
+
|
238
|
+
return fromParts.concat( toParts ).join( '/' );
|
239
|
+
}
|
240
|
+
|
241
|
+
var toString = Object.prototype.toString;
|
242
|
+
|
243
|
+
function isObject ( thing ) {
|
244
|
+
return toString.call( thing ) === '[object Object]';
|
245
|
+
}
|
246
|
+
|
247
|
+
function getLocator ( source ) {
|
248
|
+
var originalLines = source.split( '\n' );
|
249
|
+
|
250
|
+
var start = 0;
|
251
|
+
var lineRanges = originalLines.map( function ( line, i ) {
|
252
|
+
var end = start + line.length + 1;
|
253
|
+
var range = { start: start, end: end, line: i };
|
254
|
+
|
255
|
+
start = end;
|
256
|
+
return range;
|
257
|
+
});
|
258
|
+
|
259
|
+
var i = 0;
|
260
|
+
|
261
|
+
function rangeContains ( range, index ) {
|
262
|
+
return range.start <= index && index < range.end;
|
263
|
+
}
|
264
|
+
|
265
|
+
function getLocation ( range, index ) {
|
266
|
+
return { line: range.line, column: index - range.start };
|
267
|
+
}
|
268
|
+
|
269
|
+
return function locate ( index ) {
|
270
|
+
var range = lineRanges[i];
|
271
|
+
|
272
|
+
var d = index >= range.end ? 1 : -1;
|
273
|
+
|
274
|
+
while ( range ) {
|
275
|
+
if ( rangeContains( range, index ) ) { return getLocation( range, index ); }
|
276
|
+
|
277
|
+
i += d;
|
278
|
+
range = lineRanges[i];
|
279
|
+
}
|
280
|
+
};
|
281
|
+
}
|
282
|
+
|
283
|
+
function Mappings ( hires ) {
|
284
|
+
var this$1 = this;
|
285
|
+
|
286
|
+
var offsets = {
|
287
|
+
generatedCodeColumn: 0,
|
288
|
+
sourceIndex: 0,
|
289
|
+
sourceCodeLine: 0,
|
290
|
+
sourceCodeColumn: 0,
|
291
|
+
sourceCodeName: 0
|
292
|
+
};
|
293
|
+
|
294
|
+
var generatedCodeLine = 0;
|
295
|
+
var generatedCodeColumn = 0;
|
296
|
+
|
297
|
+
this.raw = [];
|
298
|
+
var rawSegments = this.raw[ generatedCodeLine ] = [];
|
299
|
+
|
300
|
+
var pending = null;
|
301
|
+
|
302
|
+
this.addEdit = function ( sourceIndex, content, original, loc, nameIndex ) {
|
303
|
+
if ( content.length ) {
|
304
|
+
rawSegments.push([
|
305
|
+
generatedCodeColumn,
|
306
|
+
sourceIndex,
|
307
|
+
loc.line,
|
308
|
+
loc.column,
|
309
|
+
nameIndex ]);
|
310
|
+
} else if ( pending ) {
|
311
|
+
rawSegments.push( pending );
|
312
|
+
}
|
313
|
+
|
314
|
+
this$1.advance( content );
|
315
|
+
pending = null;
|
316
|
+
};
|
317
|
+
|
318
|
+
this.addUneditedChunk = function ( sourceIndex, chunk, original, loc, sourcemapLocations ) {
|
319
|
+
var originalCharIndex = chunk.start;
|
320
|
+
var first = true;
|
321
|
+
|
322
|
+
while ( originalCharIndex < chunk.end ) {
|
323
|
+
if ( hires || first || sourcemapLocations[ originalCharIndex ] ) {
|
324
|
+
rawSegments.push([
|
325
|
+
generatedCodeColumn,
|
326
|
+
sourceIndex,
|
327
|
+
loc.line,
|
328
|
+
loc.column,
|
329
|
+
-1
|
330
|
+
]);
|
331
|
+
}
|
332
|
+
|
333
|
+
if ( original[ originalCharIndex ] === '\n' ) {
|
334
|
+
loc.line += 1;
|
335
|
+
loc.column = 0;
|
336
|
+
generatedCodeLine += 1;
|
337
|
+
this$1.raw[ generatedCodeLine ] = rawSegments = [];
|
338
|
+
generatedCodeColumn = 0;
|
339
|
+
} else {
|
340
|
+
loc.column += 1;
|
341
|
+
generatedCodeColumn += 1;
|
342
|
+
}
|
343
|
+
|
344
|
+
originalCharIndex += 1;
|
345
|
+
first = false;
|
346
|
+
}
|
347
|
+
|
348
|
+
pending = [
|
349
|
+
generatedCodeColumn,
|
350
|
+
sourceIndex,
|
351
|
+
loc.line,
|
352
|
+
loc.column,
|
353
|
+
-1 ];
|
354
|
+
};
|
355
|
+
|
356
|
+
this.advance = function (str) {
|
357
|
+
if ( !str ) { return; }
|
358
|
+
|
359
|
+
var lines = str.split( '\n' );
|
360
|
+
var lastLine = lines.pop();
|
361
|
+
|
362
|
+
if ( lines.length ) {
|
363
|
+
generatedCodeLine += lines.length;
|
364
|
+
this$1.raw[ generatedCodeLine ] = rawSegments = [];
|
365
|
+
generatedCodeColumn = lastLine.length;
|
366
|
+
} else {
|
367
|
+
generatedCodeColumn += lastLine.length;
|
368
|
+
}
|
369
|
+
};
|
370
|
+
|
371
|
+
this.encode = function () {
|
372
|
+
return this$1.raw.map( function (segments) {
|
373
|
+
var generatedCodeColumn = 0;
|
374
|
+
|
375
|
+
return segments.map( function (segment) {
|
376
|
+
var arr = [
|
377
|
+
segment[0] - generatedCodeColumn,
|
378
|
+
segment[1] - offsets.sourceIndex,
|
379
|
+
segment[2] - offsets.sourceCodeLine,
|
380
|
+
segment[3] - offsets.sourceCodeColumn
|
381
|
+
];
|
382
|
+
|
383
|
+
generatedCodeColumn = segment[0];
|
384
|
+
offsets.sourceIndex = segment[1];
|
385
|
+
offsets.sourceCodeLine = segment[2];
|
386
|
+
offsets.sourceCodeColumn = segment[3];
|
387
|
+
|
388
|
+
if ( ~segment[4] ) {
|
389
|
+
arr.push( segment[4] - offsets.sourceCodeName );
|
390
|
+
offsets.sourceCodeName = segment[4];
|
391
|
+
}
|
392
|
+
|
393
|
+
return vlq.encode( arr );
|
394
|
+
}).join( ',' );
|
395
|
+
}).join( ';' );
|
396
|
+
};
|
397
|
+
}
|
398
|
+
|
399
|
+
var Stats = function Stats () {
|
400
|
+
Object.defineProperties( this, {
|
401
|
+
startTimes: { value: {} }
|
402
|
+
});
|
403
|
+
};
|
404
|
+
|
405
|
+
Stats.prototype.time = function time ( label ) {
|
406
|
+
this.startTimes[ label ] = process.hrtime();
|
407
|
+
};
|
408
|
+
|
409
|
+
Stats.prototype.timeEnd = function timeEnd ( label ) {
|
410
|
+
var elapsed = process.hrtime( this.startTimes[ label ] );
|
411
|
+
|
412
|
+
if ( !this[ label ] ) { this[ label ] = 0; }
|
413
|
+
this[ label ] += elapsed[0] * 1e3 + elapsed[1] * 1e-6;
|
414
|
+
};
|
415
|
+
|
416
|
+
var warned = {
|
417
|
+
insertLeft: false,
|
418
|
+
insertRight: false,
|
419
|
+
storeName: false
|
420
|
+
};
|
421
|
+
|
422
|
+
function MagicString$1 ( string, options ) {
|
423
|
+
if ( options === void 0 ) options = {};
|
424
|
+
|
425
|
+
var chunk = new Chunk( 0, string.length, string );
|
426
|
+
|
427
|
+
Object.defineProperties( this, {
|
428
|
+
original: { writable: true, value: string },
|
429
|
+
outro: { writable: true, value: '' },
|
430
|
+
intro: { writable: true, value: '' },
|
431
|
+
firstChunk: { writable: true, value: chunk },
|
432
|
+
lastChunk: { writable: true, value: chunk },
|
433
|
+
lastSearchedChunk: { writable: true, value: chunk },
|
434
|
+
byStart: { writable: true, value: {} },
|
435
|
+
byEnd: { writable: true, value: {} },
|
436
|
+
filename: { writable: true, value: options.filename },
|
437
|
+
indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
438
|
+
sourcemapLocations: { writable: true, value: {} },
|
439
|
+
storedNames: { writable: true, value: {} },
|
440
|
+
indentStr: { writable: true, value: guessIndent( string ) }
|
441
|
+
});
|
442
|
+
|
443
|
+
this.byStart[ 0 ] = chunk;
|
444
|
+
this.byEnd[ string.length ] = chunk;
|
445
|
+
}
|
446
|
+
|
447
|
+
MagicString$1.prototype = {
|
448
|
+
addSourcemapLocation: function addSourcemapLocation ( char ) {
|
449
|
+
this.sourcemapLocations[ char ] = true;
|
450
|
+
},
|
451
|
+
|
452
|
+
append: function append ( content ) {
|
453
|
+
if ( typeof content !== 'string' ) { throw new TypeError( 'outro content must be a string' ); }
|
454
|
+
|
455
|
+
this.outro += content;
|
456
|
+
return this;
|
457
|
+
},
|
458
|
+
|
459
|
+
appendLeft: function appendLeft ( index, content ) {
|
460
|
+
if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
|
461
|
+
|
462
|
+
this._split( index );
|
463
|
+
|
464
|
+
var chunk = this.byEnd[ index ];
|
465
|
+
|
466
|
+
if ( chunk ) {
|
467
|
+
chunk.appendLeft( content );
|
468
|
+
} else {
|
469
|
+
this.intro += content;
|
470
|
+
}
|
471
|
+
|
472
|
+
return this;
|
473
|
+
},
|
474
|
+
|
475
|
+
appendRight: function appendRight ( index, content ) {
|
476
|
+
if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
|
477
|
+
|
478
|
+
this._split( index );
|
479
|
+
|
480
|
+
var chunk = this.byStart[ index ];
|
481
|
+
|
482
|
+
if ( chunk ) {
|
483
|
+
chunk.appendRight( content );
|
484
|
+
} else {
|
485
|
+
this.outro += content;
|
486
|
+
}
|
487
|
+
|
488
|
+
return this;
|
489
|
+
},
|
490
|
+
|
491
|
+
clone: function clone () {
|
492
|
+
var cloned = new MagicString$1( this.original, { filename: this.filename });
|
493
|
+
|
494
|
+
var originalChunk = this.firstChunk;
|
495
|
+
var clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
|
496
|
+
|
497
|
+
while ( originalChunk ) {
|
498
|
+
cloned.byStart[ clonedChunk.start ] = clonedChunk;
|
499
|
+
cloned.byEnd[ clonedChunk.end ] = clonedChunk;
|
500
|
+
|
501
|
+
var nextOriginalChunk = originalChunk.next;
|
502
|
+
var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
503
|
+
|
504
|
+
if ( nextClonedChunk ) {
|
505
|
+
clonedChunk.next = nextClonedChunk;
|
506
|
+
nextClonedChunk.previous = clonedChunk;
|
507
|
+
|
508
|
+
clonedChunk = nextClonedChunk;
|
509
|
+
}
|
510
|
+
|
511
|
+
originalChunk = nextOriginalChunk;
|
512
|
+
}
|
513
|
+
|
514
|
+
cloned.lastChunk = clonedChunk;
|
515
|
+
|
516
|
+
if ( this.indentExclusionRanges ) {
|
517
|
+
cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
518
|
+
}
|
519
|
+
|
520
|
+
Object.keys( this.sourcemapLocations ).forEach( function (loc) {
|
521
|
+
cloned.sourcemapLocations[ loc ] = true;
|
522
|
+
});
|
523
|
+
|
524
|
+
return cloned;
|
525
|
+
},
|
526
|
+
|
527
|
+
generateMap: function generateMap ( options ) {
|
528
|
+
var this$1 = this;
|
529
|
+
|
530
|
+
options = options || {};
|
531
|
+
|
532
|
+
var sourceIndex = 0;
|
533
|
+
var names = Object.keys( this.storedNames );
|
534
|
+
var mappings = new Mappings( options.hires );
|
535
|
+
|
536
|
+
var locate = getLocator( this.original );
|
537
|
+
|
538
|
+
if ( this.intro ) {
|
539
|
+
mappings.advance( this.intro );
|
540
|
+
}
|
541
|
+
|
542
|
+
this.firstChunk.eachNext( function (chunk) {
|
543
|
+
var loc = locate( chunk.start );
|
544
|
+
|
545
|
+
if ( chunk.intro.length ) { mappings.advance( chunk.intro ); }
|
546
|
+
|
547
|
+
if ( chunk.edited ) {
|
548
|
+
mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
|
549
|
+
} else {
|
550
|
+
mappings.addUneditedChunk( sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations );
|
551
|
+
}
|
552
|
+
|
553
|
+
if ( chunk.outro.length ) { mappings.advance( chunk.outro ); }
|
554
|
+
});
|
555
|
+
|
556
|
+
var map = new SourceMap({
|
557
|
+
file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
|
558
|
+
sources: [ options.source ? getRelativePath( options.file || '', options.source ) : null ],
|
559
|
+
sourcesContent: options.includeContent ? [ this.original ] : [ null ],
|
560
|
+
names: names,
|
561
|
+
mappings: mappings.encode()
|
562
|
+
});
|
563
|
+
return map;
|
564
|
+
},
|
565
|
+
|
566
|
+
getIndentString: function getIndentString () {
|
567
|
+
return this.indentStr === null ? '\t' : this.indentStr;
|
568
|
+
},
|
569
|
+
|
570
|
+
indent: function indent ( indentStr, options ) {
|
571
|
+
var this$1 = this;
|
572
|
+
|
573
|
+
var pattern = /^[^\r\n]/gm;
|
574
|
+
|
575
|
+
if ( isObject( indentStr ) ) {
|
576
|
+
options = indentStr;
|
577
|
+
indentStr = undefined;
|
578
|
+
}
|
579
|
+
|
580
|
+
indentStr = indentStr !== undefined ? indentStr : ( this.indentStr || '\t' );
|
581
|
+
|
582
|
+
if ( indentStr === '' ) { return this; } // noop
|
583
|
+
|
584
|
+
options = options || {};
|
585
|
+
|
586
|
+
// Process exclusion ranges
|
587
|
+
var isExcluded = {};
|
588
|
+
|
589
|
+
if ( options.exclude ) {
|
590
|
+
var exclusions = typeof options.exclude[0] === 'number' ? [ options.exclude ] : options.exclude;
|
591
|
+
exclusions.forEach( function (exclusion) {
|
592
|
+
for ( var i = exclusion[0]; i < exclusion[1]; i += 1 ) {
|
593
|
+
isExcluded[i] = true;
|
594
|
+
}
|
595
|
+
});
|
596
|
+
}
|
597
|
+
|
598
|
+
var shouldIndentNextCharacter = options.indentStart !== false;
|
599
|
+
var replacer = function (match) {
|
600
|
+
if ( shouldIndentNextCharacter ) { return ("" + indentStr + match); }
|
601
|
+
shouldIndentNextCharacter = true;
|
602
|
+
return match;
|
603
|
+
};
|
604
|
+
|
605
|
+
this.intro = this.intro.replace( pattern, replacer );
|
606
|
+
|
607
|
+
var charIndex = 0;
|
608
|
+
|
609
|
+
var chunk = this.firstChunk;
|
610
|
+
|
611
|
+
while ( chunk ) {
|
612
|
+
var end = chunk.end;
|
613
|
+
|
614
|
+
if ( chunk.edited ) {
|
615
|
+
if ( !isExcluded[ charIndex ] ) {
|
616
|
+
chunk.content = chunk.content.replace( pattern, replacer );
|
617
|
+
|
618
|
+
if ( chunk.content.length ) {
|
619
|
+
shouldIndentNextCharacter = chunk.content[ chunk.content.length - 1 ] === '\n';
|
620
|
+
}
|
621
|
+
}
|
622
|
+
} else {
|
623
|
+
charIndex = chunk.start;
|
624
|
+
|
625
|
+
while ( charIndex < end ) {
|
626
|
+
if ( !isExcluded[ charIndex ] ) {
|
627
|
+
var char = this$1.original[ charIndex ];
|
628
|
+
|
629
|
+
if ( char === '\n' ) {
|
630
|
+
shouldIndentNextCharacter = true;
|
631
|
+
} else if ( char !== '\r' && shouldIndentNextCharacter ) {
|
632
|
+
shouldIndentNextCharacter = false;
|
633
|
+
|
634
|
+
if ( charIndex === chunk.start ) {
|
635
|
+
chunk.prependRight( indentStr );
|
636
|
+
} else {
|
637
|
+
this$1._splitChunk( chunk, charIndex );
|
638
|
+
chunk = chunk.next;
|
639
|
+
chunk.prependRight( indentStr );
|
640
|
+
}
|
641
|
+
}
|
642
|
+
}
|
643
|
+
|
644
|
+
charIndex += 1;
|
645
|
+
}
|
646
|
+
}
|
647
|
+
|
648
|
+
charIndex = chunk.end;
|
649
|
+
chunk = chunk.next;
|
650
|
+
}
|
651
|
+
|
652
|
+
this.outro = this.outro.replace( pattern, replacer );
|
653
|
+
|
654
|
+
return this;
|
655
|
+
},
|
656
|
+
|
657
|
+
insert: function insert () {
|
658
|
+
throw new Error( 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)' );
|
659
|
+
},
|
660
|
+
|
661
|
+
insertLeft: function insertLeft ( index, content ) {
|
662
|
+
if ( !warned.insertLeft ) {
|
663
|
+
console.warn( 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead' ); // eslint-disable-line no-console
|
664
|
+
warned.insertLeft = true;
|
665
|
+
}
|
666
|
+
|
667
|
+
return this.appendLeft( index, content );
|
668
|
+
},
|
669
|
+
|
670
|
+
insertRight: function insertRight ( index, content ) {
|
671
|
+
if ( !warned.insertRight ) {
|
672
|
+
console.warn( 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead' ); // eslint-disable-line no-console
|
673
|
+
warned.insertRight = true;
|
674
|
+
}
|
675
|
+
|
676
|
+
return this.prependRight( index, content );
|
677
|
+
},
|
678
|
+
|
679
|
+
move: function move ( start, end, index ) {
|
680
|
+
if ( index >= start && index <= end ) { throw new Error( 'Cannot move a selection inside itself' ); }
|
681
|
+
|
682
|
+
this._split( start );
|
683
|
+
this._split( end );
|
684
|
+
this._split( index );
|
685
|
+
|
686
|
+
var first = this.byStart[ start ];
|
687
|
+
var last = this.byEnd[ end ];
|
688
|
+
|
689
|
+
var oldLeft = first.previous;
|
690
|
+
var oldRight = last.next;
|
691
|
+
|
692
|
+
var newRight = this.byStart[ index ];
|
693
|
+
if ( !newRight && last === this.lastChunk ) { return this; }
|
694
|
+
var newLeft = newRight ? newRight.previous : this.lastChunk;
|
695
|
+
|
696
|
+
if ( oldLeft ) { oldLeft.next = oldRight; }
|
697
|
+
if ( oldRight ) { oldRight.previous = oldLeft; }
|
698
|
+
|
699
|
+
if ( newLeft ) { newLeft.next = first; }
|
700
|
+
if ( newRight ) { newRight.previous = last; }
|
701
|
+
|
702
|
+
if ( !first.previous ) { this.firstChunk = last.next; }
|
703
|
+
if ( !last.next ) {
|
704
|
+
this.lastChunk = first.previous;
|
705
|
+
this.lastChunk.next = null;
|
706
|
+
}
|
707
|
+
|
708
|
+
first.previous = newLeft;
|
709
|
+
last.next = newRight || null;
|
710
|
+
|
711
|
+
if ( !newLeft ) { this.firstChunk = first; }
|
712
|
+
if ( !newRight ) { this.lastChunk = last; }
|
713
|
+
|
714
|
+
return this;
|
715
|
+
},
|
716
|
+
|
717
|
+
overwrite: function overwrite ( start, end, content, options ) {
|
718
|
+
var this$1 = this;
|
719
|
+
|
720
|
+
if ( typeof content !== 'string' ) { throw new TypeError( 'replacement content must be a string' ); }
|
721
|
+
|
722
|
+
while ( start < 0 ) { start += this$1.original.length; }
|
723
|
+
while ( end < 0 ) { end += this$1.original.length; }
|
724
|
+
|
725
|
+
if ( end > this.original.length ) { throw new Error( 'end is out of bounds' ); }
|
726
|
+
if ( start === end ) { throw new Error( 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead' ); }
|
727
|
+
|
728
|
+
this._split( start );
|
729
|
+
this._split( end );
|
730
|
+
|
731
|
+
if ( options === true ) {
|
732
|
+
if ( !warned.storeName ) {
|
733
|
+
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
|
734
|
+
warned.storeName = true;
|
735
|
+
}
|
736
|
+
|
737
|
+
options = { storeName: true };
|
738
|
+
}
|
739
|
+
var storeName = options !== undefined ? options.storeName : false;
|
740
|
+
var contentOnly = options !== undefined ? options.contentOnly : false;
|
741
|
+
|
742
|
+
if ( storeName ) {
|
743
|
+
var original = this.original.slice( start, end );
|
744
|
+
this.storedNames[ original ] = true;
|
745
|
+
}
|
746
|
+
|
747
|
+
var first = this.byStart[ start ];
|
748
|
+
var last = this.byEnd[ end ];
|
749
|
+
|
750
|
+
if ( first ) {
|
751
|
+
if ( end > first.end && first.next !== this.byStart[ first.end ] ) {
|
752
|
+
throw new Error( 'Cannot overwrite across a split point' );
|
753
|
+
}
|
754
|
+
|
755
|
+
first.edit( content, storeName, contentOnly );
|
756
|
+
|
757
|
+
if ( first !== last ) {
|
758
|
+
var chunk = first.next;
|
759
|
+
while ( chunk !== last ) {
|
760
|
+
chunk.edit( '', false );
|
761
|
+
chunk = chunk.next;
|
762
|
+
}
|
763
|
+
|
764
|
+
chunk.edit( '', false );
|
765
|
+
}
|
766
|
+
}
|
767
|
+
|
768
|
+
else {
|
769
|
+
// must be inserting at the end
|
770
|
+
var newChunk = new Chunk( start, end, '' ).edit( content, storeName );
|
771
|
+
|
772
|
+
// TODO last chunk in the array may not be the last chunk, if it's moved...
|
773
|
+
last.next = newChunk;
|
774
|
+
newChunk.previous = last;
|
775
|
+
}
|
776
|
+
|
777
|
+
return this;
|
778
|
+
},
|
779
|
+
|
780
|
+
prepend: function prepend ( content ) {
|
781
|
+
if ( typeof content !== 'string' ) { throw new TypeError( 'outro content must be a string' ); }
|
782
|
+
|
783
|
+
this.intro = content + this.intro;
|
784
|
+
return this;
|
785
|
+
},
|
786
|
+
|
787
|
+
prependLeft: function prependLeft ( index, content ) {
|
788
|
+
if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
|
789
|
+
|
790
|
+
this._split( index );
|
791
|
+
|
792
|
+
var chunk = this.byEnd[ index ];
|
793
|
+
|
794
|
+
if ( chunk ) {
|
795
|
+
chunk.prependLeft( content );
|
796
|
+
} else {
|
797
|
+
this.intro = content + this.intro;
|
798
|
+
}
|
799
|
+
|
800
|
+
return this;
|
801
|
+
},
|
802
|
+
|
803
|
+
prependRight: function prependRight ( index, content ) {
|
804
|
+
if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
|
805
|
+
|
806
|
+
this._split( index );
|
807
|
+
|
808
|
+
var chunk = this.byStart[ index ];
|
809
|
+
|
810
|
+
if ( chunk ) {
|
811
|
+
chunk.prependRight( content );
|
812
|
+
} else {
|
813
|
+
this.outro = content + this.outro;
|
814
|
+
}
|
815
|
+
|
816
|
+
return this;
|
817
|
+
},
|
818
|
+
|
819
|
+
remove: function remove ( start, end ) {
|
820
|
+
var this$1 = this;
|
821
|
+
|
822
|
+
while ( start < 0 ) { start += this$1.original.length; }
|
823
|
+
while ( end < 0 ) { end += this$1.original.length; }
|
824
|
+
|
825
|
+
if ( start === end ) { return this; }
|
826
|
+
|
827
|
+
if ( start < 0 || end > this.original.length ) { throw new Error( 'Character is out of bounds' ); }
|
828
|
+
if ( start > end ) { throw new Error( 'end must be greater than start' ); }
|
829
|
+
|
830
|
+
this._split( start );
|
831
|
+
this._split( end );
|
832
|
+
|
833
|
+
var chunk = this.byStart[ start ];
|
834
|
+
|
835
|
+
while ( chunk ) {
|
836
|
+
chunk.intro = '';
|
837
|
+
chunk.outro = '';
|
838
|
+
chunk.edit( '' );
|
839
|
+
|
840
|
+
chunk = end > chunk.end ? this$1.byStart[ chunk.end ] : null;
|
841
|
+
}
|
842
|
+
|
843
|
+
return this;
|
844
|
+
},
|
845
|
+
|
846
|
+
slice: function slice ( start, end ) {
|
847
|
+
var this$1 = this;
|
848
|
+
if ( start === void 0 ) start = 0;
|
849
|
+
if ( end === void 0 ) end = this.original.length;
|
850
|
+
|
851
|
+
while ( start < 0 ) { start += this$1.original.length; }
|
852
|
+
while ( end < 0 ) { end += this$1.original.length; }
|
853
|
+
|
854
|
+
var result = '';
|
855
|
+
|
856
|
+
// find start chunk
|
857
|
+
var chunk = this.firstChunk;
|
858
|
+
while ( chunk && ( chunk.start > start || chunk.end <= start ) ) {
|
859
|
+
|
860
|
+
// found end chunk before start
|
861
|
+
if ( chunk.start < end && chunk.end >= end ) {
|
862
|
+
return result;
|
863
|
+
}
|
864
|
+
|
865
|
+
chunk = chunk.next;
|
866
|
+
}
|
867
|
+
|
868
|
+
if ( chunk && chunk.edited && chunk.start !== start ) { throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
|
869
|
+
|
870
|
+
var startChunk = chunk;
|
871
|
+
while ( chunk ) {
|
872
|
+
if ( chunk.intro && ( startChunk !== chunk || chunk.start === start ) ) {
|
873
|
+
result += chunk.intro;
|
874
|
+
}
|
875
|
+
|
876
|
+
var containsEnd = chunk.start < end && chunk.end >= end;
|
877
|
+
if ( containsEnd && chunk.edited && chunk.end !== end ) { throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
|
878
|
+
|
879
|
+
var sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
880
|
+
var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
881
|
+
|
882
|
+
result += chunk.content.slice( sliceStart, sliceEnd );
|
883
|
+
|
884
|
+
if ( chunk.outro && ( !containsEnd || chunk.end === end ) ) {
|
885
|
+
result += chunk.outro;
|
886
|
+
}
|
887
|
+
|
888
|
+
if ( containsEnd ) {
|
889
|
+
break;
|
890
|
+
}
|
891
|
+
|
892
|
+
chunk = chunk.next;
|
893
|
+
}
|
894
|
+
|
895
|
+
return result;
|
896
|
+
},
|
897
|
+
|
898
|
+
// TODO deprecate this? not really very useful
|
899
|
+
snip: function snip ( start, end ) {
|
900
|
+
var clone = this.clone();
|
901
|
+
clone.remove( 0, start );
|
902
|
+
clone.remove( end, clone.original.length );
|
903
|
+
|
904
|
+
return clone;
|
905
|
+
},
|
906
|
+
|
907
|
+
_split: function _split ( index ) {
|
908
|
+
var this$1 = this;
|
909
|
+
|
910
|
+
if ( this.byStart[ index ] || this.byEnd[ index ] ) { return; }
|
911
|
+
|
912
|
+
var chunk = this.lastSearchedChunk;
|
913
|
+
var searchForward = index > chunk.end;
|
914
|
+
|
915
|
+
while ( true ) {
|
916
|
+
if ( chunk.contains( index ) ) { return this$1._splitChunk( chunk, index ); }
|
917
|
+
|
918
|
+
chunk = searchForward ?
|
919
|
+
this$1.byStart[ chunk.end ] :
|
920
|
+
this$1.byEnd[ chunk.start ];
|
921
|
+
}
|
922
|
+
},
|
923
|
+
|
924
|
+
_splitChunk: function _splitChunk ( chunk, index ) {
|
925
|
+
if ( chunk.edited && chunk.content.length ) { // zero-length edited chunks are a special case (overlapping replacements)
|
926
|
+
var loc = getLocator( this.original )( index );
|
927
|
+
throw new Error( ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")") );
|
928
|
+
}
|
929
|
+
|
930
|
+
var newChunk = chunk.split( index );
|
931
|
+
|
932
|
+
this.byEnd[ index ] = chunk;
|
933
|
+
this.byStart[ index ] = newChunk;
|
934
|
+
this.byEnd[ newChunk.end ] = newChunk;
|
935
|
+
|
936
|
+
if ( chunk === this.lastChunk ) { this.lastChunk = newChunk; }
|
937
|
+
|
938
|
+
this.lastSearchedChunk = chunk;
|
939
|
+
return true;
|
940
|
+
},
|
941
|
+
|
942
|
+
toString: function toString () {
|
943
|
+
var str = this.intro;
|
944
|
+
|
945
|
+
var chunk = this.firstChunk;
|
946
|
+
while ( chunk ) {
|
947
|
+
str += chunk.toString();
|
948
|
+
chunk = chunk.next;
|
949
|
+
}
|
950
|
+
|
951
|
+
return str + this.outro;
|
952
|
+
},
|
953
|
+
|
954
|
+
trimLines: function trimLines () {
|
955
|
+
return this.trim('[\\r\\n]');
|
956
|
+
},
|
957
|
+
|
958
|
+
trim: function trim ( charType ) {
|
959
|
+
return this.trimStart( charType ).trimEnd( charType );
|
960
|
+
},
|
961
|
+
|
962
|
+
trimEnd: function trimEnd ( charType ) {
|
963
|
+
var this$1 = this;
|
964
|
+
|
965
|
+
var rx = new RegExp( ( charType || '\\s' ) + '+$' );
|
966
|
+
|
967
|
+
this.outro = this.outro.replace( rx, '' );
|
968
|
+
if ( this.outro.length ) { return this; }
|
969
|
+
|
970
|
+
var chunk = this.lastChunk;
|
971
|
+
|
972
|
+
do {
|
973
|
+
var end = chunk.end;
|
974
|
+
var aborted = chunk.trimEnd( rx );
|
975
|
+
|
976
|
+
// if chunk was trimmed, we have a new lastChunk
|
977
|
+
if ( chunk.end !== end ) {
|
978
|
+
if ( this$1.lastChunk === chunk ) {
|
979
|
+
this$1.lastChunk = chunk.next;
|
980
|
+
}
|
981
|
+
|
982
|
+
this$1.byEnd[ chunk.end ] = chunk;
|
983
|
+
this$1.byStart[ chunk.next.start ] = chunk.next;
|
984
|
+
this$1.byEnd[ chunk.next.end ] = chunk.next;
|
985
|
+
}
|
986
|
+
|
987
|
+
if ( aborted ) { return this$1; }
|
988
|
+
chunk = chunk.previous;
|
989
|
+
} while ( chunk );
|
990
|
+
|
991
|
+
return this;
|
992
|
+
},
|
993
|
+
|
994
|
+
trimStart: function trimStart ( charType ) {
|
995
|
+
var this$1 = this;
|
996
|
+
|
997
|
+
var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
|
998
|
+
|
999
|
+
this.intro = this.intro.replace( rx, '' );
|
1000
|
+
if ( this.intro.length ) { return this; }
|
1001
|
+
|
1002
|
+
var chunk = this.firstChunk;
|
1003
|
+
|
1004
|
+
do {
|
1005
|
+
var end = chunk.end;
|
1006
|
+
var aborted = chunk.trimStart( rx );
|
1007
|
+
|
1008
|
+
if ( chunk.end !== end ) {
|
1009
|
+
// special case...
|
1010
|
+
if ( chunk === this$1.lastChunk ) { this$1.lastChunk = chunk.next; }
|
1011
|
+
|
1012
|
+
this$1.byEnd[ chunk.end ] = chunk;
|
1013
|
+
this$1.byStart[ chunk.next.start ] = chunk.next;
|
1014
|
+
this$1.byEnd[ chunk.next.end ] = chunk.next;
|
1015
|
+
}
|
1016
|
+
|
1017
|
+
if ( aborted ) { return this$1; }
|
1018
|
+
chunk = chunk.next;
|
1019
|
+
} while ( chunk );
|
1020
|
+
|
1021
|
+
return this;
|
1022
|
+
}
|
1023
|
+
};
|
1024
|
+
|
1025
|
+
var hasOwnProp = Object.prototype.hasOwnProperty;
|
1026
|
+
|
1027
|
+
function Bundle ( options ) {
|
1028
|
+
if ( options === void 0 ) options = {};
|
1029
|
+
|
1030
|
+
this.intro = options.intro || '';
|
1031
|
+
this.separator = options.separator !== undefined ? options.separator : '\n';
|
1032
|
+
|
1033
|
+
this.sources = [];
|
1034
|
+
|
1035
|
+
this.uniqueSources = [];
|
1036
|
+
this.uniqueSourceIndexByFilename = {};
|
1037
|
+
}
|
1038
|
+
|
1039
|
+
Bundle.prototype = {
|
1040
|
+
addSource: function addSource ( source ) {
|
1041
|
+
if ( source instanceof MagicString$1 ) {
|
1042
|
+
return this.addSource({
|
1043
|
+
content: source,
|
1044
|
+
filename: source.filename,
|
1045
|
+
separator: this.separator
|
1046
|
+
});
|
1047
|
+
}
|
1048
|
+
|
1049
|
+
if ( !isObject( source ) || !source.content ) {
|
1050
|
+
throw new Error( 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`' );
|
1051
|
+
}
|
1052
|
+
|
1053
|
+
[ 'filename', 'indentExclusionRanges', 'separator' ].forEach( function (option) {
|
1054
|
+
if ( !hasOwnProp.call( source, option ) ) { source[ option ] = source.content[ option ]; }
|
1055
|
+
});
|
1056
|
+
|
1057
|
+
if ( source.separator === undefined ) { // TODO there's a bunch of this sort of thing, needs cleaning up
|
1058
|
+
source.separator = this.separator;
|
1059
|
+
}
|
1060
|
+
|
1061
|
+
if ( source.filename ) {
|
1062
|
+
if ( !hasOwnProp.call( this.uniqueSourceIndexByFilename, source.filename ) ) {
|
1063
|
+
this.uniqueSourceIndexByFilename[ source.filename ] = this.uniqueSources.length;
|
1064
|
+
this.uniqueSources.push({ filename: source.filename, content: source.content.original });
|
1065
|
+
} else {
|
1066
|
+
var uniqueSource = this.uniqueSources[ this.uniqueSourceIndexByFilename[ source.filename ] ];
|
1067
|
+
if ( source.content.original !== uniqueSource.content ) {
|
1068
|
+
throw new Error( ("Illegal source: same filename (" + (source.filename) + "), different contents") );
|
1069
|
+
}
|
1070
|
+
}
|
1071
|
+
}
|
1072
|
+
|
1073
|
+
this.sources.push( source );
|
1074
|
+
return this;
|
1075
|
+
},
|
1076
|
+
|
1077
|
+
append: function append ( str, options ) {
|
1078
|
+
this.addSource({
|
1079
|
+
content: new MagicString$1( str ),
|
1080
|
+
separator: ( options && options.separator ) || ''
|
1081
|
+
});
|
1082
|
+
|
1083
|
+
return this;
|
1084
|
+
},
|
1085
|
+
|
1086
|
+
clone: function clone () {
|
1087
|
+
var bundle = new Bundle({
|
1088
|
+
intro: this.intro,
|
1089
|
+
separator: this.separator
|
1090
|
+
});
|
1091
|
+
|
1092
|
+
this.sources.forEach( function (source) {
|
1093
|
+
bundle.addSource({
|
1094
|
+
filename: source.filename,
|
1095
|
+
content: source.content.clone(),
|
1096
|
+
separator: source.separator
|
1097
|
+
});
|
1098
|
+
});
|
1099
|
+
|
1100
|
+
return bundle;
|
1101
|
+
},
|
1102
|
+
|
1103
|
+
generateMap: function generateMap ( options ) {
|
1104
|
+
var this$1 = this;
|
1105
|
+
if ( options === void 0 ) options = {};
|
1106
|
+
|
1107
|
+
var names = [];
|
1108
|
+
this.sources.forEach( function (source) {
|
1109
|
+
Object.keys( source.content.storedNames ).forEach( function (name) {
|
1110
|
+
if ( !~names.indexOf( name ) ) { names.push( name ); }
|
1111
|
+
});
|
1112
|
+
});
|
1113
|
+
|
1114
|
+
var mappings = new Mappings( options.hires );
|
1115
|
+
|
1116
|
+
if ( this.intro ) {
|
1117
|
+
mappings.advance( this.intro );
|
1118
|
+
}
|
1119
|
+
|
1120
|
+
this.sources.forEach( function ( source, i ) {
|
1121
|
+
if ( i > 0 ) {
|
1122
|
+
mappings.advance( this$1.separator );
|
1123
|
+
}
|
1124
|
+
|
1125
|
+
var sourceIndex = source.filename ? this$1.uniqueSourceIndexByFilename[ source.filename ] : -1;
|
1126
|
+
var magicString = source.content;
|
1127
|
+
var locate = getLocator( magicString.original );
|
1128
|
+
|
1129
|
+
if ( magicString.intro ) {
|
1130
|
+
mappings.advance( magicString.intro );
|
1131
|
+
}
|
1132
|
+
|
1133
|
+
magicString.firstChunk.eachNext( function (chunk) {
|
1134
|
+
var loc = locate( chunk.start );
|
1135
|
+
|
1136
|
+
if ( chunk.intro.length ) { mappings.advance( chunk.intro ); }
|
1137
|
+
|
1138
|
+
if ( source.filename ) {
|
1139
|
+
if ( chunk.edited ) {
|
1140
|
+
mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
|
1141
|
+
} else {
|
1142
|
+
mappings.addUneditedChunk( sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations );
|
1143
|
+
}
|
1144
|
+
}
|
1145
|
+
|
1146
|
+
else {
|
1147
|
+
mappings.advance( chunk.content );
|
1148
|
+
}
|
1149
|
+
|
1150
|
+
if ( chunk.outro.length ) { mappings.advance( chunk.outro ); }
|
1151
|
+
});
|
1152
|
+
|
1153
|
+
if ( magicString.outro ) {
|
1154
|
+
mappings.advance( magicString.outro );
|
1155
|
+
}
|
1156
|
+
});
|
1157
|
+
|
1158
|
+
return new SourceMap({
|
1159
|
+
file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
|
1160
|
+
sources: this.uniqueSources.map( function (source) {
|
1161
|
+
return options.file ? getRelativePath( options.file, source.filename ) : source.filename;
|
1162
|
+
}),
|
1163
|
+
sourcesContent: this.uniqueSources.map( function (source) {
|
1164
|
+
return options.includeContent ? source.content : null;
|
1165
|
+
}),
|
1166
|
+
names: names,
|
1167
|
+
mappings: mappings.encode()
|
1168
|
+
});
|
1169
|
+
},
|
1170
|
+
|
1171
|
+
getIndentString: function getIndentString () {
|
1172
|
+
var indentStringCounts = {};
|
1173
|
+
|
1174
|
+
this.sources.forEach( function (source) {
|
1175
|
+
var indentStr = source.content.indentStr;
|
1176
|
+
|
1177
|
+
if ( indentStr === null ) { return; }
|
1178
|
+
|
1179
|
+
if ( !indentStringCounts[ indentStr ] ) { indentStringCounts[ indentStr ] = 0; }
|
1180
|
+
indentStringCounts[ indentStr ] += 1;
|
1181
|
+
});
|
1182
|
+
|
1183
|
+
return ( Object.keys( indentStringCounts ).sort( function ( a, b ) {
|
1184
|
+
return indentStringCounts[a] - indentStringCounts[b];
|
1185
|
+
})[0] ) || '\t';
|
1186
|
+
},
|
1187
|
+
|
1188
|
+
indent: function indent ( indentStr ) {
|
1189
|
+
var this$1 = this;
|
1190
|
+
|
1191
|
+
if ( !arguments.length ) {
|
1192
|
+
indentStr = this.getIndentString();
|
1193
|
+
}
|
1194
|
+
|
1195
|
+
if ( indentStr === '' ) { return this; } // noop
|
1196
|
+
|
1197
|
+
var trailingNewline = !this.intro || this.intro.slice( -1 ) === '\n';
|
1198
|
+
|
1199
|
+
this.sources.forEach( function ( source, i ) {
|
1200
|
+
var separator = source.separator !== undefined ? source.separator : this$1.separator;
|
1201
|
+
var indentStart = trailingNewline || ( i > 0 && /\r?\n$/.test( separator ) );
|
1202
|
+
|
1203
|
+
source.content.indent( indentStr, {
|
1204
|
+
exclude: source.indentExclusionRanges,
|
1205
|
+
indentStart: indentStart//: trailingNewline || /\r?\n$/.test( separator ) //true///\r?\n/.test( separator )
|
1206
|
+
});
|
1207
|
+
|
1208
|
+
// TODO this is a very slow way to determine this
|
1209
|
+
trailingNewline = source.content.toString().slice( 0, -1 ) === '\n';
|
1210
|
+
});
|
1211
|
+
|
1212
|
+
if ( this.intro ) {
|
1213
|
+
this.intro = indentStr + this.intro.replace( /^[^\n]/gm, function ( match, index ) {
|
1214
|
+
return index > 0 ? indentStr + match : match;
|
1215
|
+
});
|
1216
|
+
}
|
1217
|
+
|
1218
|
+
return this;
|
1219
|
+
},
|
1220
|
+
|
1221
|
+
prepend: function prepend ( str ) {
|
1222
|
+
this.intro = str + this.intro;
|
1223
|
+
return this;
|
1224
|
+
},
|
1225
|
+
|
1226
|
+
toString: function toString () {
|
1227
|
+
var this$1 = this;
|
1228
|
+
|
1229
|
+
var body = this.sources.map( function ( source, i ) {
|
1230
|
+
var separator = source.separator !== undefined ? source.separator : this$1.separator;
|
1231
|
+
var str = ( i > 0 ? separator : '' ) + source.content.toString();
|
1232
|
+
|
1233
|
+
return str;
|
1234
|
+
}).join( '' );
|
1235
|
+
|
1236
|
+
return this.intro + body;
|
1237
|
+
},
|
1238
|
+
|
1239
|
+
trimLines: function trimLines () {
|
1240
|
+
return this.trim('[\\r\\n]');
|
1241
|
+
},
|
1242
|
+
|
1243
|
+
trim: function trim ( charType ) {
|
1244
|
+
return this.trimStart( charType ).trimEnd( charType );
|
1245
|
+
},
|
1246
|
+
|
1247
|
+
trimStart: function trimStart ( charType ) {
|
1248
|
+
var this$1 = this;
|
1249
|
+
|
1250
|
+
var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
|
1251
|
+
this.intro = this.intro.replace( rx, '' );
|
1252
|
+
|
1253
|
+
if ( !this.intro ) {
|
1254
|
+
var source;
|
1255
|
+
var i = 0;
|
1256
|
+
|
1257
|
+
do {
|
1258
|
+
source = this$1.sources[i];
|
1259
|
+
|
1260
|
+
if ( !source ) {
|
1261
|
+
break;
|
1262
|
+
}
|
1263
|
+
|
1264
|
+
source.content.trimStart( charType );
|
1265
|
+
i += 1;
|
1266
|
+
} while ( source.content.toString() === '' ); // TODO faster way to determine non-empty source?
|
1267
|
+
}
|
1268
|
+
|
1269
|
+
return this;
|
1270
|
+
},
|
1271
|
+
|
1272
|
+
trimEnd: function trimEnd ( charType ) {
|
1273
|
+
var this$1 = this;
|
1274
|
+
|
1275
|
+
var rx = new RegExp( ( charType || '\\s' ) + '+$' );
|
1276
|
+
|
1277
|
+
var source;
|
1278
|
+
var i = this.sources.length - 1;
|
1279
|
+
|
1280
|
+
do {
|
1281
|
+
source = this$1.sources[i];
|
1282
|
+
|
1283
|
+
if ( !source ) {
|
1284
|
+
this$1.intro = this$1.intro.replace( rx, '' );
|
1285
|
+
break;
|
1286
|
+
}
|
1287
|
+
|
1288
|
+
source.content.trimEnd( charType );
|
1289
|
+
i -= 1;
|
1290
|
+
} while ( source.content.toString() === '' ); // TODO faster way to determine non-empty source?
|
1291
|
+
|
1292
|
+
return this;
|
1293
|
+
}
|
1294
|
+
};
|
1295
|
+
|
1296
|
+
MagicString$1.Bundle = Bundle;
|
1297
|
+
MagicString$1.default = MagicString$1; // work around TypeScript bug https://github.com/Rich-Harris/magic-string/pull/121
|
1298
|
+
|
1299
|
+
module.exports = MagicString$1;
|
1300
|
+
//# sourceMappingURL=magic-string.cjs.js.map
|