esperanto-source 0.6.10 → 0.6.11
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/esperanto/source/version.rb +1 -1
- data/lib/esperanto/source.rb +0 -2
- data/vendor/esperanto.browser.js +862 -7
- data/vendor/esperanto.js +6 -6
- metadata +1 -3
- data/vendor/magic-string.js +0 -765
- data/vendor/vlq.js +0 -99
data/vendor/esperanto.browser.js
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
/*
|
2
|
-
esperanto.js v0.6.
|
2
|
+
esperanto.js v0.6.11 - 2015-02-08
|
3
3
|
http://esperantojs.org
|
4
4
|
|
5
5
|
Released under the MIT License.
|
6
6
|
*/
|
7
7
|
|
8
8
|
(function (global, factory) {
|
9
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('acorn'), require('
|
10
|
-
typeof define === 'function' && define.amd ? define(['acorn', '
|
11
|
-
global.esperanto = factory(global.acorn, global.
|
12
|
-
}(this, function (acorn,
|
9
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('acorn'), require('estraverse')) :
|
10
|
+
typeof define === 'function' && define.amd ? define(['acorn', 'estraverse'], factory) :
|
11
|
+
global.esperanto = factory(global.acorn, global.estraverse)
|
12
|
+
}(this, function (acorn, estraverse) { 'use strict';
|
13
13
|
|
14
14
|
var hasOwnProp = Object.prototype.hasOwnProperty;
|
15
15
|
|
@@ -33,6 +33,861 @@
|
|
33
33
|
}
|
34
34
|
}
|
35
35
|
|
36
|
+
var _btoa;
|
37
|
+
|
38
|
+
if ( typeof window !== 'undefined' && typeof window.btoa === 'function' ) {
|
39
|
+
_btoa = window.btoa;
|
40
|
+
} else if ( typeof Buffer === 'function' ) {
|
41
|
+
_btoa = function ( str ) {
|
42
|
+
return new Buffer( str ).toString( 'base64' );
|
43
|
+
};
|
44
|
+
} else {
|
45
|
+
throw new Error( 'Unsupported environment' );
|
46
|
+
}
|
47
|
+
|
48
|
+
var btoa = _btoa;
|
49
|
+
|
50
|
+
var SourceMap = function ( properties ) {
|
51
|
+
this.version = 3;
|
52
|
+
|
53
|
+
this.file = properties.file;
|
54
|
+
this.sources = properties.sources;
|
55
|
+
this.sourcesContent = properties.sourcesContent;
|
56
|
+
this.names = properties.names;
|
57
|
+
this.mappings = properties.mappings;
|
58
|
+
};
|
59
|
+
|
60
|
+
SourceMap.prototype = {
|
61
|
+
toString: function () {
|
62
|
+
return JSON.stringify( this );
|
63
|
+
},
|
64
|
+
|
65
|
+
toUrl: function () {
|
66
|
+
return 'data:application/json;charset=utf-8;base64,' + btoa( this.toString() );
|
67
|
+
}
|
68
|
+
};
|
69
|
+
|
70
|
+
function getRelativePath__getRelativePath ( from, to ) {
|
71
|
+
var fromParts, toParts, i;
|
72
|
+
|
73
|
+
fromParts = from.split( '/' );
|
74
|
+
toParts = to.split( '/' );
|
75
|
+
|
76
|
+
fromParts.pop(); // get dirname
|
77
|
+
|
78
|
+
while ( fromParts[0] === toParts[0] ) {
|
79
|
+
fromParts.shift();
|
80
|
+
toParts.shift();
|
81
|
+
}
|
82
|
+
|
83
|
+
if ( fromParts.length ) {
|
84
|
+
i = fromParts.length;
|
85
|
+
while ( i-- ) fromParts[i] = '..';
|
86
|
+
}
|
87
|
+
|
88
|
+
return fromParts.concat( toParts ).join( '/' );
|
89
|
+
}
|
90
|
+
|
91
|
+
var Bundle = function ( options ) {
|
92
|
+
options = options || {};
|
93
|
+
|
94
|
+
this.intro = options.intro || '';
|
95
|
+
this.outro = options.outro || '';
|
96
|
+
this.separator = 'separator' in options ? options.separator : '\n';
|
97
|
+
|
98
|
+
this.sources = [];
|
99
|
+
};
|
100
|
+
|
101
|
+
Bundle.prototype = {
|
102
|
+
addSource: function ( source ) {
|
103
|
+
if ( typeof source !== 'object' || !source.content ) {
|
104
|
+
throw new Error( 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`' );
|
105
|
+
}
|
106
|
+
|
107
|
+
this.sources.push( source );
|
108
|
+
return this;
|
109
|
+
},
|
110
|
+
|
111
|
+
append: function ( str ) {
|
112
|
+
this.outro += str;
|
113
|
+
return this;
|
114
|
+
},
|
115
|
+
|
116
|
+
clone: function () {
|
117
|
+
var bundle = new Bundle({
|
118
|
+
intro: this.intro,
|
119
|
+
outro: this.outro,
|
120
|
+
separator: this.separator
|
121
|
+
});
|
122
|
+
|
123
|
+
this.sources.forEach( function ( source ) {
|
124
|
+
bundle.addSource({
|
125
|
+
filename: source.filename,
|
126
|
+
content: source.content.clone()
|
127
|
+
});
|
128
|
+
});
|
129
|
+
|
130
|
+
return bundle;
|
131
|
+
},
|
132
|
+
|
133
|
+
generateMap: function ( options ) {
|
134
|
+
var offsets = {}, encoded, encodingSeparator;
|
135
|
+
|
136
|
+
encodingSeparator = getSemis( this.separator );
|
137
|
+
|
138
|
+
encoded = (
|
139
|
+
getSemis( this.intro ) +
|
140
|
+
this.sources.map( function ( source, sourceIndex) {
|
141
|
+
return source.content.getMappings( options.hires, sourceIndex, offsets );
|
142
|
+
}).join( encodingSeparator ) +
|
143
|
+
getSemis( this.outro )
|
144
|
+
);
|
145
|
+
|
146
|
+
return new SourceMap({
|
147
|
+
file: options.file.split( '/' ).pop(),
|
148
|
+
sources: this.sources.map( function ( source ) {
|
149
|
+
return getRelativePath__getRelativePath( options.file, source.filename );
|
150
|
+
}),
|
151
|
+
sourcesContent: this.sources.map( function ( source ) {
|
152
|
+
return options.includeContent ? source.content.original : null;
|
153
|
+
}),
|
154
|
+
names: [],
|
155
|
+
mappings: encoded
|
156
|
+
});
|
157
|
+
},
|
158
|
+
|
159
|
+
getIndentString: function () {
|
160
|
+
var indentStringCounts = {};
|
161
|
+
|
162
|
+
this.sources.forEach( function ( source ) {
|
163
|
+
var indentStr = source.content.indentStr;
|
164
|
+
|
165
|
+
if ( indentStr === null ) return;
|
166
|
+
|
167
|
+
if ( !indentStringCounts[ indentStr ] ) indentStringCounts[ indentStr ] = 0;
|
168
|
+
indentStringCounts[ indentStr ] += 1;
|
169
|
+
});
|
170
|
+
|
171
|
+
return ( Object.keys( indentStringCounts ).sort( function ( a, b ) {
|
172
|
+
return indentStringCounts[a] - indentStringCounts[b];
|
173
|
+
})[0] ) || '\t';
|
174
|
+
},
|
175
|
+
|
176
|
+
indent: function ( indentStr ) {
|
177
|
+
if ( !indentStr ) {
|
178
|
+
indentStr = this.getIndentString();
|
179
|
+
}
|
180
|
+
|
181
|
+
this.sources.forEach( function ( source ) {
|
182
|
+
source.content.indent( indentStr, { exclude: source.indentExclusionRanges });
|
183
|
+
});
|
184
|
+
|
185
|
+
this.intro = this.intro.replace( /^[^\n]/gm, indentStr + '$&' );
|
186
|
+
this.outro = this.outro.replace( /^[^\n]/gm, indentStr + '$&' );
|
187
|
+
|
188
|
+
return this;
|
189
|
+
},
|
190
|
+
|
191
|
+
prepend: function ( str ) {
|
192
|
+
this.intro = str + this.intro;
|
193
|
+
return this;
|
194
|
+
},
|
195
|
+
|
196
|
+
toString: function () {
|
197
|
+
return this.intro + this.sources.map( stringify ).join( this.separator ) + this.outro;
|
198
|
+
},
|
199
|
+
|
200
|
+
trimLines: function () {
|
201
|
+
return this.trim('[\\r\\n]');
|
202
|
+
},
|
203
|
+
|
204
|
+
trim: function (charType) {
|
205
|
+
return this.trimStart(charType).trimEnd(charType);
|
206
|
+
},
|
207
|
+
|
208
|
+
trimStart: function (charType) {
|
209
|
+
var rx = new RegExp('^' + (charType || '\\s') + '+');
|
210
|
+
this.intro = this.intro.replace( rx, '' );
|
211
|
+
|
212
|
+
if ( !this.intro ) {
|
213
|
+
var source;
|
214
|
+
var i = 0;
|
215
|
+
do {
|
216
|
+
source = this.sources[i];
|
217
|
+
|
218
|
+
if ( !source ) {
|
219
|
+
this.outro = this.outro.replace( rx, '' );
|
220
|
+
break;
|
221
|
+
}
|
222
|
+
|
223
|
+
source.content.trimStart();
|
224
|
+
i += 1;
|
225
|
+
} while ( source.content.str === '' );
|
226
|
+
}
|
227
|
+
|
228
|
+
return this;
|
229
|
+
},
|
230
|
+
|
231
|
+
trimEnd: function(charType) {
|
232
|
+
var rx = new RegExp((charType || '\\s') + '+$');
|
233
|
+
this.outro = this.outro.replace( rx, '' );
|
234
|
+
|
235
|
+
if ( !this.outro ) {
|
236
|
+
var source;
|
237
|
+
var i = this.sources.length - 1;
|
238
|
+
do {
|
239
|
+
source = this.sources[i];
|
240
|
+
|
241
|
+
if ( !source ) {
|
242
|
+
this.intro = this.intro.replace( rx, '' );
|
243
|
+
break;
|
244
|
+
}
|
245
|
+
|
246
|
+
source.content.trimEnd(charType);
|
247
|
+
i -= 1;
|
248
|
+
} while ( source.content.str === '' );
|
249
|
+
}
|
250
|
+
|
251
|
+
return this;
|
252
|
+
}
|
253
|
+
};
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
function stringify ( source ) {
|
258
|
+
return source.content.toString();
|
259
|
+
}
|
260
|
+
|
261
|
+
function getSemis ( str ) {
|
262
|
+
return new Array( str.split( '\n' ).length ).join( ';' );
|
263
|
+
}
|
264
|
+
|
265
|
+
function guessIndent ( code ) {
|
266
|
+
var lines, tabbed, spaced, min;
|
267
|
+
|
268
|
+
lines = code.split( '\n' );
|
269
|
+
|
270
|
+
tabbed = lines.filter( function ( line ) {
|
271
|
+
return /^\t+/.test( line );
|
272
|
+
});
|
273
|
+
|
274
|
+
spaced = lines.filter( function ( line ) {
|
275
|
+
return /^ {2,}/.test( line );
|
276
|
+
});
|
277
|
+
|
278
|
+
if ( tabbed.length === 0 && spaced.length === 0 ) {
|
279
|
+
return null;
|
280
|
+
}
|
281
|
+
|
282
|
+
// More lines tabbed than spaced? Assume tabs, and
|
283
|
+
// default to tabs in the case of a tie (or nothing
|
284
|
+
// to go on)
|
285
|
+
if ( tabbed.length >= spaced.length ) {
|
286
|
+
return '\t';
|
287
|
+
}
|
288
|
+
|
289
|
+
// Otherwise, we need to guess the multiple
|
290
|
+
min = spaced.reduce( function ( previous, current ) {
|
291
|
+
var numSpaces = /^ +/.exec( current )[0].length;
|
292
|
+
return Math.min( numSpaces, previous );
|
293
|
+
}, Infinity );
|
294
|
+
|
295
|
+
return new Array( min + 1 ).join( ' ' );
|
296
|
+
}
|
297
|
+
|
298
|
+
var charToInteger = {};
|
299
|
+
var integerToChar = {};
|
300
|
+
|
301
|
+
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
|
302
|
+
charToInteger[ char ] = i;
|
303
|
+
integerToChar[ i ] = char;
|
304
|
+
});
|
305
|
+
|
306
|
+
function decode ( string ) {
|
307
|
+
var result = [],
|
308
|
+
len = string.length,
|
309
|
+
i,
|
310
|
+
hasContinuationBit,
|
311
|
+
shift = 0,
|
312
|
+
value = 0,
|
313
|
+
integer,
|
314
|
+
shouldNegate;
|
315
|
+
|
316
|
+
for ( i = 0; i < len; i += 1 ) {
|
317
|
+
integer = charToInteger[ string[i] ];
|
318
|
+
|
319
|
+
if ( integer === undefined ) {
|
320
|
+
throw new Error( 'Invalid character (' + string[i] + ')' );
|
321
|
+
}
|
322
|
+
|
323
|
+
hasContinuationBit = integer & 32;
|
324
|
+
|
325
|
+
integer &= 31;
|
326
|
+
value += integer << shift;
|
327
|
+
|
328
|
+
if ( hasContinuationBit ) {
|
329
|
+
shift += 5;
|
330
|
+
} else {
|
331
|
+
shouldNegate = value & 1;
|
332
|
+
value >>= 1;
|
333
|
+
|
334
|
+
result.push( shouldNegate ? -value : value );
|
335
|
+
|
336
|
+
// reset
|
337
|
+
value = shift = 0;
|
338
|
+
}
|
339
|
+
}
|
340
|
+
|
341
|
+
return result;
|
342
|
+
}
|
343
|
+
|
344
|
+
function encode ( value ) {
|
345
|
+
var result;
|
346
|
+
|
347
|
+
if ( typeof value === 'number' ) {
|
348
|
+
result = encodeInteger( value );
|
349
|
+
} else if ( Array.isArray( value ) ) {
|
350
|
+
result = '';
|
351
|
+
value.forEach( function ( num ) {
|
352
|
+
result += encodeInteger( num );
|
353
|
+
});
|
354
|
+
} else {
|
355
|
+
throw new Error( 'vlq.encode accepts an integer or an array of integers' );
|
356
|
+
}
|
357
|
+
|
358
|
+
return result;
|
359
|
+
}
|
360
|
+
|
361
|
+
function encodeInteger ( num ) {
|
362
|
+
var result = '', clamped;
|
363
|
+
|
364
|
+
if ( num < 0 ) {
|
365
|
+
num = ( -num << 1 ) | 1;
|
366
|
+
} else {
|
367
|
+
num <<= 1;
|
368
|
+
}
|
369
|
+
|
370
|
+
do {
|
371
|
+
clamped = num & 31;
|
372
|
+
num >>= 5;
|
373
|
+
|
374
|
+
if ( num > 0 ) {
|
375
|
+
clamped |= 32;
|
376
|
+
}
|
377
|
+
|
378
|
+
result += integerToChar[ clamped ];
|
379
|
+
} while ( num > 0 );
|
380
|
+
|
381
|
+
return result;
|
382
|
+
}
|
383
|
+
|
384
|
+
var encode__default = encode;
|
385
|
+
|
386
|
+
function encodeMappings ( original, str, mappings, hires, sourceIndex, offsets ) {
|
387
|
+
var lineStart,
|
388
|
+
locations,
|
389
|
+
lines,
|
390
|
+
encoded,
|
391
|
+
inverseMappings,
|
392
|
+
charOffset = 0,
|
393
|
+
firstSegment = true;
|
394
|
+
|
395
|
+
// store locations, for fast lookup
|
396
|
+
lineStart = 0;
|
397
|
+
locations = original.split( '\n' ).map( function ( line ) {
|
398
|
+
var start = lineStart;
|
399
|
+
lineStart += line.length + 1; // +1 for the newline
|
400
|
+
|
401
|
+
return start;
|
402
|
+
});
|
403
|
+
|
404
|
+
inverseMappings = invert( str, mappings );
|
405
|
+
|
406
|
+
lines = str.split( '\n' ).map( function ( line ) {
|
407
|
+
var segments, len, char, origin, lastOrigin, i, location;
|
408
|
+
|
409
|
+
segments = [];
|
410
|
+
|
411
|
+
len = line.length;
|
412
|
+
for ( i = 0; i < len; i += 1 ) {
|
413
|
+
char = i + charOffset;
|
414
|
+
origin = inverseMappings[ char ];
|
415
|
+
|
416
|
+
if ( !~origin ) {
|
417
|
+
if ( !~lastOrigin ) {
|
418
|
+
// do nothing
|
419
|
+
} else {
|
420
|
+
segments.push({
|
421
|
+
generatedCodeColumn: i,
|
422
|
+
sourceIndex: sourceIndex,
|
423
|
+
sourceCodeLine: 0,
|
424
|
+
sourceCodeColumn: 0
|
425
|
+
});
|
426
|
+
}
|
427
|
+
}
|
428
|
+
|
429
|
+
else {
|
430
|
+
if ( !hires && ( origin === lastOrigin + 1 ) ) {
|
431
|
+
// do nothing
|
432
|
+
} else {
|
433
|
+
location = getLocation( locations, origin );
|
434
|
+
|
435
|
+
segments.push({
|
436
|
+
generatedCodeColumn: i,
|
437
|
+
sourceIndex: sourceIndex,
|
438
|
+
sourceCodeLine: location.line,
|
439
|
+
sourceCodeColumn: location.column
|
440
|
+
});
|
441
|
+
}
|
442
|
+
}
|
443
|
+
|
444
|
+
lastOrigin = origin;
|
445
|
+
}
|
446
|
+
|
447
|
+
charOffset += line.length + 1;
|
448
|
+
return segments;
|
449
|
+
});
|
450
|
+
|
451
|
+
offsets = offsets || {};
|
452
|
+
|
453
|
+
offsets.sourceIndex = offsets.sourceIndex || 0;
|
454
|
+
offsets.sourceCodeLine = offsets.sourceCodeLine || 0;
|
455
|
+
offsets.sourceCodeColumn = offsets.sourceCodeColumn || 0;
|
456
|
+
|
457
|
+
encoded = lines.map( function ( segments ) {
|
458
|
+
var generatedCodeColumn = 0;
|
459
|
+
|
460
|
+
return segments.map( function ( segment ) {
|
461
|
+
var arr = [
|
462
|
+
segment.generatedCodeColumn - generatedCodeColumn,
|
463
|
+
segment.sourceIndex - offsets.sourceIndex,
|
464
|
+
segment.sourceCodeLine - offsets.sourceCodeLine,
|
465
|
+
segment.sourceCodeColumn - offsets.sourceCodeColumn
|
466
|
+
];
|
467
|
+
|
468
|
+
generatedCodeColumn = segment.generatedCodeColumn;
|
469
|
+
offsets.sourceIndex = segment.sourceIndex;
|
470
|
+
offsets.sourceCodeLine = segment.sourceCodeLine;
|
471
|
+
offsets.sourceCodeColumn = segment.sourceCodeColumn;
|
472
|
+
|
473
|
+
firstSegment = false;
|
474
|
+
|
475
|
+
return encode__default( arr );
|
476
|
+
}).join( ',' );
|
477
|
+
}).join( ';' );
|
478
|
+
|
479
|
+
return encoded;
|
480
|
+
}
|
481
|
+
|
482
|
+
|
483
|
+
function invert ( str, mappings ) {
|
484
|
+
var inverted = new Uint32Array( str.length ), i;
|
485
|
+
|
486
|
+
// initialise everything to -1
|
487
|
+
i = str.length;
|
488
|
+
while ( i-- ) {
|
489
|
+
inverted[i] = -1;
|
490
|
+
}
|
491
|
+
|
492
|
+
// then apply the actual mappings
|
493
|
+
i = mappings.length;
|
494
|
+
while ( i-- ) {
|
495
|
+
if ( ~mappings[i] ) {
|
496
|
+
inverted[ mappings[i] ] = i;
|
497
|
+
}
|
498
|
+
}
|
499
|
+
|
500
|
+
return inverted;
|
501
|
+
}
|
502
|
+
|
503
|
+
function getLocation ( locations, char ) {
|
504
|
+
var i;
|
505
|
+
|
506
|
+
i = locations.length;
|
507
|
+
while ( i-- ) {
|
508
|
+
if ( locations[i] <= char ) {
|
509
|
+
return {
|
510
|
+
line: i,
|
511
|
+
column: char - locations[i]
|
512
|
+
};
|
513
|
+
}
|
514
|
+
}
|
515
|
+
|
516
|
+
throw new Error( 'Character out of bounds' );
|
517
|
+
}
|
518
|
+
|
519
|
+
var MagicString = function ( string ) {
|
520
|
+
this.original = this.str = string;
|
521
|
+
this.mappings = initMappings( string.length );
|
522
|
+
|
523
|
+
this.indentStr = guessIndent( string );
|
524
|
+
};
|
525
|
+
|
526
|
+
MagicString.prototype = {
|
527
|
+
append: function ( content ) {
|
528
|
+
this.str += content;
|
529
|
+
return this;
|
530
|
+
},
|
531
|
+
|
532
|
+
clone: function () {
|
533
|
+
var clone, i;
|
534
|
+
|
535
|
+
clone = new MagicString( this.original );
|
536
|
+
clone.str = this.str;
|
537
|
+
|
538
|
+
i = clone.mappings.length;
|
539
|
+
while ( i-- ) {
|
540
|
+
clone.mappings[i] = this.mappings[i];
|
541
|
+
}
|
542
|
+
|
543
|
+
return clone;
|
544
|
+
},
|
545
|
+
|
546
|
+
generateMap: function ( options ) {
|
547
|
+
options = options || {};
|
548
|
+
|
549
|
+
return new SourceMap({
|
550
|
+
file: ( options.file ? options.file.split( '/' ).pop() : null ),
|
551
|
+
sources: [ options.source ? getRelativePath__getRelativePath( options.file || '', options.source ) : null ],
|
552
|
+
sourcesContent: options.includeContent ? [ this.original ] : [ null ],
|
553
|
+
names: [],
|
554
|
+
mappings: this.getMappings( options.hires, 0 )
|
555
|
+
});
|
556
|
+
},
|
557
|
+
|
558
|
+
getIndentString: function () {
|
559
|
+
return this.indentStr === null ? '\t' : this.indentStr;
|
560
|
+
},
|
561
|
+
|
562
|
+
getMappings: function ( hires, sourceIndex, offsets ) {
|
563
|
+
return encodeMappings( this.original, this.str, this.mappings, hires, sourceIndex, offsets );
|
564
|
+
},
|
565
|
+
|
566
|
+
indent: function ( indentStr, options ) {
|
567
|
+
var self = this,
|
568
|
+
mappings = this.mappings,
|
569
|
+
reverseMappings = reverse( mappings, this.str.length ),
|
570
|
+
pattern = /^[^\n]/gm,
|
571
|
+
match,
|
572
|
+
inserts = [],
|
573
|
+
adjustments,
|
574
|
+
exclusions,
|
575
|
+
lastEnd,
|
576
|
+
i;
|
577
|
+
|
578
|
+
if ( typeof indentStr === 'object' ) {
|
579
|
+
options = indentStr;
|
580
|
+
indentStr = undefined;
|
581
|
+
}
|
582
|
+
|
583
|
+
indentStr = indentStr !== undefined ? indentStr : ( this.indentStr || '\t' );
|
584
|
+
|
585
|
+
options = options || {};
|
586
|
+
|
587
|
+
// Process exclusion ranges
|
588
|
+
if ( options.exclude ) {
|
589
|
+
exclusions = typeof options.exclude[0] === 'number' ? [ options.exclude ] : options.exclude;
|
590
|
+
|
591
|
+
exclusions = exclusions.map( function ( range ) {
|
592
|
+
var rangeStart, rangeEnd;
|
593
|
+
|
594
|
+
rangeStart = self.locate( range[0] );
|
595
|
+
rangeEnd = self.locate( range[1] );
|
596
|
+
|
597
|
+
if ( rangeStart === null || rangeEnd === null ) {
|
598
|
+
throw new Error( 'Cannot use indices of replaced characters as exclusion ranges' );
|
599
|
+
}
|
600
|
+
|
601
|
+
return [ rangeStart, rangeEnd ];
|
602
|
+
});
|
603
|
+
|
604
|
+
exclusions.sort( function ( a, b ) {
|
605
|
+
return a[0] - b[0];
|
606
|
+
});
|
607
|
+
|
608
|
+
// check for overlaps
|
609
|
+
lastEnd = -1;
|
610
|
+
exclusions.forEach( function ( range ) {
|
611
|
+
if ( range[0] < lastEnd ) {
|
612
|
+
throw new Error( 'Exclusion ranges cannot overlap' );
|
613
|
+
}
|
614
|
+
|
615
|
+
lastEnd = range[1];
|
616
|
+
});
|
617
|
+
}
|
618
|
+
|
619
|
+
if ( !exclusions ) {
|
620
|
+
while ( match = pattern.exec( this.str ) ) {
|
621
|
+
inserts.push( match.index );
|
622
|
+
}
|
623
|
+
|
624
|
+
this.str = this.str.replace( pattern, indentStr + '$&' );
|
625
|
+
} else {
|
626
|
+
while ( match = pattern.exec( this.str ) ) {
|
627
|
+
if ( !isExcluded( match.index - 1 ) ) {
|
628
|
+
inserts.push( match.index );
|
629
|
+
}
|
630
|
+
}
|
631
|
+
|
632
|
+
this.str = this.str.replace( pattern, function ( match, index ) {
|
633
|
+
return isExcluded( index - 1 ) ? match : indentStr + match;
|
634
|
+
});
|
635
|
+
}
|
636
|
+
|
637
|
+
adjustments = inserts.map( function ( index ) {
|
638
|
+
var origin;
|
639
|
+
|
640
|
+
do {
|
641
|
+
origin = reverseMappings[ index++ ];
|
642
|
+
} while ( !~origin && index < self.str.length );
|
643
|
+
|
644
|
+
return origin;
|
645
|
+
});
|
646
|
+
|
647
|
+
i = adjustments.length;
|
648
|
+
lastEnd = this.mappings.length;
|
649
|
+
while ( i-- ) {
|
650
|
+
adjust( self.mappings, adjustments[i], lastEnd, ( ( i + 1 ) * indentStr.length ) );
|
651
|
+
lastEnd = adjustments[i];
|
652
|
+
}
|
653
|
+
|
654
|
+
return this;
|
655
|
+
|
656
|
+
function isExcluded ( index ) {
|
657
|
+
var i = exclusions.length, range;
|
658
|
+
|
659
|
+
while ( i-- ) {
|
660
|
+
range = exclusions[i];
|
661
|
+
|
662
|
+
if ( range[1] < index ) {
|
663
|
+
return false;
|
664
|
+
}
|
665
|
+
|
666
|
+
if ( range[0] <= index ) {
|
667
|
+
return true;
|
668
|
+
}
|
669
|
+
}
|
670
|
+
}
|
671
|
+
},
|
672
|
+
|
673
|
+
insert: function ( index, content ) {
|
674
|
+
if ( index === 0 ) {
|
675
|
+
this.prepend( content );
|
676
|
+
} else if ( index === this.original.length ) {
|
677
|
+
this.append( content );
|
678
|
+
} else {
|
679
|
+
var mapped = this.locate(index);
|
680
|
+
|
681
|
+
if ( mapped === null ) {
|
682
|
+
throw new Error( 'Cannot insert at replaced character index: ' + index );
|
683
|
+
}
|
684
|
+
|
685
|
+
this.str = this.str.substr( 0, mapped ) + content + this.str.substr( mapped );
|
686
|
+
adjust( this.mappings, index, this.mappings.length, content.length );
|
687
|
+
}
|
688
|
+
|
689
|
+
return this;
|
690
|
+
},
|
691
|
+
|
692
|
+
// get current location of character in original string
|
693
|
+
locate: function ( character ) {
|
694
|
+
var loc;
|
695
|
+
|
696
|
+
if ( character < 0 || character > this.mappings.length ) {
|
697
|
+
throw new Error( 'Character is out of bounds' );
|
698
|
+
}
|
699
|
+
|
700
|
+
loc = this.mappings[ character ];
|
701
|
+
return ~loc ? loc : null;
|
702
|
+
},
|
703
|
+
|
704
|
+
locateOrigin: function ( character ) {
|
705
|
+
var i;
|
706
|
+
|
707
|
+
if ( character < 0 || character >= this.str.length ) {
|
708
|
+
throw new Error( 'Character is out of bounds' );
|
709
|
+
}
|
710
|
+
|
711
|
+
i = this.mappings.length;
|
712
|
+
while ( i-- ) {
|
713
|
+
if ( this.mappings[i] === character ) {
|
714
|
+
return i;
|
715
|
+
}
|
716
|
+
}
|
717
|
+
|
718
|
+
return null;
|
719
|
+
},
|
720
|
+
|
721
|
+
prepend: function ( content ) {
|
722
|
+
this.str = content + this.str;
|
723
|
+
adjust( this.mappings, 0, this.mappings.length, content.length );
|
724
|
+
return this;
|
725
|
+
},
|
726
|
+
|
727
|
+
remove: function ( start, end ) {
|
728
|
+
this.replace( start, end, '' );
|
729
|
+
return this;
|
730
|
+
},
|
731
|
+
|
732
|
+
replace: function ( start, end, content ) {
|
733
|
+
var firstChar, lastChar, d;
|
734
|
+
|
735
|
+
firstChar = this.locate( start );
|
736
|
+
lastChar = this.locate( end - 1 );
|
737
|
+
|
738
|
+
if ( firstChar === null || lastChar === null ) {
|
739
|
+
throw new Error( 'Cannot replace the same content twice' );
|
740
|
+
}
|
741
|
+
|
742
|
+
if ( firstChar > lastChar + 1 ) {
|
743
|
+
throw new Error(
|
744
|
+
'BUG! First character mapped to a position after the last character: ' +
|
745
|
+
'[' + start + ', ' + end + '] -> [' + firstChar + ', ' + ( lastChar + 1 ) + ']'
|
746
|
+
);
|
747
|
+
}
|
748
|
+
|
749
|
+
this.str = this.str.substr( 0, firstChar ) + content + this.str.substring( lastChar + 1 );
|
750
|
+
|
751
|
+
d = content.length - ( lastChar + 1 - firstChar );
|
752
|
+
|
753
|
+
blank( this.mappings, start, end );
|
754
|
+
adjust( this.mappings, end, this.mappings.length, d );
|
755
|
+
return this;
|
756
|
+
},
|
757
|
+
|
758
|
+
slice: function ( start, end ) {
|
759
|
+
var firstChar, lastChar;
|
760
|
+
|
761
|
+
firstChar = this.locate( start );
|
762
|
+
lastChar = this.locate( end - 1 ) + 1;
|
763
|
+
|
764
|
+
if ( firstChar === null || lastChar === null ) {
|
765
|
+
throw new Error( 'Cannot use replaced characters as slice anchors' );
|
766
|
+
}
|
767
|
+
|
768
|
+
return this.str.slice( firstChar, lastChar );
|
769
|
+
},
|
770
|
+
|
771
|
+
toString: function () {
|
772
|
+
return this.str;
|
773
|
+
},
|
774
|
+
|
775
|
+
trimLines: function() {
|
776
|
+
return this.trim('[\\r\\n]');
|
777
|
+
},
|
778
|
+
|
779
|
+
trim: function (charType) {
|
780
|
+
return this.trimStart(charType).trimEnd(charType);
|
781
|
+
},
|
782
|
+
|
783
|
+
trimEnd: function (charType) {
|
784
|
+
var self = this;
|
785
|
+
var rx = new RegExp((charType || '\\s') + '+$');
|
786
|
+
|
787
|
+
this.str = this.str.replace( rx, function ( trailing, index, str ) {
|
788
|
+
var strLength = str.length,
|
789
|
+
length = trailing.length,
|
790
|
+
i,
|
791
|
+
chars = [];
|
792
|
+
|
793
|
+
i = strLength;
|
794
|
+
while ( i-- > strLength - length ) {
|
795
|
+
chars.push( self.locateOrigin( i ) );
|
796
|
+
}
|
797
|
+
|
798
|
+
i = chars.length;
|
799
|
+
while ( i-- ) {
|
800
|
+
if ( chars[i] !== null ) {
|
801
|
+
self.mappings[ chars[i] ] = -1;
|
802
|
+
}
|
803
|
+
}
|
804
|
+
|
805
|
+
return '';
|
806
|
+
});
|
807
|
+
|
808
|
+
return this;
|
809
|
+
},
|
810
|
+
|
811
|
+
trimStart: function (charType) {
|
812
|
+
var self = this;
|
813
|
+
var rx = new RegExp('^' + (charType || '\\s') + '+');
|
814
|
+
|
815
|
+
this.str = this.str.replace( rx, function ( leading ) {
|
816
|
+
var length = leading.length, i, chars = [], adjustmentStart = 0;
|
817
|
+
|
818
|
+
i = length;
|
819
|
+
while ( i-- ) {
|
820
|
+
chars.push( self.locateOrigin( i ) );
|
821
|
+
}
|
822
|
+
|
823
|
+
i = chars.length;
|
824
|
+
while ( i-- ) {
|
825
|
+
if ( chars[i] !== null ) {
|
826
|
+
self.mappings[ chars[i] ] = -1;
|
827
|
+
adjustmentStart += 1;
|
828
|
+
}
|
829
|
+
}
|
830
|
+
|
831
|
+
adjust( self.mappings, adjustmentStart, self.mappings.length, -length );
|
832
|
+
|
833
|
+
return '';
|
834
|
+
});
|
835
|
+
|
836
|
+
return this;
|
837
|
+
}
|
838
|
+
};
|
839
|
+
|
840
|
+
MagicString.Bundle = Bundle;
|
841
|
+
|
842
|
+
function adjust ( mappings, start, end, d ) {
|
843
|
+
var i = end;
|
844
|
+
|
845
|
+
if ( !d ) return; // replacement is same length as replaced string
|
846
|
+
|
847
|
+
while ( i-- > start ) {
|
848
|
+
if ( ~mappings[i] ) {
|
849
|
+
mappings[i] += d;
|
850
|
+
}
|
851
|
+
}
|
852
|
+
}
|
853
|
+
|
854
|
+
function initMappings ( i ) {
|
855
|
+
var mappings = new Uint32Array( i );
|
856
|
+
|
857
|
+
while ( i-- ) {
|
858
|
+
mappings[i] = i;
|
859
|
+
}
|
860
|
+
|
861
|
+
return mappings;
|
862
|
+
}
|
863
|
+
|
864
|
+
function blank ( mappings, start, i ) {
|
865
|
+
while ( i-- > start ) {
|
866
|
+
mappings[i] = -1;
|
867
|
+
}
|
868
|
+
}
|
869
|
+
|
870
|
+
function reverse ( mappings, i ) {
|
871
|
+
var result, location;
|
872
|
+
|
873
|
+
result = new Uint32Array( i );
|
874
|
+
|
875
|
+
while ( i-- ) {
|
876
|
+
result[i] = -1;
|
877
|
+
}
|
878
|
+
|
879
|
+
i = mappings.length;
|
880
|
+
while ( i-- ) {
|
881
|
+
location = mappings[i];
|
882
|
+
|
883
|
+
if ( ~location ) {
|
884
|
+
result[ location ] = i;
|
885
|
+
}
|
886
|
+
}
|
887
|
+
|
888
|
+
return result;
|
889
|
+
}
|
890
|
+
|
36
891
|
/*
|
37
892
|
This module traverse a module's AST, attaching scope information
|
38
893
|
to nodes as it goes, which is later used to determine which
|
@@ -618,7 +1473,7 @@
|
|
618
1473
|
includeContent: true,
|
619
1474
|
hires: true,
|
620
1475
|
file: sourceMapFile,
|
621
|
-
source: !isBundle ?
|
1476
|
+
source: !isBundle ? packageResult__getRelativePath( sourceMapFile, options.sourceMapSource ) : null
|
622
1477
|
});
|
623
1478
|
|
624
1479
|
if ( options.sourceMap === 'inline' ) {
|
@@ -645,7 +1500,7 @@
|
|
645
1500
|
};
|
646
1501
|
}
|
647
1502
|
|
648
|
-
function
|
1503
|
+
function packageResult__getRelativePath ( from, to ) {
|
649
1504
|
var fromParts, toParts, i;
|
650
1505
|
|
651
1506
|
fromParts = splitPath( from );
|