1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | import * as fs from 'fs';
|
12 |
|
13 |
|
14 |
|
15 | var absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|\/])/;
|
16 | var relativePath = /^\.?\.\//;
|
17 |
|
18 | function isAbsolute ( path ) {
|
19 | return absolutePath.test( path );
|
20 | }
|
21 |
|
22 | function isRelative ( path ) {
|
23 | return relativePath.test( path );
|
24 | }
|
25 |
|
26 | function basename ( path ) {
|
27 | return path.split( /(\/|\\)/ ).pop();
|
28 | }
|
29 |
|
30 | function dirname ( path ) {
|
31 | var match = /(\/|\\)[^\/\\]*$/.exec( path );
|
32 | if ( !match ) return '.';
|
33 |
|
34 | var dir = path.slice( 0, -match[0].length );
|
35 |
|
36 |
|
37 | return dir ? dir : '/';
|
38 | }
|
39 |
|
40 | function extname ( path ) {
|
41 | var match = /\.[^\.]+$/.exec( basename( path ) );
|
42 | if ( !match ) return '';
|
43 | return match[0];
|
44 | }
|
45 |
|
46 | function relative ( from, to ) {
|
47 | var fromParts = from.split( /[\/\\]/ ).filter( Boolean );
|
48 | var toParts = to.split( /[\/\\]/ ).filter( Boolean );
|
49 |
|
50 | while ( fromParts[0] && toParts[0] && fromParts[0] === toParts[0] ) {
|
51 | fromParts.shift();
|
52 | toParts.shift();
|
53 | }
|
54 |
|
55 | while ( toParts[0] === '.' || toParts[0] === '..' ) {
|
56 | var toPart = toParts.shift();
|
57 | if ( toPart === '..' ) {
|
58 | fromParts.pop();
|
59 | }
|
60 | }
|
61 |
|
62 | while ( fromParts.pop() ) {
|
63 | toParts.unshift( '..' );
|
64 | }
|
65 |
|
66 | return toParts.join( '/' );
|
67 | }
|
68 |
|
69 | function resolve () {
|
70 | var paths = [], len = arguments.length;
|
71 | while ( len-- ) paths[ len ] = arguments[ len ];
|
72 |
|
73 | var resolvedParts = paths.shift().split( /[\/\\]/ );
|
74 |
|
75 | paths.forEach( function (path) {
|
76 | if ( isAbsolute( path ) ) {
|
77 | resolvedParts = path.split( /[\/\\]/ );
|
78 | } else {
|
79 | var parts = path.split( /[\/\\]/ );
|
80 |
|
81 | while ( parts[0] === '.' || parts[0] === '..' ) {
|
82 | var part = parts.shift();
|
83 | if ( part === '..' ) {
|
84 | resolvedParts.pop();
|
85 | }
|
86 | }
|
87 |
|
88 | resolvedParts.push.apply( resolvedParts, parts );
|
89 | }
|
90 | });
|
91 |
|
92 | return resolvedParts.join( '/' );
|
93 | }
|
94 |
|
95 | function mkdirpath ( path ) {
|
96 | var dir = dirname( path );
|
97 | try {
|
98 | fs.readdirSync( dir );
|
99 | } catch ( err ) {
|
100 | mkdirpath( dir );
|
101 | fs.mkdirSync( dir );
|
102 | }
|
103 | }
|
104 |
|
105 | function isFile ( file ) {
|
106 | try {
|
107 | var stats = fs.statSync( file );
|
108 | return stats.isFile();
|
109 | } catch ( err ) {
|
110 | return false;
|
111 | }
|
112 | }
|
113 |
|
114 | function writeFile ( dest, data ) {
|
115 | return new Promise( function ( fulfil, reject ) {
|
116 | mkdirpath( dest );
|
117 |
|
118 | fs.writeFile( dest, data, function (err) {
|
119 | if ( err ) {
|
120 | reject( err );
|
121 | } else {
|
122 | fulfil();
|
123 | }
|
124 | });
|
125 | });
|
126 | }
|
127 |
|
128 | var readFileSync = fs.readFileSync;
|
129 |
|
130 | var keys = Object.keys;
|
131 |
|
132 | function blank () {
|
133 | return Object.create( null );
|
134 | }
|
135 |
|
136 | function forOwn ( object, func ) {
|
137 | Object.keys( object ).forEach( function (key) { return func( object[ key ], key ); } );
|
138 | }
|
139 |
|
140 | function assign ( target ) {
|
141 | var sources = [], len = arguments.length - 1;
|
142 | while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
|
143 |
|
144 | sources.forEach( function (source) {
|
145 | for ( var key in source ) {
|
146 | if ( source.hasOwnProperty( key ) ) target[ key ] = source[ key ];
|
147 | }
|
148 | });
|
149 |
|
150 | return target;
|
151 | }
|
152 |
|
153 | function mapSequence ( array, fn ) {
|
154 | var results = [];
|
155 | var promise = Promise.resolve();
|
156 |
|
157 | function next ( member, i ) {
|
158 | return fn( member ).then( function (value) { return results[i] = value; } );
|
159 | }
|
160 |
|
161 | var loop = function ( i ) {
|
162 | promise = promise.then( function () { return next( array[i], i ); } );
|
163 | };
|
164 |
|
165 | for ( var i = 0; i < array.length; i += 1 ) loop( i );
|
166 |
|
167 | return promise.then( function () { return results; } );
|
168 | }
|
169 |
|
170 | function validateKeys ( object, allowedKeys ) {
|
171 | var actualKeys = keys( object );
|
172 |
|
173 | var i = actualKeys.length;
|
174 |
|
175 | while ( i-- ) {
|
176 | var key = actualKeys[i];
|
177 |
|
178 | if ( allowedKeys.indexOf( key ) === -1 ) {
|
179 | return new Error(
|
180 | ("Unexpected key '" + key + "' found, expected one of: " + (allowedKeys.join( ', ' )))
|
181 | );
|
182 | }
|
183 | }
|
184 | }
|
185 |
|
186 |
|
187 |
|
188 | var SOURCEMAPPING_URL = 'sourceMa';
|
189 | SOURCEMAPPING_URL += 'ppingURL';
|
190 |
|
191 | var SOURCEMAPPING_URL$1 = SOURCEMAPPING_URL;
|
192 |
|
193 | var charToInteger = {};
|
194 | var integerToChar = {};
|
195 |
|
196 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
|
197 | charToInteger[ char ] = i;
|
198 | integerToChar[ i ] = char;
|
199 | });
|
200 |
|
201 | function encode ( value ) {
|
202 | var result, i;
|
203 |
|
204 | if ( typeof value === 'number' ) {
|
205 | result = encodeInteger( value );
|
206 | } else {
|
207 | result = '';
|
208 | for ( i = 0; i < value.length; i += 1 ) {
|
209 | result += encodeInteger( value[i] );
|
210 | }
|
211 | }
|
212 |
|
213 | return result;
|
214 | }
|
215 |
|
216 | function encodeInteger ( num ) {
|
217 | var result = '', clamped;
|
218 |
|
219 | if ( num < 0 ) {
|
220 | num = ( -num << 1 ) | 1;
|
221 | } else {
|
222 | num <<= 1;
|
223 | }
|
224 |
|
225 | do {
|
226 | clamped = num & 31;
|
227 | num >>= 5;
|
228 |
|
229 | if ( num > 0 ) {
|
230 | clamped |= 32;
|
231 | }
|
232 |
|
233 | result += integerToChar[ clamped ];
|
234 | } while ( num > 0 );
|
235 |
|
236 | return result;
|
237 | }
|
238 |
|
239 | function Chunk ( start, end, content ) {
|
240 | this.start = start;
|
241 | this.end = end;
|
242 | this.original = content;
|
243 |
|
244 | this.intro = '';
|
245 | this.outro = '';
|
246 |
|
247 | this.content = content;
|
248 | this.storeName = false;
|
249 | this.edited = false;
|
250 |
|
251 |
|
252 | Object.defineProperties( this, {
|
253 | previous: { writable: true, value: null },
|
254 | next: { writable: true, value: null }
|
255 | });
|
256 | }
|
257 |
|
258 | Chunk.prototype = {
|
259 | append: function append ( content ) {
|
260 | this.outro += content;
|
261 | },
|
262 |
|
263 | clone: function clone () {
|
264 | var chunk = new Chunk( this.start, this.end, this.original );
|
265 |
|
266 | chunk.intro = this.intro;
|
267 | chunk.outro = this.outro;
|
268 | chunk.content = this.content;
|
269 | chunk.storeName = this.storeName;
|
270 | chunk.edited = this.edited;
|
271 |
|
272 | return chunk;
|
273 | },
|
274 |
|
275 | contains: function contains ( index ) {
|
276 | return this.start < index && index < this.end;
|
277 | },
|
278 |
|
279 | eachNext: function eachNext ( fn ) {
|
280 | var chunk = this;
|
281 | while ( chunk ) {
|
282 | fn( chunk );
|
283 | chunk = chunk.next;
|
284 | }
|
285 | },
|
286 |
|
287 | eachPrevious: function eachPrevious ( fn ) {
|
288 | var chunk = this;
|
289 | while ( chunk ) {
|
290 | fn( chunk );
|
291 | chunk = chunk.previous;
|
292 | }
|
293 | },
|
294 |
|
295 | edit: function edit ( content, storeName ) {
|
296 | this.content = content;
|
297 | this.storeName = storeName;
|
298 |
|
299 | this.edited = true;
|
300 |
|
301 | return this;
|
302 | },
|
303 |
|
304 | prepend: function prepend ( content ) {
|
305 | this.intro = content + this.intro;
|
306 | },
|
307 |
|
308 | split: function split ( index ) {
|
309 | var sliceIndex = index - this.start;
|
310 |
|
311 | var originalBefore = this.original.slice( 0, sliceIndex );
|
312 | var originalAfter = this.original.slice( sliceIndex );
|
313 |
|
314 | this.original = originalBefore;
|
315 |
|
316 | var newChunk = new Chunk( index, this.end, originalAfter );
|
317 | newChunk.outro = this.outro;
|
318 | this.outro = '';
|
319 |
|
320 | this.end = index;
|
321 |
|
322 | if ( this.edited ) {
|
323 |
|
324 | newChunk.edit( '', false );
|
325 | this.content = '';
|
326 | } else {
|
327 | this.content = originalBefore;
|
328 | }
|
329 |
|
330 | newChunk.next = this.next;
|
331 | if ( newChunk.next ) newChunk.next.previous = newChunk;
|
332 | newChunk.previous = this;
|
333 | this.next = newChunk;
|
334 |
|
335 | return newChunk;
|
336 | },
|
337 |
|
338 | toString: function toString () {
|
339 | return this.intro + this.content + this.outro;
|
340 | },
|
341 |
|
342 | trimEnd: function trimEnd ( rx ) {
|
343 | this.outro = this.outro.replace( rx, '' );
|
344 | if ( this.outro.length ) return true;
|
345 |
|
346 | var trimmed = this.content.replace( rx, '' );
|
347 |
|
348 | if ( trimmed.length ) {
|
349 | if ( trimmed !== this.content ) {
|
350 | this.split( this.start + trimmed.length ).edit( '', false );
|
351 | }
|
352 |
|
353 | return true;
|
354 | } else {
|
355 | this.edit( '', false );
|
356 |
|
357 | this.intro = this.intro.replace( rx, '' );
|
358 | if ( this.intro.length ) return true;
|
359 | }
|
360 | },
|
361 |
|
362 | trimStart: function trimStart ( rx ) {
|
363 | this.intro = this.intro.replace( rx, '' );
|
364 | if ( this.intro.length ) return true;
|
365 |
|
366 | var trimmed = this.content.replace( rx, '' );
|
367 |
|
368 | if ( trimmed.length ) {
|
369 | if ( trimmed !== this.content ) {
|
370 | this.split( this.end - trimmed.length );
|
371 | this.edit( '', false );
|
372 | }
|
373 |
|
374 | return true;
|
375 | } else {
|
376 | this.edit( '', false );
|
377 |
|
378 | this.outro = this.outro.replace( rx, '' );
|
379 | if ( this.outro.length ) return true;
|
380 | }
|
381 | }
|
382 | };
|
383 |
|
384 | var _btoa;
|
385 |
|
386 | if ( typeof window !== 'undefined' && typeof window.btoa === 'function' ) {
|
387 | _btoa = window.btoa;
|
388 | } else if ( typeof Buffer === 'function' ) {
|
389 | _btoa = function (str) { return new Buffer( str ).toString( 'base64' ); };
|
390 | } else {
|
391 | _btoa = function () {
|
392 | throw new Error( 'Unsupported environment: `window.btoa` or `Buffer` should be supported.' );
|
393 | };
|
394 | }
|
395 |
|
396 | var btoa = _btoa;
|
397 |
|
398 | function SourceMap ( properties ) {
|
399 | this.version = 3;
|
400 |
|
401 | this.file = properties.file;
|
402 | this.sources = properties.sources;
|
403 | this.sourcesContent = properties.sourcesContent;
|
404 | this.names = properties.names;
|
405 | this.mappings = properties.mappings;
|
406 | }
|
407 |
|
408 | SourceMap.prototype = {
|
409 | toString: function toString () {
|
410 | return JSON.stringify( this );
|
411 | },
|
412 |
|
413 | toUrl: function toUrl () {
|
414 | return 'data:application/json;charset=utf-8;base64,' + btoa( this.toString() );
|
415 | }
|
416 | };
|
417 |
|
418 | function guessIndent ( code ) {
|
419 | var lines = code.split( '\n' );
|
420 |
|
421 | var tabbed = lines.filter( function (line) { return /^\t+/.test( line ); } );
|
422 | var spaced = lines.filter( function (line) { return /^ {2,}/.test( line ); } );
|
423 |
|
424 | if ( tabbed.length === 0 && spaced.length === 0 ) {
|
425 | return null;
|
426 | }
|
427 |
|
428 |
|
429 |
|
430 |
|
431 | if ( tabbed.length >= spaced.length ) {
|
432 | return '\t';
|
433 | }
|
434 |
|
435 |
|
436 | var min = spaced.reduce( function ( previous, current ) {
|
437 | var numSpaces = /^ +/.exec( current )[0].length;
|
438 | return Math.min( numSpaces, previous );
|
439 | }, Infinity );
|
440 |
|
441 | return new Array( min + 1 ).join( ' ' );
|
442 | }
|
443 |
|
444 | function getLocator ( source ) {
|
445 | var originalLines = source.split( '\n' );
|
446 |
|
447 | var start = 0;
|
448 | var lineRanges = originalLines.map( function ( line, i ) {
|
449 | var end = start + line.length + 1;
|
450 | var range = { start: start, end: end, line: i };
|
451 |
|
452 | start = end;
|
453 | return range;
|
454 | });
|
455 |
|
456 | var i = 0;
|
457 |
|
458 | function rangeContains ( range, index ) {
|
459 | return range.start <= index && index < range.end;
|
460 | }
|
461 |
|
462 | function getLocation ( range, index ) {
|
463 | return { line: range.line, column: index - range.start };
|
464 | }
|
465 |
|
466 | return function locate ( index ) {
|
467 | var range = lineRanges[i];
|
468 |
|
469 | var d = index >= range.end ? 1 : -1;
|
470 |
|
471 | while ( range ) {
|
472 | if ( rangeContains( range, index ) ) return getLocation( range, index );
|
473 |
|
474 | i += d;
|
475 | range = lineRanges[i];
|
476 | }
|
477 | };
|
478 | }
|
479 |
|
480 | var nonWhitespace = /\S/;
|
481 |
|
482 | function encodeMappings ( original, intro, outro, chunk, hires, sourcemapLocations, sourceIndex, offsets, names ) {
|
483 | var rawLines = [];
|
484 |
|
485 | var generatedCodeLine = intro.split( '\n' ).length - 1;
|
486 | var rawSegments = rawLines[ generatedCodeLine ] = [];
|
487 |
|
488 | var generatedCodeColumn = 0;
|
489 |
|
490 | var locate = getLocator( original );
|
491 |
|
492 | function addEdit ( content, original, loc, nameIndex, i ) {
|
493 | if ( i || ( content.length && nonWhitespace.test( content ) ) ) {
|
494 | rawSegments.push({
|
495 | generatedCodeLine: generatedCodeLine,
|
496 | generatedCodeColumn: generatedCodeColumn,
|
497 | sourceCodeLine: loc.line,
|
498 | sourceCodeColumn: loc.column,
|
499 | sourceCodeName: nameIndex,
|
500 | sourceIndex: sourceIndex
|
501 | });
|
502 | }
|
503 |
|
504 | var lines = content.split( '\n' );
|
505 | var lastLine = lines.pop();
|
506 |
|
507 | if ( lines.length ) {
|
508 | generatedCodeLine += lines.length;
|
509 | rawLines[ generatedCodeLine ] = rawSegments = [];
|
510 | generatedCodeColumn = lastLine.length;
|
511 | } else {
|
512 | generatedCodeColumn += lastLine.length;
|
513 | }
|
514 |
|
515 | lines = original.split( '\n' );
|
516 | lastLine = lines.pop();
|
517 |
|
518 | if ( lines.length ) {
|
519 | loc.line += lines.length;
|
520 | loc.column = lastLine.length;
|
521 | } else {
|
522 | loc.column += lastLine.length;
|
523 | }
|
524 | }
|
525 |
|
526 | function addUneditedChunk ( chunk, loc ) {
|
527 | var originalCharIndex = chunk.start;
|
528 | var first = true;
|
529 |
|
530 | while ( originalCharIndex < chunk.end ) {
|
531 | if ( hires || first || sourcemapLocations[ originalCharIndex ] ) {
|
532 | rawSegments.push({
|
533 | generatedCodeLine: generatedCodeLine,
|
534 | generatedCodeColumn: generatedCodeColumn,
|
535 | sourceCodeLine: loc.line,
|
536 | sourceCodeColumn: loc.column,
|
537 | sourceCodeName: -1,
|
538 | sourceIndex: sourceIndex
|
539 | });
|
540 | }
|
541 |
|
542 | if ( original[ originalCharIndex ] === '\n' ) {
|
543 | loc.line += 1;
|
544 | loc.column = 0;
|
545 | generatedCodeLine += 1;
|
546 | rawLines[ generatedCodeLine ] = rawSegments = [];
|
547 | generatedCodeColumn = 0;
|
548 | } else {
|
549 | loc.column += 1;
|
550 | generatedCodeColumn += 1;
|
551 | }
|
552 |
|
553 | originalCharIndex += 1;
|
554 | first = false;
|
555 | }
|
556 | }
|
557 |
|
558 | var hasContent = false;
|
559 |
|
560 | while ( chunk ) {
|
561 | var loc = locate( chunk.start );
|
562 |
|
563 | if ( chunk.intro.length ) {
|
564 | addEdit( chunk.intro, '', loc, -1, hasContent );
|
565 | }
|
566 |
|
567 | if ( chunk.edited ) {
|
568 | addEdit( chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1, hasContent );
|
569 | } else {
|
570 | addUneditedChunk( chunk, loc );
|
571 | }
|
572 |
|
573 | if ( chunk.outro.length ) {
|
574 | addEdit( chunk.outro, '', loc, -1, hasContent );
|
575 | }
|
576 |
|
577 | if ( chunk.content || chunk.intro || chunk.outro ) hasContent = true;
|
578 |
|
579 | var nextChunk = chunk.next;
|
580 | chunk = nextChunk;
|
581 | }
|
582 |
|
583 | offsets.sourceIndex = offsets.sourceIndex || 0;
|
584 | offsets.sourceCodeLine = offsets.sourceCodeLine || 0;
|
585 | offsets.sourceCodeColumn = offsets.sourceCodeColumn || 0;
|
586 | offsets.sourceCodeName = offsets.sourceCodeName || 0;
|
587 |
|
588 | var outroSemis = outro.split( '\n' ).map( function () { return ''; } ).join( ';' );
|
589 |
|
590 | var encoded = rawLines.map( function (segments) {
|
591 | var generatedCodeColumn = 0;
|
592 |
|
593 | return segments.map( function (segment) {
|
594 | var arr = [
|
595 | segment.generatedCodeColumn - generatedCodeColumn,
|
596 | segment.sourceIndex - offsets.sourceIndex,
|
597 | segment.sourceCodeLine - offsets.sourceCodeLine,
|
598 | segment.sourceCodeColumn - offsets.sourceCodeColumn
|
599 | ];
|
600 |
|
601 | generatedCodeColumn = segment.generatedCodeColumn;
|
602 | offsets.sourceIndex = segment.sourceIndex;
|
603 | offsets.sourceCodeLine = segment.sourceCodeLine;
|
604 | offsets.sourceCodeColumn = segment.sourceCodeColumn;
|
605 |
|
606 | if ( ~segment.sourceCodeName ) {
|
607 | arr.push( segment.sourceCodeName - offsets.sourceCodeName );
|
608 | offsets.sourceCodeName = segment.sourceCodeName;
|
609 | }
|
610 |
|
611 | return encode( arr );
|
612 | }).join( ',' );
|
613 | }).join( ';' ) + outroSemis;
|
614 |
|
615 | return encoded;
|
616 | }
|
617 |
|
618 | function getRelativePath ( from, to ) {
|
619 | var fromParts = from.split( /[\/\\]/ );
|
620 | var toParts = to.split( /[\/\\]/ );
|
621 |
|
622 | fromParts.pop();
|
623 |
|
624 | while ( fromParts[0] === toParts[0] ) {
|
625 | fromParts.shift();
|
626 | toParts.shift();
|
627 | }
|
628 |
|
629 | if ( fromParts.length ) {
|
630 | var i = fromParts.length;
|
631 | while ( i-- ) fromParts[i] = '..';
|
632 | }
|
633 |
|
634 | return fromParts.concat( toParts ).join( '/' );
|
635 | }
|
636 |
|
637 | var toString = Object.prototype.toString;
|
638 |
|
639 | function isObject ( thing ) {
|
640 | return toString.call( thing ) === '[object Object]';
|
641 | }
|
642 |
|
643 | function MagicString ( string, options ) {
|
644 | if ( options === void 0 ) options = {};
|
645 |
|
646 | var chunk = new Chunk( 0, string.length, string );
|
647 |
|
648 | Object.defineProperties( this, {
|
649 | original: { writable: true, value: string },
|
650 | outro: { writable: true, value: '' },
|
651 | intro: { writable: true, value: '' },
|
652 | firstChunk: { writable: true, value: chunk },
|
653 | lastChunk: { writable: true, value: chunk },
|
654 | lastSearchedChunk: { writable: true, value: chunk },
|
655 | byStart: { writable: true, value: {} },
|
656 | byEnd: { writable: true, value: {} },
|
657 | filename: { writable: true, value: options.filename },
|
658 | indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
659 | sourcemapLocations: { writable: true, value: {} },
|
660 | storedNames: { writable: true, value: {} },
|
661 | indentStr: { writable: true, value: guessIndent( string ) }
|
662 | });
|
663 |
|
664 | if ( false ) {}
|
665 |
|
666 | this.byStart[ 0 ] = chunk;
|
667 | this.byEnd[ string.length ] = chunk;
|
668 | }
|
669 |
|
670 | MagicString.prototype = {
|
671 | addSourcemapLocation: function addSourcemapLocation ( char ) {
|
672 | this.sourcemapLocations[ char ] = true;
|
673 | },
|
674 |
|
675 | append: function append ( content ) {
|
676 | if ( typeof content !== 'string' ) throw new TypeError( 'outro content must be a string' );
|
677 |
|
678 | this.outro += content;
|
679 | return this;
|
680 | },
|
681 |
|
682 | clone: function clone () {
|
683 | var cloned = new MagicString( this.original, { filename: this.filename });
|
684 |
|
685 | var originalChunk = this.firstChunk;
|
686 | var clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
|
687 |
|
688 | while ( originalChunk ) {
|
689 | cloned.byStart[ clonedChunk.start ] = clonedChunk;
|
690 | cloned.byEnd[ clonedChunk.end ] = clonedChunk;
|
691 |
|
692 | var nextOriginalChunk = originalChunk.next;
|
693 | var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
694 |
|
695 | if ( nextClonedChunk ) {
|
696 | clonedChunk.next = nextClonedChunk;
|
697 | nextClonedChunk.previous = clonedChunk;
|
698 |
|
699 | clonedChunk = nextClonedChunk;
|
700 | }
|
701 |
|
702 | originalChunk = nextOriginalChunk;
|
703 | }
|
704 |
|
705 | cloned.lastChunk = clonedChunk;
|
706 |
|
707 | if ( this.indentExclusionRanges ) {
|
708 | cloned.indentExclusionRanges = typeof this.indentExclusionRanges[0] === 'number' ?
|
709 | [ this.indentExclusionRanges[0], this.indentExclusionRanges[1] ] :
|
710 | this.indentExclusionRanges.map( function (range) { return [ range.start, range.end ]; } );
|
711 | }
|
712 |
|
713 | Object.keys( this.sourcemapLocations ).forEach( function (loc) {
|
714 | cloned.sourcemapLocations[ loc ] = true;
|
715 | });
|
716 |
|
717 | return cloned;
|
718 | },
|
719 |
|
720 | generateMap: function generateMap ( options ) {
|
721 | options = options || {};
|
722 |
|
723 | var names = Object.keys( this.storedNames );
|
724 |
|
725 | if ( false ) {}
|
726 | var map = new SourceMap({
|
727 | file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
|
728 | sources: [ options.source ? getRelativePath( options.file || '', options.source ) : null ],
|
729 | sourcesContent: options.includeContent ? [ this.original ] : [ null ],
|
730 | names: names,
|
731 | mappings: this.getMappings( options.hires, 0, {}, names )
|
732 | });
|
733 | if ( false ) {}
|
734 |
|
735 | return map;
|
736 | },
|
737 |
|
738 | getIndentString: function getIndentString () {
|
739 | return this.indentStr === null ? '\t' : this.indentStr;
|
740 | },
|
741 |
|
742 | getMappings: function getMappings ( hires, sourceIndex, offsets, names ) {
|
743 | return encodeMappings( this.original, this.intro, this.outro, this.firstChunk, hires, this.sourcemapLocations, sourceIndex, offsets, names );
|
744 | },
|
745 |
|
746 | indent: function indent ( indentStr, options ) {
|
747 | var this$1 = this;
|
748 |
|
749 | var pattern = /^[^\r\n]/gm;
|
750 |
|
751 | if ( isObject( indentStr ) ) {
|
752 | options = indentStr;
|
753 | indentStr = undefined;
|
754 | }
|
755 |
|
756 | indentStr = indentStr !== undefined ? indentStr : ( this.indentStr || '\t' );
|
757 |
|
758 | if ( indentStr === '' ) return this;
|
759 |
|
760 | options = options || {};
|
761 |
|
762 |
|
763 | var isExcluded = {};
|
764 |
|
765 | if ( options.exclude ) {
|
766 | var exclusions = typeof options.exclude[0] === 'number' ? [ options.exclude ] : options.exclude;
|
767 | exclusions.forEach( function (exclusion) {
|
768 | for ( var i = exclusion[0]; i < exclusion[1]; i += 1 ) {
|
769 | isExcluded[i] = true;
|
770 | }
|
771 | });
|
772 | }
|
773 |
|
774 | var shouldIndentNextCharacter = options.indentStart !== false;
|
775 | var replacer = function (match) {
|
776 | if ( shouldIndentNextCharacter ) return ("" + indentStr + match);
|
777 | shouldIndentNextCharacter = true;
|
778 | return match;
|
779 | };
|
780 |
|
781 | this.intro = this.intro.replace( pattern, replacer );
|
782 |
|
783 | var charIndex = 0;
|
784 |
|
785 | var chunk = this.firstChunk;
|
786 |
|
787 | while ( chunk ) {
|
788 | var end = chunk.end;
|
789 |
|
790 | if ( chunk.edited ) {
|
791 | if ( !isExcluded[ charIndex ] ) {
|
792 | chunk.content = chunk.content.replace( pattern, replacer );
|
793 |
|
794 | if ( chunk.content.length ) {
|
795 | shouldIndentNextCharacter = chunk.content[ chunk.content.length - 1 ] === '\n';
|
796 | }
|
797 | }
|
798 | } else {
|
799 | charIndex = chunk.start;
|
800 |
|
801 | while ( charIndex < end ) {
|
802 | if ( !isExcluded[ charIndex ] ) {
|
803 | var char = this$1.original[ charIndex ];
|
804 |
|
805 | if ( char === '\n' ) {
|
806 | shouldIndentNextCharacter = true;
|
807 | } else if ( char !== '\r' && shouldIndentNextCharacter ) {
|
808 | shouldIndentNextCharacter = false;
|
809 |
|
810 | if ( charIndex === chunk.start ) {
|
811 | chunk.prepend( indentStr );
|
812 | } else {
|
813 | var rhs = chunk.split( charIndex );
|
814 | rhs.prepend( indentStr );
|
815 |
|
816 | this$1.byStart[ charIndex ] = rhs;
|
817 | this$1.byEnd[ charIndex ] = chunk;
|
818 |
|
819 | chunk = rhs;
|
820 | }
|
821 | }
|
822 | }
|
823 |
|
824 | charIndex += 1;
|
825 | }
|
826 | }
|
827 |
|
828 | charIndex = chunk.end;
|
829 | chunk = chunk.next;
|
830 | }
|
831 |
|
832 | this.outro = this.outro.replace( pattern, replacer );
|
833 |
|
834 | return this;
|
835 | },
|
836 |
|
837 | insert: function insert () {
|
838 | throw new Error( 'magicString.insert(...) is deprecated. Use insertRight(...) or insertLeft(...)' );
|
839 | },
|
840 |
|
841 | insertLeft: function insertLeft ( index, content ) {
|
842 | if ( typeof content !== 'string' ) throw new TypeError( 'inserted content must be a string' );
|
843 |
|
844 | if ( false ) {}
|
845 |
|
846 | this._split( index );
|
847 |
|
848 | var chunk = this.byEnd[ index ];
|
849 |
|
850 | if ( chunk ) {
|
851 | chunk.append( content );
|
852 | } else {
|
853 | this.intro += content;
|
854 | }
|
855 |
|
856 | if ( false ) {}
|
857 | return this;
|
858 | },
|
859 |
|
860 | insertRight: function insertRight ( index, content ) {
|
861 | if ( typeof content !== 'string' ) throw new TypeError( 'inserted content must be a string' );
|
862 |
|
863 | if ( false ) {}
|
864 |
|
865 | this._split( index );
|
866 |
|
867 | var chunk = this.byStart[ index ];
|
868 |
|
869 | if ( chunk ) {
|
870 | chunk.prepend( content );
|
871 | } else {
|
872 | this.outro += content;
|
873 | }
|
874 |
|
875 | if ( false ) {}
|
876 | return this;
|
877 | },
|
878 |
|
879 | move: function move ( start, end, index ) {
|
880 | if ( index >= start && index <= end ) throw new Error( 'Cannot move a selection inside itself' );
|
881 |
|
882 | if ( false ) {}
|
883 |
|
884 | this._split( start );
|
885 | this._split( end );
|
886 | this._split( index );
|
887 |
|
888 | var first = this.byStart[ start ];
|
889 | var last = this.byEnd[ end ];
|
890 |
|
891 | var oldLeft = first.previous;
|
892 | var oldRight = last.next;
|
893 |
|
894 | var newRight = this.byStart[ index ];
|
895 | if ( !newRight && last === this.lastChunk ) return this;
|
896 | var newLeft = newRight ? newRight.previous : this.lastChunk;
|
897 |
|
898 | if ( oldLeft ) oldLeft.next = oldRight;
|
899 | if ( oldRight ) oldRight.previous = oldLeft;
|
900 |
|
901 | if ( newLeft ) newLeft.next = first;
|
902 | if ( newRight ) newRight.previous = last;
|
903 |
|
904 | if ( !first.previous ) this.firstChunk = last.next;
|
905 | if ( !last.next ) {
|
906 | this.lastChunk = first.previous;
|
907 | this.lastChunk.next = null;
|
908 | }
|
909 |
|
910 | first.previous = newLeft;
|
911 | last.next = newRight;
|
912 |
|
913 | if ( !newLeft ) this.firstChunk = first;
|
914 | if ( !newRight ) this.lastChunk = last;
|
915 |
|
916 | if ( false ) {}
|
917 | return this;
|
918 | },
|
919 |
|
920 | overwrite: function overwrite ( start, end, content, storeName ) {
|
921 | var this$1 = this;
|
922 |
|
923 | if ( typeof content !== 'string' ) throw new TypeError( 'replacement content must be a string' );
|
924 |
|
925 | while ( start < 0 ) start += this$1.original.length;
|
926 | while ( end < 0 ) end += this$1.original.length;
|
927 |
|
928 | if ( end > this.original.length ) throw new Error( 'end is out of bounds' );
|
929 | if ( start === end ) throw new Error( 'Cannot overwrite a zero-length range – use insertLeft or insertRight instead' );
|
930 |
|
931 | if ( false ) {}
|
932 |
|
933 | this._split( start );
|
934 | this._split( end );
|
935 |
|
936 | if ( storeName ) {
|
937 | var original = this.original.slice( start, end );
|
938 | this.storedNames[ original ] = true;
|
939 | }
|
940 |
|
941 | var first = this.byStart[ start ];
|
942 | var last = this.byEnd[ end ];
|
943 |
|
944 | if ( first ) {
|
945 | first.edit( content, storeName );
|
946 |
|
947 | if ( first !== last ) {
|
948 | first.outro = '';
|
949 |
|
950 | var chunk = first.next;
|
951 | while ( chunk !== last ) {
|
952 | chunk.edit( '', false );
|
953 | chunk.intro = chunk.outro = '';
|
954 | chunk = chunk.next;
|
955 | }
|
956 |
|
957 | chunk.edit( '', false );
|
958 | chunk.intro = '';
|
959 | }
|
960 | }
|
961 |
|
962 | else {
|
963 |
|
964 | var newChunk = new Chunk( start, end, '' ).edit( content, storeName );
|
965 |
|
966 |
|
967 | last.next = newChunk;
|
968 | newChunk.previous = last;
|
969 | }
|
970 |
|
971 | if ( false ) {}
|
972 | return this;
|
973 | },
|
974 |
|
975 | prepend: function prepend ( content ) {
|
976 | if ( typeof content !== 'string' ) throw new TypeError( 'outro content must be a string' );
|
977 |
|
978 | this.intro = content + this.intro;
|
979 | return this;
|
980 | },
|
981 |
|
982 | remove: function remove ( start, end ) {
|
983 | var this$1 = this;
|
984 |
|
985 | while ( start < 0 ) start += this$1.original.length;
|
986 | while ( end < 0 ) end += this$1.original.length;
|
987 |
|
988 | if ( start === end ) return this;
|
989 |
|
990 | if ( start < 0 || end > this.original.length ) throw new Error( 'Character is out of bounds' );
|
991 | if ( start > end ) throw new Error( 'end must be greater than start' );
|
992 |
|
993 | return this.overwrite( start, end, '', false );
|
994 | },
|
995 |
|
996 | slice: function slice ( start, end ) {
|
997 | var this$1 = this;
|
998 | if ( start === void 0 ) start = 0;
|
999 | if ( end === void 0 ) end = this.original.length;
|
1000 |
|
1001 | while ( start < 0 ) start += this$1.original.length;
|
1002 | while ( end < 0 ) end += this$1.original.length;
|
1003 |
|
1004 | var result = '';
|
1005 |
|
1006 |
|
1007 | var chunk = this.firstChunk;
|
1008 | while ( chunk && ( chunk.start > start || chunk.end <= start ) ) {
|
1009 |
|
1010 |
|
1011 | if ( chunk.start < end && chunk.end >= end ) {
|
1012 | return result;
|
1013 | }
|
1014 |
|
1015 | chunk = chunk.next;
|
1016 | }
|
1017 |
|
1018 | if ( chunk && chunk.edited && chunk.start !== start ) throw new Error(("Cannot use replaced character " + start + " as slice start anchor."));
|
1019 |
|
1020 | var startChunk = chunk;
|
1021 | while ( chunk ) {
|
1022 | if ( chunk.intro && ( startChunk !== chunk || chunk.start === start ) ) {
|
1023 | result += chunk.intro;
|
1024 | }
|
1025 |
|
1026 | var containsEnd = chunk.start < end && chunk.end >= end;
|
1027 | if ( containsEnd && chunk.edited && chunk.end !== end ) throw new Error(("Cannot use replaced character " + end + " as slice end anchor."));
|
1028 |
|
1029 | var sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
1030 | var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
1031 |
|
1032 | result += chunk.content.slice( sliceStart, sliceEnd );
|
1033 |
|
1034 | if ( chunk.outro && ( !containsEnd || chunk.end === end ) ) {
|
1035 | result += chunk.outro;
|
1036 | }
|
1037 |
|
1038 | if ( containsEnd ) {
|
1039 | break;
|
1040 | }
|
1041 |
|
1042 | chunk = chunk.next;
|
1043 | }
|
1044 |
|
1045 | return result;
|
1046 | },
|
1047 |
|
1048 |
|
1049 | snip: function snip ( start, end ) {
|
1050 | var clone = this.clone();
|
1051 | clone.remove( 0, start );
|
1052 | clone.remove( end, clone.original.length );
|
1053 |
|
1054 | return clone;
|
1055 | },
|
1056 |
|
1057 | _split: function _split ( index ) {
|
1058 | var this$1 = this;
|
1059 |
|
1060 | if ( this.byStart[ index ] || this.byEnd[ index ] ) return;
|
1061 |
|
1062 | if ( false ) {}
|
1063 |
|
1064 | var chunk = this.lastSearchedChunk;
|
1065 | var searchForward = index > chunk.end;
|
1066 |
|
1067 | while ( true ) {
|
1068 | if ( chunk.contains( index ) ) return this$1._splitChunk( chunk, index );
|
1069 |
|
1070 | chunk = searchForward ?
|
1071 | this$1.byStart[ chunk.end ] :
|
1072 | this$1.byEnd[ chunk.start ];
|
1073 | }
|
1074 | },
|
1075 |
|
1076 | _splitChunk: function _splitChunk ( chunk, index ) {
|
1077 | if ( chunk.edited && chunk.content.length ) {
|
1078 | var loc = getLocator( this.original )( index );
|
1079 | throw new Error( ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")") );
|
1080 | }
|
1081 |
|
1082 | var newChunk = chunk.split( index );
|
1083 |
|
1084 | this.byEnd[ index ] = chunk;
|
1085 | this.byStart[ index ] = newChunk;
|
1086 | this.byEnd[ newChunk.end ] = newChunk;
|
1087 |
|
1088 | if ( chunk === this.lastChunk ) this.lastChunk = newChunk;
|
1089 |
|
1090 | this.lastSearchedChunk = chunk;
|
1091 | if ( false ) {}
|
1092 | return true;
|
1093 | },
|
1094 |
|
1095 | toString: function toString () {
|
1096 | var str = this.intro;
|
1097 |
|
1098 | var chunk = this.firstChunk;
|
1099 | while ( chunk ) {
|
1100 | str += chunk.toString();
|
1101 | chunk = chunk.next;
|
1102 | }
|
1103 |
|
1104 | return str + this.outro;
|
1105 | },
|
1106 |
|
1107 | trimLines: function trimLines () {
|
1108 | return this.trim('[\\r\\n]');
|
1109 | },
|
1110 |
|
1111 | trim: function trim ( charType ) {
|
1112 | return this.trimStart( charType ).trimEnd( charType );
|
1113 | },
|
1114 |
|
1115 | trimEnd: function trimEnd ( charType ) {
|
1116 | var this$1 = this;
|
1117 |
|
1118 | var rx = new RegExp( ( charType || '\\s' ) + '+$' );
|
1119 |
|
1120 | this.outro = this.outro.replace( rx, '' );
|
1121 | if ( this.outro.length ) return this;
|
1122 |
|
1123 | var chunk = this.lastChunk;
|
1124 |
|
1125 | do {
|
1126 | var end = chunk.end;
|
1127 | var aborted = chunk.trimEnd( rx );
|
1128 |
|
1129 |
|
1130 | if ( chunk.end !== end ) {
|
1131 | this$1.lastChunk = chunk.next;
|
1132 |
|
1133 | this$1.byEnd[ chunk.end ] = chunk;
|
1134 | this$1.byStart[ chunk.next.start ] = chunk.next;
|
1135 | }
|
1136 |
|
1137 | if ( aborted ) return this$1;
|
1138 | chunk = chunk.previous;
|
1139 | } while ( chunk );
|
1140 |
|
1141 | return this;
|
1142 | },
|
1143 |
|
1144 | trimStart: function trimStart ( charType ) {
|
1145 | var this$1 = this;
|
1146 |
|
1147 | var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
|
1148 |
|
1149 | this.intro = this.intro.replace( rx, '' );
|
1150 | if ( this.intro.length ) return this;
|
1151 |
|
1152 | var chunk = this.firstChunk;
|
1153 |
|
1154 | do {
|
1155 | var end = chunk.end;
|
1156 | var aborted = chunk.trimStart( rx );
|
1157 |
|
1158 | if ( chunk.end !== end ) {
|
1159 |
|
1160 | if ( chunk === this$1.lastChunk ) this$1.lastChunk = chunk.next;
|
1161 |
|
1162 | this$1.byEnd[ chunk.end ] = chunk;
|
1163 | this$1.byStart[ chunk.next.start ] = chunk.next;
|
1164 | }
|
1165 |
|
1166 | if ( aborted ) return this$1;
|
1167 | chunk = chunk.next;
|
1168 | } while ( chunk );
|
1169 |
|
1170 | return this;
|
1171 | }
|
1172 | };
|
1173 |
|
1174 | var hasOwnProp = Object.prototype.hasOwnProperty;
|
1175 |
|
1176 | function Bundle$1 ( options ) {
|
1177 | if ( options === void 0 ) options = {};
|
1178 |
|
1179 | this.intro = options.intro || '';
|
1180 | this.separator = options.separator !== undefined ? options.separator : '\n';
|
1181 |
|
1182 | this.sources = [];
|
1183 |
|
1184 | this.uniqueSources = [];
|
1185 | this.uniqueSourceIndexByFilename = {};
|
1186 | }
|
1187 |
|
1188 | Bundle$1.prototype = {
|
1189 | addSource: function addSource ( source ) {
|
1190 | if ( source instanceof MagicString ) {
|
1191 | return this.addSource({
|
1192 | content: source,
|
1193 | filename: source.filename,
|
1194 | separator: this.separator
|
1195 | });
|
1196 | }
|
1197 |
|
1198 | if ( !isObject( source ) || !source.content ) {
|
1199 | throw new Error( 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`' );
|
1200 | }
|
1201 |
|
1202 | [ 'filename', 'indentExclusionRanges', 'separator' ].forEach( function (option) {
|
1203 | if ( !hasOwnProp.call( source, option ) ) source[ option ] = source.content[ option ];
|
1204 | });
|
1205 |
|
1206 | if ( source.separator === undefined ) {
|
1207 | source.separator = this.separator;
|
1208 | }
|
1209 |
|
1210 | if ( source.filename ) {
|
1211 | if ( !hasOwnProp.call( this.uniqueSourceIndexByFilename, source.filename ) ) {
|
1212 | this.uniqueSourceIndexByFilename[ source.filename ] = this.uniqueSources.length;
|
1213 | this.uniqueSources.push({ filename: source.filename, content: source.content.original });
|
1214 | } else {
|
1215 | var uniqueSource = this.uniqueSources[ this.uniqueSourceIndexByFilename[ source.filename ] ];
|
1216 | if ( source.content.original !== uniqueSource.content ) {
|
1217 | throw new Error( ("Illegal source: same filename (" + (source.filename) + "), different contents") );
|
1218 | }
|
1219 | }
|
1220 | }
|
1221 |
|
1222 | this.sources.push( source );
|
1223 | return this;
|
1224 | },
|
1225 |
|
1226 | append: function append ( str, options ) {
|
1227 | this.addSource({
|
1228 | content: new MagicString( str ),
|
1229 | separator: ( options && options.separator ) || ''
|
1230 | });
|
1231 |
|
1232 | return this;
|
1233 | },
|
1234 |
|
1235 | clone: function clone () {
|
1236 | var bundle = new Bundle$1({
|
1237 | intro: this.intro,
|
1238 | separator: this.separator
|
1239 | });
|
1240 |
|
1241 | this.sources.forEach( function (source) {
|
1242 | bundle.addSource({
|
1243 | filename: source.filename,
|
1244 | content: source.content.clone(),
|
1245 | separator: source.separator
|
1246 | });
|
1247 | });
|
1248 |
|
1249 | return bundle;
|
1250 | },
|
1251 |
|
1252 | generateMap: function generateMap ( options ) {
|
1253 | var this$1 = this;
|
1254 |
|
1255 | var offsets = {};
|
1256 |
|
1257 | var names = [];
|
1258 | this.sources.forEach( function (source) {
|
1259 | Object.keys( source.content.storedNames ).forEach( function (name) {
|
1260 | if ( !~names.indexOf( name ) ) names.push( name );
|
1261 | });
|
1262 | });
|
1263 |
|
1264 | var encoded = (
|
1265 | getSemis( this.intro ) +
|
1266 | this.sources.map( function ( source, i ) {
|
1267 | var prefix = ( i > 0 ) ? ( getSemis( source.separator ) || ',' ) : '';
|
1268 | var mappings;
|
1269 |
|
1270 |
|
1271 | if ( !source.filename ) {
|
1272 | mappings = getSemis( source.content.toString() );
|
1273 | } else {
|
1274 | var sourceIndex = this$1.uniqueSourceIndexByFilename[ source.filename ];
|
1275 | mappings = source.content.getMappings( options.hires, sourceIndex, offsets, names );
|
1276 | }
|
1277 |
|
1278 | return prefix + mappings;
|
1279 | }).join( '' )
|
1280 | );
|
1281 |
|
1282 | return new SourceMap({
|
1283 | file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
|
1284 | sources: this.uniqueSources.map( function (source) {
|
1285 | return options.file ? getRelativePath( options.file, source.filename ) : source.filename;
|
1286 | }),
|
1287 | sourcesContent: this.uniqueSources.map( function (source) {
|
1288 | return options.includeContent ? source.content : null;
|
1289 | }),
|
1290 | names: names,
|
1291 | mappings: encoded
|
1292 | });
|
1293 | },
|
1294 |
|
1295 | getIndentString: function getIndentString () {
|
1296 | var indentStringCounts = {};
|
1297 |
|
1298 | this.sources.forEach( function (source) {
|
1299 | var indentStr = source.content.indentStr;
|
1300 |
|
1301 | if ( indentStr === null ) return;
|
1302 |
|
1303 | if ( !indentStringCounts[ indentStr ] ) indentStringCounts[ indentStr ] = 0;
|
1304 | indentStringCounts[ indentStr ] += 1;
|
1305 | });
|
1306 |
|
1307 | return ( Object.keys( indentStringCounts ).sort( function ( a, b ) {
|
1308 | return indentStringCounts[a] - indentStringCounts[b];
|
1309 | })[0] ) || '\t';
|
1310 | },
|
1311 |
|
1312 | indent: function indent ( indentStr ) {
|
1313 | var this$1 = this;
|
1314 |
|
1315 | if ( !arguments.length ) {
|
1316 | indentStr = this.getIndentString();
|
1317 | }
|
1318 |
|
1319 | if ( indentStr === '' ) return this;
|
1320 |
|
1321 | var trailingNewline = !this.intro || this.intro.slice( -1 ) === '\n';
|
1322 |
|
1323 | this.sources.forEach( function ( source, i ) {
|
1324 | var separator = source.separator !== undefined ? source.separator : this$1.separator;
|
1325 | var indentStart = trailingNewline || ( i > 0 && /\r?\n$/.test( separator ) );
|
1326 |
|
1327 | source.content.indent( indentStr, {
|
1328 | exclude: source.indentExclusionRanges,
|
1329 | indentStart: indentStart
|
1330 | });
|
1331 |
|
1332 |
|
1333 | trailingNewline = source.content.toString().slice( 0, -1 ) === '\n';
|
1334 | });
|
1335 |
|
1336 | if ( this.intro ) {
|
1337 | this.intro = indentStr + this.intro.replace( /^[^\n]/gm, function ( match, index ) {
|
1338 | return index > 0 ? indentStr + match : match;
|
1339 | });
|
1340 | }
|
1341 |
|
1342 | return this;
|
1343 | },
|
1344 |
|
1345 | prepend: function prepend ( str ) {
|
1346 | this.intro = str + this.intro;
|
1347 | return this;
|
1348 | },
|
1349 |
|
1350 | toString: function toString () {
|
1351 | var this$1 = this;
|
1352 |
|
1353 | var body = this.sources.map( function ( source, i ) {
|
1354 | var separator = source.separator !== undefined ? source.separator : this$1.separator;
|
1355 | var str = ( i > 0 ? separator : '' ) + source.content.toString();
|
1356 |
|
1357 | return str;
|
1358 | }).join( '' );
|
1359 |
|
1360 | return this.intro + body;
|
1361 | },
|
1362 |
|
1363 | trimLines: function trimLines () {
|
1364 | return this.trim('[\\r\\n]');
|
1365 | },
|
1366 |
|
1367 | trim: function trim ( charType ) {
|
1368 | return this.trimStart( charType ).trimEnd( charType );
|
1369 | },
|
1370 |
|
1371 | trimStart: function trimStart ( charType ) {
|
1372 | var this$1 = this;
|
1373 |
|
1374 | var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
|
1375 | this.intro = this.intro.replace( rx, '' );
|
1376 |
|
1377 | if ( !this.intro ) {
|
1378 | var source;
|
1379 | var i = 0;
|
1380 |
|
1381 | do {
|
1382 | source = this$1.sources[i];
|
1383 |
|
1384 | if ( !source ) {
|
1385 | break;
|
1386 | }
|
1387 |
|
1388 | source.content.trimStart( charType );
|
1389 | i += 1;
|
1390 | } while ( source.content.toString() === '' );
|
1391 | }
|
1392 |
|
1393 | return this;
|
1394 | },
|
1395 |
|
1396 | trimEnd: function trimEnd ( charType ) {
|
1397 | var this$1 = this;
|
1398 |
|
1399 | var rx = new RegExp( ( charType || '\\s' ) + '+$' );
|
1400 |
|
1401 | var source;
|
1402 | var i = this.sources.length - 1;
|
1403 |
|
1404 | do {
|
1405 | source = this$1.sources[i];
|
1406 |
|
1407 | if ( !source ) {
|
1408 | this$1.intro = this$1.intro.replace( rx, '' );
|
1409 | break;
|
1410 | }
|
1411 |
|
1412 | source.content.trimEnd( charType );
|
1413 | i -= 1;
|
1414 | } while ( source.content.toString() === '' );
|
1415 |
|
1416 | return this;
|
1417 | }
|
1418 | };
|
1419 |
|
1420 | function getSemis ( str ) {
|
1421 | return new Array( str.split( '\n' ).length ).join( ';' );
|
1422 | }
|
1423 |
|
1424 |
|
1425 |
|
1426 | function first ( candidates ) {
|
1427 | return function () {
|
1428 | var args = [], len = arguments.length;
|
1429 | while ( len-- ) args[ len ] = arguments[ len ];
|
1430 |
|
1431 | return candidates.reduce( function ( promise, candidate ) {
|
1432 | return promise.then( function (result) { return result != null ?
|
1433 | result :
|
1434 | Promise.resolve( candidate.apply( void 0, args ) ); } );
|
1435 | }, Promise.resolve() );
|
1436 | };
|
1437 | }
|
1438 |
|
1439 | function find ( array, fn ) {
|
1440 | for ( var i = 0; i < array.length; i += 1 ) {
|
1441 | if ( fn( array[i], i ) ) return array[i];
|
1442 | }
|
1443 |
|
1444 | return null;
|
1445 | }
|
1446 |
|
1447 |
|
1448 |
|
1449 | var reservedWords = {
|
1450 | 3: "abstract boolean byte char class double enum export extends final float goto implements import int interface long native package private protected public short static super synchronized throws transient volatile",
|
1451 | 5: "class enum extends super const export import",
|
1452 | 6: "enum",
|
1453 | 7: "enum",
|
1454 | strict: "implements interface let package private protected public static yield",
|
1455 | strictBind: "eval arguments"
|
1456 | }
|
1457 |
|
1458 |
|
1459 |
|
1460 | var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this"
|
1461 |
|
1462 | var keywords = {
|
1463 | 5: ecma5AndLessKeywords,
|
1464 | 6: ecma5AndLessKeywords + " const class extends export import super"
|
1465 | }
|
1466 |
|
1467 |
|
1468 |
|
1469 |
|
1470 |
|
1471 |
|
1472 |
|
1473 |
|
1474 |
|
1475 | var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0-\u08b4\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e87\u0e88\u0e8a\u0e8d\u0e94-\u0e97\u0e99-\u0e9f\u0ea1-\u0ea3\u0ea5\u0ea7\u0eaa\u0eab\u0ead-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1877\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1ce9-\u1cec\u1cee-\u1cf1\u1cf5\u1cf6\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312d\u3131-\u318e\u31a0-\u31ba\u31f0-\u31ff\u3400-\u4db5\u4e00-\u9fd5\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7ad\ua7b0-\ua7b7\ua7f7-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab65\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc"
|
1476 | var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b56\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c03\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d01-\u0d03\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d82\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0eb9\u0ebb\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf2-\u1cf4\u1cf8\u1cf9\u1dc0-\u1df5\u1dfc-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua880\ua881\ua8b4-\ua8c4\ua8d0-\ua8d9\ua8e0-\ua8f1\ua900-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f"
|
1477 |
|
1478 | var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]")
|
1479 | var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]")
|
1480 |
|
1481 | nonASCIIidentifierStartChars = nonASCIIidentifierChars = null
|
1482 |
|
1483 |
|
1484 |
|
1485 |
|
1486 |
|
1487 |
|
1488 | var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,17,26,6,37,11,29,3,35,5,7,2,4,43,157,99,39,9,51,157,310,10,21,11,7,153,5,3,0,2,43,2,1,4,0,3,22,11,22,10,30,66,18,2,1,11,21,11,25,71,55,7,1,65,0,16,3,2,2,2,26,45,28,4,28,36,7,2,27,28,53,11,21,11,18,14,17,111,72,56,50,14,50,785,52,76,44,33,24,27,35,42,34,4,0,13,47,15,3,22,0,2,0,36,17,2,24,85,6,2,0,2,3,2,14,2,9,8,46,39,7,3,1,3,21,2,6,2,1,2,4,4,0,19,0,13,4,287,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,25,391,63,32,0,449,56,1288,921,103,110,18,195,2749,1070,4050,582,8634,568,8,30,114,29,19,47,17,3,32,20,6,18,881,68,12,0,67,12,16481,1,3071,106,6,12,4,8,8,9,5991,84,2,70,2,1,3,0,3,1,3,3,2,11,2,0,2,6,2,64,2,3,3,7,2,6,2,27,2,3,2,4,2,0,4,6,2,339,3,24,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,30,2,24,2,7,4149,196,1340,3,2,26,2,1,2,0,3,0,2,9,2,3,2,0,2,0,7,0,5,0,2,0,2,0,2,2,2,1,2,0,3,0,2,0,2,0,2,0,2,0,2,1,2,0,3,3,2,6,2,3,2,3,2,0,2,9,2,16,6,2,2,4,2,16,4421,42710,42,4148,12,221,3,5761,10591,541]
|
1489 | var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,1306,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,52,0,13,2,49,13,10,2,4,9,83,11,168,11,6,9,7,3,57,0,2,6,3,1,3,2,10,0,11,1,3,6,4,4,316,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,423,9,20855,9,135,4,60,6,26,9,1016,45,17,3,19723,1,5319,4,4,5,9,7,3,6,31,3,149,2,1418,49,513,54,5,49,9,0,15,0,23,4,2,14,3617,6,792618,239]
|
1490 |
|
1491 |
|
1492 |
|
1493 |
|
1494 | function isInAstralSet(code, set) {
|
1495 | var pos = 0x10000
|
1496 | for (var i = 0; i < set.length; i += 2) {
|
1497 | pos += set[i]
|
1498 | if (pos > code) return false
|
1499 | pos += set[i + 1]
|
1500 | if (pos >= code) return true
|
1501 | }
|
1502 | }
|
1503 |
|
1504 | // Test whether a given character code starts an identifier.
|
1505 |
|
1506 | function isIdentifierStart(code, astral) {
|
1507 | if (code < 65) return code === 36
|
1508 | if (code < 91) return true
|
1509 | if (code < 97) return code === 95
|
1510 | if (code < 123) return true
|
1511 | if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code))
|
1512 | if (astral === false) return false
|
1513 | return isInAstralSet(code, astralIdentifierStartCodes)
|
1514 | }
|
1515 |
|
1516 |
|
1517 |
|
1518 | function isIdentifierChar(code, astral) {
|
1519 | if (code < 48) return code === 36
|
1520 | if (code < 58) return true
|
1521 | if (code < 65) return false
|
1522 | if (code < 91) return true
|
1523 | if (code < 97) return code === 95
|
1524 | if (code < 123) return true
|
1525 | if (code <= 0xffff) return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code))
|
1526 | if (astral === false) return false
|
1527 | return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
|
1528 | }
|
1529 |
|
1530 |
|
1531 |
|
1532 |
|
1533 |
|
1534 |
|
1535 |
|
1536 |
|
1537 |
|
1538 |
|
1539 |
|
1540 |
|
1541 |
|
1542 |
|
1543 |
|
1544 |
|
1545 |
|
1546 |
|
1547 |
|
1548 |
|
1549 |
|
1550 |
|
1551 |
|
1552 |
|
1553 | var TokenType = function TokenType(label, conf) {
|
1554 | if ( conf === void 0 ) conf = {};
|
1555 |
|
1556 | this.label = label
|
1557 | this.keyword = conf.keyword
|
1558 | this.beforeExpr = !!conf.beforeExpr
|
1559 | this.startsExpr = !!conf.startsExpr
|
1560 | this.isLoop = !!conf.isLoop
|
1561 | this.isAssign = !!conf.isAssign
|
1562 | this.prefix = !!conf.prefix
|
1563 | this.postfix = !!conf.postfix
|
1564 | this.binop = conf.binop || null
|
1565 | this.updateContext = null
|
1566 | };
|
1567 |
|
1568 | function binop(name, prec) {
|
1569 | return new TokenType(name, {beforeExpr: true, binop: prec})
|
1570 | }
|
1571 | var beforeExpr = {beforeExpr: true};
|
1572 | var startsExpr = {startsExpr: true};
|
1573 | var tt = {
|
1574 | num: new TokenType("num", startsExpr),
|
1575 | regexp: new TokenType("regexp", startsExpr),
|
1576 | string: new TokenType("string", startsExpr),
|
1577 | name: new TokenType("name", startsExpr),
|
1578 | eof: new TokenType("eof"),
|
1579 |
|
1580 |
|
1581 | bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
|
1582 | bracketR: new TokenType("]"),
|
1583 | braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
|
1584 | braceR: new TokenType("}"),
|
1585 | parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
|
1586 | parenR: new TokenType(")"),
|
1587 | comma: new TokenType(",", beforeExpr),
|
1588 | semi: new TokenType(";", beforeExpr),
|
1589 | colon: new TokenType(":", beforeExpr),
|
1590 | dot: new TokenType("."),
|
1591 | question: new TokenType("?", beforeExpr),
|
1592 | arrow: new TokenType("=>", beforeExpr),
|
1593 | template: new TokenType("template"),
|
1594 | ellipsis: new TokenType("...", beforeExpr),
|
1595 | backQuote: new TokenType("`", startsExpr),
|
1596 | dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
|
1597 |
|
1598 |
|
1599 |
|
1600 |
|
1601 |
|
1602 |
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 |
|
1610 |
|
1611 |
|
1612 | eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
|
1613 | assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
|
1614 | incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
|
1615 | prefix: new TokenType("prefix", {beforeExpr: true, prefix: true, startsExpr: true}),
|
1616 | logicalOR: binop("||", 1),
|
1617 | logicalAND: binop("&&", 2),
|
1618 | bitwiseOR: binop("|", 3),
|
1619 | bitwiseXOR: binop("^", 4),
|
1620 | bitwiseAND: binop("&", 5),
|
1621 | equality: binop("==/!=", 6),
|
1622 | relational: binop("</>", 7),
|
1623 | bitShift: binop("<</>>", 8),
|
1624 | plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
|
1625 | modulo: binop("%", 10),
|
1626 | star: binop("*", 10),
|
1627 | slash: binop("/", 10),
|
1628 | starstar: new TokenType("**", {beforeExpr: true})
|
1629 | }
|
1630 |
|
1631 |
|
1632 |
|
1633 | var keywordTypes = {}
|
1634 |
|
1635 |
|
1636 | function kw(name, options) {
|
1637 | if ( options === void 0 ) options = {};
|
1638 |
|
1639 | options.keyword = name
|
1640 | keywordTypes[name] = tt["_" + name] = new TokenType(name, options)
|
1641 | }
|
1642 |
|
1643 | kw("break")
|
1644 | kw("case", beforeExpr)
|
1645 | kw("catch")
|
1646 | kw("continue")
|
1647 | kw("debugger")
|
1648 | kw("default", beforeExpr)
|
1649 | kw("do", {isLoop: true, beforeExpr: true})
|
1650 | kw("else", beforeExpr)
|
1651 | kw("finally")
|
1652 | kw("for", {isLoop: true})
|
1653 | kw("function", startsExpr)
|
1654 | kw("if")
|
1655 | kw("return", beforeExpr)
|
1656 | kw("switch")
|
1657 | kw("throw", beforeExpr)
|
1658 | kw("try")
|
1659 | kw("var")
|
1660 | kw("const")
|
1661 | kw("while", {isLoop: true})
|
1662 | kw("with")
|
1663 | kw("new", {beforeExpr: true, startsExpr: true})
|
1664 | kw("this", startsExpr)
|
1665 | kw("super", startsExpr)
|
1666 | kw("class")
|
1667 | kw("extends", beforeExpr)
|
1668 | kw("export")
|
1669 | kw("import")
|
1670 | kw("null", startsExpr)
|
1671 | kw("true", startsExpr)
|
1672 | kw("false", startsExpr)
|
1673 | kw("in", {beforeExpr: true, binop: 7})
|
1674 | kw("instanceof", {beforeExpr: true, binop: 7})
|
1675 | kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true})
|
1676 | kw("void", {beforeExpr: true, prefix: true, startsExpr: true})
|
1677 | kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
|
1678 |
|
1679 |
|
1680 |
|
1681 |
|
1682 | var lineBreak = /\r\n?|\n|\u2028|\u2029/
|
1683 | var lineBreakG = new RegExp(lineBreak.source, "g")
|
1684 |
|
1685 | function isNewLine(code) {
|
1686 | return code === 10 || code === 13 || code === 0x2028 || code == 0x2029
|
1687 | }
|
1688 |
|
1689 | var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/
|
1690 |
|
1691 | var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g
|
1692 |
|
1693 | function isArray(obj) {
|
1694 | return Object.prototype.toString.call(obj) === "[object Array]"
|
1695 | }
|
1696 |
|
1697 |
|
1698 |
|
1699 | function has(obj, propName) {
|
1700 | return Object.prototype.hasOwnProperty.call(obj, propName)
|
1701 | }
|
1702 |
|
1703 |
|
1704 |
|
1705 |
|
1706 | var Position = function Position(line, col) {
|
1707 | this.line = line
|
1708 | this.column = col
|
1709 | };
|
1710 |
|
1711 | Position.prototype.offset = function offset (n) {
|
1712 | return new Position(this.line, this.column + n)
|
1713 | };
|
1714 |
|
1715 | var SourceLocation = function SourceLocation(p, start, end) {
|
1716 | this.start = start
|
1717 | this.end = end
|
1718 | if (p.sourceFile !== null) this.source = p.sourceFile
|
1719 | };
|
1720 |
|
1721 |
|
1722 |
|
1723 |
|
1724 |
|
1725 |
|
1726 |
|
1727 | function getLineInfo(input, offset) {
|
1728 | for (var line = 1, cur = 0;;) {
|
1729 | lineBreakG.lastIndex = cur
|
1730 | var match = lineBreakG.exec(input)
|
1731 | if (match && match.index < offset) {
|
1732 | ++line
|
1733 | cur = match.index + match[0].length
|
1734 | } else {
|
1735 | return new Position(line, offset - cur)
|
1736 | }
|
1737 | }
|
1738 | }
|
1739 |
|
1740 |
|
1741 |
|
1742 |
|
1743 | var defaultOptions = {
|
1744 |
|
1745 |
|
1746 |
|
1747 |
|
1748 | ecmaVersion: 6,
|
1749 |
|
1750 | sourceType: "script",
|
1751 |
|
1752 |
|
1753 |
|
1754 |
|
1755 |
|
1756 | onInsertedSemicolon: null,
|
1757 |
|
1758 |
|
1759 | onTrailingComma: null,
|
1760 |
|
1761 |
|
1762 |
|
1763 |
|
1764 | allowReserved: null,
|
1765 |
|
1766 |
|
1767 | allowReturnOutsideFunction: false,
|
1768 |
|
1769 |
|
1770 | allowImportExportEverywhere: false,
|
1771 |
|
1772 |
|
1773 | allowHashBang: false,
|
1774 |
|
1775 |
|
1776 |
|
1777 |
|
1778 | locations: false,
|
1779 |
|
1780 |
|
1781 |
|
1782 |
|
1783 |
|
1784 | onToken: null,
|
1785 |
|
1786 |
|
1787 |
|
1788 |
|
1789 |
|
1790 |
|
1791 |
|
1792 |
|
1793 |
|
1794 |
|
1795 | onComment: null,
|
1796 |
|
1797 |
|
1798 |
|
1799 |
|
1800 |
|
1801 |
|
1802 |
|
1803 |
|
1804 | ranges: false,
|
1805 |
|
1806 |
|
1807 |
|
1808 |
|
1809 |
|
1810 | program: null,
|
1811 |
|
1812 |
|
1813 | sourceFile: null,
|
1814 |
|
1815 |
|
1816 | directSourceFile: null,
|
1817 |
|
1818 |
|
1819 | preserveParens: false,
|
1820 | plugins: {}
|
1821 | }
|
1822 |
|
1823 |
|
1824 |
|
1825 | function getOptions(opts) {
|
1826 | var options = {}
|
1827 | for (var opt in defaultOptions)
|
1828 | options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]
|
1829 | if (options.allowReserved == null)
|
1830 | options.allowReserved = options.ecmaVersion < 5
|
1831 |
|
1832 | if (isArray(options.onToken)) {
|
1833 | var tokens = options.onToken
|
1834 | options.onToken = function (token) { return tokens.push(token); }
|
1835 | }
|
1836 | if (isArray(options.onComment))
|
1837 | options.onComment = pushComment(options, options.onComment)
|
1838 |
|
1839 | return options
|
1840 | }
|
1841 |
|
1842 | function pushComment(options, array) {
|
1843 | return function (block, text, start, end, startLoc, endLoc) {
|
1844 | var comment = {
|
1845 | type: block ? 'Block' : 'Line',
|
1846 | value: text,
|
1847 | start: start,
|
1848 | end: end
|
1849 | }
|
1850 | if (options.locations)
|
1851 | comment.loc = new SourceLocation(this, startLoc, endLoc)
|
1852 | if (options.ranges)
|
1853 | comment.range = [start, end]
|
1854 | array.push(comment)
|
1855 | }
|
1856 | }
|
1857 |
|
1858 |
|
1859 | var plugins = {}
|
1860 |
|
1861 | function keywordRegexp(words) {
|
1862 | return new RegExp("^(" + words.replace(/ /g, "|") + ")$")
|
1863 | }
|
1864 |
|
1865 | var Parser = function Parser(options, input, startPos) {
|
1866 | this.options = options = getOptions(options)
|
1867 | this.sourceFile = options.sourceFile
|
1868 | this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5])
|
1869 | var reserved = options.allowReserved ? "" :
|
1870 | reservedWords[options.ecmaVersion] + (options.sourceType == "module" ? " await" : "")
|
1871 | this.reservedWords = keywordRegexp(reserved)
|
1872 | var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict
|
1873 | this.reservedWordsStrict = keywordRegexp(reservedStrict)
|
1874 | this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind)
|
1875 | this.input = String(input)
|
1876 |
|
1877 |
|
1878 |
|
1879 |
|
1880 | this.containsEsc = false
|
1881 |
|
1882 |
|
1883 | this.loadPlugins(options.plugins)
|
1884 |
|
1885 |
|
1886 |
|
1887 |
|
1888 | if (startPos) {
|
1889 | this.pos = startPos
|
1890 | this.lineStart = Math.max(0, this.input.lastIndexOf("\n", startPos))
|
1891 | this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length
|
1892 | } else {
|
1893 | this.pos = this.lineStart = 0
|
1894 | this.curLine = 1
|
1895 | }
|
1896 |
|
1897 |
|
1898 |
|
1899 | this.type = tt.eof
|
1900 |
|
1901 | this.value = null
|
1902 |
|
1903 | this.start = this.end = this.pos
|
1904 |
|
1905 |
|
1906 | this.startLoc = this.endLoc = this.curPosition()
|
1907 |
|
1908 |
|
1909 | this.lastTokEndLoc = this.lastTokStartLoc = null
|
1910 | this.lastTokStart = this.lastTokEnd = this.pos
|
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 | this.context = this.initialContext()
|
1916 | this.exprAllowed = true
|
1917 |
|
1918 |
|
1919 | this.strict = this.inModule = options.sourceType === "module"
|
1920 |
|
1921 |
|
1922 | this.potentialArrowAt = -1
|
1923 |
|
1924 |
|
1925 | this.inFunction = this.inGenerator = false
|
1926 |
|
1927 | this.labels = []
|
1928 |
|
1929 |
|
1930 | if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === '#!')
|
1931 | this.skipLineComment(2)
|
1932 | };
|
1933 |
|
1934 |
|
1935 | Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
|
1936 | Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
|
1937 |
|
1938 | Parser.prototype.extend = function extend (name, f) {
|
1939 | this[name] = f(this[name])
|
1940 | };
|
1941 |
|
1942 | Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
|
1943 | var this$1 = this;
|
1944 |
|
1945 | for (var name in pluginConfigs) {
|
1946 | var plugin = plugins[name]
|
1947 | if (!plugin) throw new Error("Plugin '" + name + "' not found")
|
1948 | plugin(this$1, pluginConfigs[name])
|
1949 | }
|
1950 | };
|
1951 |
|
1952 | Parser.prototype.parse = function parse () {
|
1953 | var node = this.options.program || this.startNode()
|
1954 | this.nextToken()
|
1955 | return this.parseTopLevel(node)
|
1956 | };
|
1957 |
|
1958 | var pp = Parser.prototype
|
1959 |
|
1960 |
|
1961 |
|
1962 |
|
1963 |
|
1964 | pp.isUseStrict = function(stmt) {
|
1965 | return this.options.ecmaVersion >= 5 && stmt.type === "ExpressionStatement" &&
|
1966 | stmt.expression.type === "Literal" &&
|
1967 | stmt.expression.raw.slice(1, -1) === "use strict"
|
1968 | }
|
1969 |
|
1970 |
|
1971 |
|
1972 |
|
1973 | pp.eat = function(type) {
|
1974 | if (this.type === type) {
|
1975 | this.next()
|
1976 | return true
|
1977 | } else {
|
1978 | return false
|
1979 | }
|
1980 | }
|
1981 |
|
1982 |
|
1983 |
|
1984 | pp.isContextual = function(name) {
|
1985 | return this.type === tt.name && this.value === name
|
1986 | }
|
1987 |
|
1988 |
|
1989 |
|
1990 | pp.eatContextual = function(name) {
|
1991 | return this.value === name && this.eat(tt.name)
|
1992 | }
|
1993 |
|
1994 |
|
1995 |
|
1996 | pp.expectContextual = function(name) {
|
1997 | if (!this.eatContextual(name)) this.unexpected()
|
1998 | }
|
1999 |
|
2000 |
|
2001 |
|
2002 | pp.canInsertSemicolon = function() {
|
2003 | return this.type === tt.eof ||
|
2004 | this.type === tt.braceR ||
|
2005 | lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
|
2006 | }
|
2007 |
|
2008 | pp.insertSemicolon = function() {
|
2009 | if (this.canInsertSemicolon()) {
|
2010 | if (this.options.onInsertedSemicolon)
|
2011 | this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc)
|
2012 | return true
|
2013 | }
|
2014 | }
|
2015 |
|
2016 |
|
2017 |
|
2018 |
|
2019 | pp.semicolon = function() {
|
2020 | if (!this.eat(tt.semi) && !this.insertSemicolon()) this.unexpected()
|
2021 | }
|
2022 |
|
2023 | pp.afterTrailingComma = function(tokType) {
|
2024 | if (this.type == tokType) {
|
2025 | if (this.options.onTrailingComma)
|
2026 | this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc)
|
2027 | this.next()
|
2028 | return true
|
2029 | }
|
2030 | }
|
2031 |
|
2032 |
|
2033 |
|
2034 |
|
2035 | pp.expect = function(type) {
|
2036 | this.eat(type) || this.unexpected()
|
2037 | }
|
2038 |
|
2039 |
|
2040 |
|
2041 | pp.unexpected = function(pos) {
|
2042 | this.raise(pos != null ? pos : this.start, "Unexpected token")
|
2043 | }
|
2044 |
|
2045 | var DestructuringErrors = function DestructuringErrors() {
|
2046 | this.shorthandAssign = 0
|
2047 | this.trailingComma = 0
|
2048 | };
|
2049 |
|
2050 | pp.checkPatternErrors = function(refDestructuringErrors, andThrow) {
|
2051 | var trailing = refDestructuringErrors && refDestructuringErrors.trailingComma
|
2052 | if (!andThrow) return !!trailing
|
2053 | if (trailing) this.raise(trailing, "Comma is not permitted after the rest element")
|
2054 | }
|
2055 |
|
2056 | pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
|
2057 | var pos = refDestructuringErrors && refDestructuringErrors.shorthandAssign
|
2058 | if (!andThrow) return !!pos
|
2059 | if (pos) this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns")
|
2060 | }
|
2061 |
|
2062 | var pp$1 = Parser.prototype
|
2063 |
|
2064 |
|
2065 |
|
2066 |
|
2067 |
|
2068 |
|
2069 |
|
2070 |
|
2071 | pp$1.parseTopLevel = function(node) {
|
2072 | var this$1 = this;
|
2073 |
|
2074 | var first = true
|
2075 | if (!node.body) node.body = []
|
2076 | while (this.type !== tt.eof) {
|
2077 | var stmt = this$1.parseStatement(true, true)
|
2078 | node.body.push(stmt)
|
2079 | if (first) {
|
2080 | if (this$1.isUseStrict(stmt)) this$1.setStrict(true)
|
2081 | first = false
|
2082 | }
|
2083 | }
|
2084 | this.next()
|
2085 | if (this.options.ecmaVersion >= 6) {
|
2086 | node.sourceType = this.options.sourceType
|
2087 | }
|
2088 | return this.finishNode(node, "Program")
|
2089 | }
|
2090 |
|
2091 | var loopLabel = {kind: "loop"};
|
2092 | var switchLabel = {kind: "switch"};
|
2093 | pp$1.isLet = function() {
|
2094 | if (this.type !== tt.name || this.options.ecmaVersion < 6 || this.value != "let") return false
|
2095 | skipWhiteSpace.lastIndex = this.pos
|
2096 | var skip = skipWhiteSpace.exec(this.input)
|
2097 | var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next)
|
2098 | if (nextCh === 91 || nextCh == 123) return true
|
2099 | if (isIdentifierStart(nextCh, true)) {
|
2100 | for (var pos = next + 1; isIdentifierChar(this.input.charCodeAt(pos, true)); ++pos) {}
|
2101 | var ident = this.input.slice(next, pos)
|
2102 | if (!this.isKeyword(ident)) return true
|
2103 | }
|
2104 | return false
|
2105 | }
|
2106 |
|
2107 |
|
2108 |
|
2109 |
|
2110 |
|
2111 |
|
2112 |
|
2113 |
|
2114 | pp$1.parseStatement = function(declaration, topLevel) {
|
2115 | var starttype = this.type, node = this.startNode(), kind
|
2116 |
|
2117 | if (this.isLet()) {
|
2118 | starttype = tt._var
|
2119 | kind = "let"
|
2120 | }
|
2121 |
|
2122 |
|
2123 |
|
2124 |
|
2125 |
|
2126 | switch (starttype) {
|
2127 | case tt._break: case tt._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
|
2128 | case tt._debugger: return this.parseDebuggerStatement(node)
|
2129 | case tt._do: return this.parseDoStatement(node)
|
2130 | case tt._for: return this.parseForStatement(node)
|
2131 | case tt._function:
|
2132 | if (!declaration && this.options.ecmaVersion >= 6) this.unexpected()
|
2133 | return this.parseFunctionStatement(node)
|
2134 | case tt._class:
|
2135 | if (!declaration) this.unexpected()
|
2136 | return this.parseClass(node, true)
|
2137 | case tt._if: return this.parseIfStatement(node)
|
2138 | case tt._return: return this.parseReturnStatement(node)
|
2139 | case tt._switch: return this.parseSwitchStatement(node)
|
2140 | case tt._throw: return this.parseThrowStatement(node)
|
2141 | case tt._try: return this.parseTryStatement(node)
|
2142 | case tt._const: case tt._var:
|
2143 | kind = kind || this.value
|
2144 | if (!declaration && kind != "var") this.unexpected()
|
2145 | return this.parseVarStatement(node, kind)
|
2146 | case tt._while: return this.parseWhileStatement(node)
|
2147 | case tt._with: return this.parseWithStatement(node)
|
2148 | case tt.braceL: return this.parseBlock()
|
2149 | case tt.semi: return this.parseEmptyStatement(node)
|
2150 | case tt._export:
|
2151 | case tt._import:
|
2152 | if (!this.options.allowImportExportEverywhere) {
|
2153 | if (!topLevel)
|
2154 | this.raise(this.start, "'import' and 'export' may only appear at the top level")
|
2155 | if (!this.inModule)
|
2156 | this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'")
|
2157 | }
|
2158 | return starttype === tt._import ? this.parseImport(node) : this.parseExport(node)
|
2159 |
|
2160 |
|
2161 |
|
2162 |
|
2163 |
|
2164 |
|
2165 | default:
|
2166 | var maybeName = this.value, expr = this.parseExpression()
|
2167 | if (starttype === tt.name && expr.type === "Identifier" && this.eat(tt.colon))
|
2168 | return this.parseLabeledStatement(node, maybeName, expr)
|
2169 | else return this.parseExpressionStatement(node, expr)
|
2170 | }
|
2171 | }
|
2172 |
|
2173 | pp$1.parseBreakContinueStatement = function(node, keyword) {
|
2174 | var this$1 = this;
|
2175 |
|
2176 | var isBreak = keyword == "break"
|
2177 | this.next()
|
2178 | if (this.eat(tt.semi) || this.insertSemicolon()) node.label = null
|
2179 | else if (this.type !== tt.name) this.unexpected()
|
2180 | else {
|
2181 | node.label = this.parseIdent()
|
2182 | this.semicolon()
|
2183 | }
|
2184 |
|
2185 |
|
2186 |
|
2187 | for (var i = 0; i < this.labels.length; ++i) {
|
2188 | var lab = this$1.labels[i]
|
2189 | if (node.label == null || lab.name === node.label.name) {
|
2190 | if (lab.kind != null && (isBreak || lab.kind === "loop")) break
|
2191 | if (node.label && isBreak) break
|
2192 | }
|
2193 | }
|
2194 | if (i === this.labels.length) this.raise(node.start, "Unsyntactic " + keyword)
|
2195 | return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
|
2196 | }
|
2197 |
|
2198 | pp$1.parseDebuggerStatement = function(node) {
|
2199 | this.next()
|
2200 | this.semicolon()
|
2201 | return this.finishNode(node, "DebuggerStatement")
|
2202 | }
|
2203 |
|
2204 | pp$1.parseDoStatement = function(node) {
|
2205 | this.next()
|
2206 | this.labels.push(loopLabel)
|
2207 | node.body = this.parseStatement(false)
|
2208 | this.labels.pop()
|
2209 | this.expect(tt._while)
|
2210 | node.test = this.parseParenExpression()
|
2211 | if (this.options.ecmaVersion >= 6)
|
2212 | this.eat(tt.semi)
|
2213 | else
|
2214 | this.semicolon()
|
2215 | return this.finishNode(node, "DoWhileStatement")
|
2216 | }
|
2217 |
|
2218 |
|
2219 |
|
2220 |
|
2221 |
|
2222 |
|
2223 |
|
2224 |
|
2225 |
|
2226 | pp$1.parseForStatement = function(node) {
|
2227 | this.next()
|
2228 | this.labels.push(loopLabel)
|
2229 | this.expect(tt.parenL)
|
2230 | if (this.type === tt.semi) return this.parseFor(node, null)
|
2231 | var isLet = this.isLet()
|
2232 | if (this.type === tt._var || this.type === tt._const || isLet) {
|
2233 | var init$1 = this.startNode(), kind = isLet ? "let" : this.value
|
2234 | this.next()
|
2235 | this.parseVar(init$1, true, kind)
|
2236 | this.finishNode(init$1, "VariableDeclaration")
|
2237 | if ((this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
|
2238 | !(kind !== "var" && init$1.declarations[0].init))
|
2239 | return this.parseForIn(node, init$1)
|
2240 | return this.parseFor(node, init$1)
|
2241 | }
|
2242 | var refDestructuringErrors = new DestructuringErrors
|
2243 | var init = this.parseExpression(true, refDestructuringErrors)
|
2244 | if (this.type === tt._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
|
2245 | this.checkPatternErrors(refDestructuringErrors, true)
|
2246 | this.toAssignable(init)
|
2247 | this.checkLVal(init)
|
2248 | return this.parseForIn(node, init)
|
2249 | } else {
|
2250 | this.checkExpressionErrors(refDestructuringErrors, true)
|
2251 | }
|
2252 | return this.parseFor(node, init)
|
2253 | }
|
2254 |
|
2255 | pp$1.parseFunctionStatement = function(node) {
|
2256 | this.next()
|
2257 | return this.parseFunction(node, true)
|
2258 | }
|
2259 |
|
2260 | pp$1.parseIfStatement = function(node) {
|
2261 | this.next()
|
2262 | node.test = this.parseParenExpression()
|
2263 | node.consequent = this.parseStatement(false)
|
2264 | node.alternate = this.eat(tt._else) ? this.parseStatement(false) : null
|
2265 | return this.finishNode(node, "IfStatement")
|
2266 | }
|
2267 |
|
2268 | pp$1.parseReturnStatement = function(node) {
|
2269 | if (!this.inFunction && !this.options.allowReturnOutsideFunction)
|
2270 | this.raise(this.start, "'return' outside of function")
|
2271 | this.next()
|
2272 |
|
2273 |
|
2274 |
|
2275 |
|
2276 |
|
2277 | if (this.eat(tt.semi) || this.insertSemicolon()) node.argument = null
|
2278 | else { node.argument = this.parseExpression(); this.semicolon() }
|
2279 | return this.finishNode(node, "ReturnStatement")
|
2280 | }
|
2281 |
|
2282 | pp$1.parseSwitchStatement = function(node) {
|
2283 | var this$1 = this;
|
2284 |
|
2285 | this.next()
|
2286 | node.discriminant = this.parseParenExpression()
|
2287 | node.cases = []
|
2288 | this.expect(tt.braceL)
|
2289 | this.labels.push(switchLabel)
|
2290 |
|
2291 |
|
2292 |
|
2293 |
|
2294 |
|
2295 | for (var cur, sawDefault = false; this.type != tt.braceR;) {
|
2296 | if (this$1.type === tt._case || this$1.type === tt._default) {
|
2297 | var isCase = this$1.type === tt._case
|
2298 | if (cur) this$1.finishNode(cur, "SwitchCase")
|
2299 | node.cases.push(cur = this$1.startNode())
|
2300 | cur.consequent = []
|
2301 | this$1.next()
|
2302 | if (isCase) {
|
2303 | cur.test = this$1.parseExpression()
|
2304 | } else {
|
2305 | if (sawDefault) this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses")
|
2306 | sawDefault = true
|
2307 | cur.test = null
|
2308 | }
|
2309 | this$1.expect(tt.colon)
|
2310 | } else {
|
2311 | if (!cur) this$1.unexpected()
|
2312 | cur.consequent.push(this$1.parseStatement(true))
|
2313 | }
|
2314 | }
|
2315 | if (cur) this.finishNode(cur, "SwitchCase")
|
2316 | this.next()
|
2317 | this.labels.pop()
|
2318 | return this.finishNode(node, "SwitchStatement")
|
2319 | }
|
2320 |
|
2321 | pp$1.parseThrowStatement = function(node) {
|
2322 | this.next()
|
2323 | if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
|
2324 | this.raise(this.lastTokEnd, "Illegal newline after throw")
|
2325 | node.argument = this.parseExpression()
|
2326 | this.semicolon()
|
2327 | return this.finishNode(node, "ThrowStatement")
|
2328 | }
|
2329 |
|
2330 |
|
2331 |
|
2332 | var empty = []
|
2333 |
|
2334 | pp$1.parseTryStatement = function(node) {
|
2335 | this.next()
|
2336 | node.block = this.parseBlock()
|
2337 | node.handler = null
|
2338 | if (this.type === tt._catch) {
|
2339 | var clause = this.startNode()
|
2340 | this.next()
|
2341 | this.expect(tt.parenL)
|
2342 | clause.param = this.parseBindingAtom()
|
2343 | this.checkLVal(clause.param, true)
|
2344 | this.expect(tt.parenR)
|
2345 | clause.body = this.parseBlock()
|
2346 | node.handler = this.finishNode(clause, "CatchClause")
|
2347 | }
|
2348 | node.finalizer = this.eat(tt._finally) ? this.parseBlock() : null
|
2349 | if (!node.handler && !node.finalizer)
|
2350 | this.raise(node.start, "Missing catch or finally clause")
|
2351 | return this.finishNode(node, "TryStatement")
|
2352 | }
|
2353 |
|
2354 | pp$1.parseVarStatement = function(node, kind) {
|
2355 | this.next()
|
2356 | this.parseVar(node, false, kind)
|
2357 | this.semicolon()
|
2358 | return this.finishNode(node, "VariableDeclaration")
|
2359 | }
|
2360 |
|
2361 | pp$1.parseWhileStatement = function(node) {
|
2362 | this.next()
|
2363 | node.test = this.parseParenExpression()
|
2364 | this.labels.push(loopLabel)
|
2365 | node.body = this.parseStatement(false)
|
2366 | this.labels.pop()
|
2367 | return this.finishNode(node, "WhileStatement")
|
2368 | }
|
2369 |
|
2370 | pp$1.parseWithStatement = function(node) {
|
2371 | if (this.strict) this.raise(this.start, "'with' in strict mode")
|
2372 | this.next()
|
2373 | node.object = this.parseParenExpression()
|
2374 | node.body = this.parseStatement(false)
|
2375 | return this.finishNode(node, "WithStatement")
|
2376 | }
|
2377 |
|
2378 | pp$1.parseEmptyStatement = function(node) {
|
2379 | this.next()
|
2380 | return this.finishNode(node, "EmptyStatement")
|
2381 | }
|
2382 |
|
2383 | pp$1.parseLabeledStatement = function(node, maybeName, expr) {
|
2384 | var this$1 = this;
|
2385 |
|
2386 | for (var i = 0; i < this.labels.length; ++i)
|
2387 | if (this$1.labels[i].name === maybeName) this$1.raise(expr.start, "Label '" + maybeName + "' is already declared")
|
2388 | var kind = this.type.isLoop ? "loop" : this.type === tt._switch ? "switch" : null
|
2389 | for (var i$1 = this.labels.length - 1; i$1 >= 0; i$1--) {
|
2390 | var label = this$1.labels[i$1]
|
2391 | if (label.statementStart == node.start) {
|
2392 | label.statementStart = this$1.start
|
2393 | label.kind = kind
|
2394 | } else break
|
2395 | }
|
2396 | this.labels.push({name: maybeName, kind: kind, statementStart: this.start})
|
2397 | node.body = this.parseStatement(true)
|
2398 | this.labels.pop()
|
2399 | node.label = expr
|
2400 | return this.finishNode(node, "LabeledStatement")
|
2401 | }
|
2402 |
|
2403 | pp$1.parseExpressionStatement = function(node, expr) {
|
2404 | node.expression = expr
|
2405 | this.semicolon()
|
2406 | return this.finishNode(node, "ExpressionStatement")
|
2407 | }
|
2408 |
|
2409 |
|
2410 |
|
2411 |
|
2412 |
|
2413 | pp$1.parseBlock = function(allowStrict) {
|
2414 | var this$1 = this;
|
2415 |
|
2416 | var node = this.startNode(), first = true, oldStrict
|
2417 | node.body = []
|
2418 | this.expect(tt.braceL)
|
2419 | while (!this.eat(tt.braceR)) {
|
2420 | var stmt = this$1.parseStatement(true)
|
2421 | node.body.push(stmt)
|
2422 | if (first && allowStrict && this$1.isUseStrict(stmt)) {
|
2423 | oldStrict = this$1.strict
|
2424 | this$1.setStrict(this$1.strict = true)
|
2425 | }
|
2426 | first = false
|
2427 | }
|
2428 | if (oldStrict === false) this.setStrict(false)
|
2429 | return this.finishNode(node, "BlockStatement")
|
2430 | }
|
2431 |
|
2432 |
|
2433 |
|
2434 |
|
2435 |
|
2436 | pp$1.parseFor = function(node, init) {
|
2437 | node.init = init
|
2438 | this.expect(tt.semi)
|
2439 | node.test = this.type === tt.semi ? null : this.parseExpression()
|
2440 | this.expect(tt.semi)
|
2441 | node.update = this.type === tt.parenR ? null : this.parseExpression()
|
2442 | this.expect(tt.parenR)
|
2443 | node.body = this.parseStatement(false)
|
2444 | this.labels.pop()
|
2445 | return this.finishNode(node, "ForStatement")
|
2446 | }
|
2447 |
|
2448 |
|
2449 |
|
2450 |
|
2451 | pp$1.parseForIn = function(node, init) {
|
2452 | var type = this.type === tt._in ? "ForInStatement" : "ForOfStatement"
|
2453 | this.next()
|
2454 | node.left = init
|
2455 | node.right = this.parseExpression()
|
2456 | this.expect(tt.parenR)
|
2457 | node.body = this.parseStatement(false)
|
2458 | this.labels.pop()
|
2459 | return this.finishNode(node, type)
|
2460 | }
|
2461 |
|
2462 |
|
2463 |
|
2464 | pp$1.parseVar = function(node, isFor, kind) {
|
2465 | var this$1 = this;
|
2466 |
|
2467 | node.declarations = []
|
2468 | node.kind = kind
|
2469 | for (;;) {
|
2470 | var decl = this$1.startNode()
|
2471 | this$1.parseVarId(decl)
|
2472 | if (this$1.eat(tt.eq)) {
|
2473 | decl.init = this$1.parseMaybeAssign(isFor)
|
2474 | } else if (kind === "const" && !(this$1.type === tt._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
|
2475 | this$1.unexpected()
|
2476 | } else if (decl.id.type != "Identifier" && !(isFor && (this$1.type === tt._in || this$1.isContextual("of")))) {
|
2477 | this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value")
|
2478 | } else {
|
2479 | decl.init = null
|
2480 | }
|
2481 | node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"))
|
2482 | if (!this$1.eat(tt.comma)) break
|
2483 | }
|
2484 | return node
|
2485 | }
|
2486 |
|
2487 | pp$1.parseVarId = function(decl) {
|
2488 | decl.id = this.parseBindingAtom()
|
2489 | this.checkLVal(decl.id, true)
|
2490 | }
|
2491 |
|
2492 |
|
2493 |
|
2494 |
|
2495 | pp$1.parseFunction = function(node, isStatement, allowExpressionBody) {
|
2496 | this.initFunction(node)
|
2497 | if (this.options.ecmaVersion >= 6)
|
2498 | node.generator = this.eat(tt.star)
|
2499 | var oldInGen = this.inGenerator
|
2500 | this.inGenerator = node.generator
|
2501 | if (isStatement || this.type === tt.name)
|
2502 | node.id = this.parseIdent()
|
2503 | this.parseFunctionParams(node)
|
2504 | this.parseFunctionBody(node, allowExpressionBody)
|
2505 | this.inGenerator = oldInGen
|
2506 | return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
|
2507 | }
|
2508 |
|
2509 | pp$1.parseFunctionParams = function(node) {
|
2510 | this.expect(tt.parenL)
|
2511 | node.params = this.parseBindingList(tt.parenR, false, false, true)
|
2512 | }
|
2513 |
|
2514 |
|
2515 |
|
2516 |
|
2517 | pp$1.parseClass = function(node, isStatement) {
|
2518 | var this$1 = this;
|
2519 |
|
2520 | this.next()
|
2521 | this.parseClassId(node, isStatement)
|
2522 | this.parseClassSuper(node)
|
2523 | var classBody = this.startNode()
|
2524 | var hadConstructor = false
|
2525 | classBody.body = []
|
2526 | this.expect(tt.braceL)
|
2527 | while (!this.eat(tt.braceR)) {
|
2528 | if (this$1.eat(tt.semi)) continue
|
2529 | var method = this$1.startNode()
|
2530 | var isGenerator = this$1.eat(tt.star)
|
2531 | var isMaybeStatic = this$1.type === tt.name && this$1.value === "static"
|
2532 | this$1.parsePropertyName(method)
|
2533 | method.static = isMaybeStatic && this$1.type !== tt.parenL
|
2534 | if (method.static) {
|
2535 | if (isGenerator) this$1.unexpected()
|
2536 | isGenerator = this$1.eat(tt.star)
|
2537 | this$1.parsePropertyName(method)
|
2538 | }
|
2539 | method.kind = "method"
|
2540 | var isGetSet = false
|
2541 | if (!method.computed) {
|
2542 | var key = method.key;
|
2543 | if (!isGenerator && key.type === "Identifier" && this$1.type !== tt.parenL && (key.name === "get" || key.name === "set")) {
|
2544 | isGetSet = true
|
2545 | method.kind = key.name
|
2546 | key = this$1.parsePropertyName(method)
|
2547 | }
|
2548 | if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
|
2549 | key.type === "Literal" && key.value === "constructor")) {
|
2550 | if (hadConstructor) this$1.raise(key.start, "Duplicate constructor in the same class")
|
2551 | if (isGetSet) this$1.raise(key.start, "Constructor can't have get/set modifier")
|
2552 | if (isGenerator) this$1.raise(key.start, "Constructor can't be a generator")
|
2553 | method.kind = "constructor"
|
2554 | hadConstructor = true
|
2555 | }
|
2556 | }
|
2557 | this$1.parseClassMethod(classBody, method, isGenerator)
|
2558 | if (isGetSet) {
|
2559 | var paramCount = method.kind === "get" ? 0 : 1
|
2560 | if (method.value.params.length !== paramCount) {
|
2561 | var start = method.value.start
|
2562 | if (method.kind === "get")
|
2563 | this$1.raiseRecoverable(start, "getter should have no params")
|
2564 | else
|
2565 | this$1.raiseRecoverable(start, "setter should have exactly one param")
|
2566 | }
|
2567 | if (method.kind === "set" && method.value.params[0].type === "RestElement")
|
2568 | this$1.raise(method.value.params[0].start, "Setter cannot use rest params")
|
2569 | }
|
2570 | }
|
2571 | node.body = this.finishNode(classBody, "ClassBody")
|
2572 | return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
|
2573 | }
|
2574 |
|
2575 | pp$1.parseClassMethod = function(classBody, method, isGenerator) {
|
2576 | method.value = this.parseMethod(isGenerator)
|
2577 | classBody.body.push(this.finishNode(method, "MethodDefinition"))
|
2578 | }
|
2579 |
|
2580 | pp$1.parseClassId = function(node, isStatement) {
|
2581 | node.id = this.type === tt.name ? this.parseIdent() : isStatement ? this.unexpected() : null
|
2582 | }
|
2583 |
|
2584 | pp$1.parseClassSuper = function(node) {
|
2585 | node.superClass = this.eat(tt._extends) ? this.parseExprSubscripts() : null
|
2586 | }
|
2587 |
|
2588 |
|
2589 |
|
2590 | pp$1.parseExport = function(node) {
|
2591 | var this$1 = this;
|
2592 |
|
2593 | this.next()
|
2594 |
|
2595 | if (this.eat(tt.star)) {
|
2596 | this.expectContextual("from")
|
2597 | node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected()
|
2598 | this.semicolon()
|
2599 | return this.finishNode(node, "ExportAllDeclaration")
|
2600 | }
|
2601 | if (this.eat(tt._default)) {
|
2602 | var parens = this.type == tt.parenL
|
2603 | var expr = this.parseMaybeAssign()
|
2604 | var needsSemi = true
|
2605 | if (!parens && (expr.type == "FunctionExpression" ||
|
2606 | expr.type == "ClassExpression")) {
|
2607 | needsSemi = false
|
2608 | if (expr.id) {
|
2609 | expr.type = expr.type == "FunctionExpression"
|
2610 | ? "FunctionDeclaration"
|
2611 | : "ClassDeclaration"
|
2612 | }
|
2613 | }
|
2614 | node.declaration = expr
|
2615 | if (needsSemi) this.semicolon()
|
2616 | return this.finishNode(node, "ExportDefaultDeclaration")
|
2617 | }
|
2618 |
|
2619 | if (this.shouldParseExportStatement()) {
|
2620 | node.declaration = this.parseStatement(true)
|
2621 | node.specifiers = []
|
2622 | node.source = null
|
2623 | } else {
|
2624 | node.declaration = null
|
2625 | node.specifiers = this.parseExportSpecifiers()
|
2626 | if (this.eatContextual("from")) {
|
2627 | node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected()
|
2628 | } else {
|
2629 |
|
2630 | for (var i = 0; i < node.specifiers.length; i++) {
|
2631 | if (this$1.keywords.test(node.specifiers[i].local.name) || this$1.reservedWords.test(node.specifiers[i].local.name)) {
|
2632 | this$1.unexpected(node.specifiers[i].local.start)
|
2633 | }
|
2634 | }
|
2635 |
|
2636 | node.source = null
|
2637 | }
|
2638 | this.semicolon()
|
2639 | }
|
2640 | return this.finishNode(node, "ExportNamedDeclaration")
|
2641 | }
|
2642 |
|
2643 | pp$1.shouldParseExportStatement = function() {
|
2644 | return this.type.keyword || this.isLet()
|
2645 | }
|
2646 |
|
2647 |
|
2648 |
|
2649 | pp$1.parseExportSpecifiers = function() {
|
2650 | var this$1 = this;
|
2651 |
|
2652 | var nodes = [], first = true
|
2653 |
|
2654 | this.expect(tt.braceL)
|
2655 | while (!this.eat(tt.braceR)) {
|
2656 | if (!first) {
|
2657 | this$1.expect(tt.comma)
|
2658 | if (this$1.afterTrailingComma(tt.braceR)) break
|
2659 | } else first = false
|
2660 |
|
2661 | var node = this$1.startNode()
|
2662 | node.local = this$1.parseIdent(this$1.type === tt._default)
|
2663 | node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local
|
2664 | nodes.push(this$1.finishNode(node, "ExportSpecifier"))
|
2665 | }
|
2666 | return nodes
|
2667 | }
|
2668 |
|
2669 |
|
2670 |
|
2671 | pp$1.parseImport = function(node) {
|
2672 | this.next()
|
2673 |
|
2674 | if (this.type === tt.string) {
|
2675 | node.specifiers = empty
|
2676 | node.source = this.parseExprAtom()
|
2677 | } else {
|
2678 | node.specifiers = this.parseImportSpecifiers()
|
2679 | this.expectContextual("from")
|
2680 | node.source = this.type === tt.string ? this.parseExprAtom() : this.unexpected()
|
2681 | }
|
2682 | this.semicolon()
|
2683 | return this.finishNode(node, "ImportDeclaration")
|
2684 | }
|
2685 |
|
2686 |
|
2687 |
|
2688 | pp$1.parseImportSpecifiers = function() {
|
2689 | var this$1 = this;
|
2690 |
|
2691 | var nodes = [], first = true
|
2692 | if (this.type === tt.name) {
|
2693 |
|
2694 | var node = this.startNode()
|
2695 | node.local = this.parseIdent()
|
2696 | this.checkLVal(node.local, true)
|
2697 | nodes.push(this.finishNode(node, "ImportDefaultSpecifier"))
|
2698 | if (!this.eat(tt.comma)) return nodes
|
2699 | }
|
2700 | if (this.type === tt.star) {
|
2701 | var node$1 = this.startNode()
|
2702 | this.next()
|
2703 | this.expectContextual("as")
|
2704 | node$1.local = this.parseIdent()
|
2705 | this.checkLVal(node$1.local, true)
|
2706 | nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"))
|
2707 | return nodes
|
2708 | }
|
2709 | this.expect(tt.braceL)
|
2710 | while (!this.eat(tt.braceR)) {
|
2711 | if (!first) {
|
2712 | this$1.expect(tt.comma)
|
2713 | if (this$1.afterTrailingComma(tt.braceR)) break
|
2714 | } else first = false
|
2715 |
|
2716 | var node$2 = this$1.startNode()
|
2717 | node$2.imported = this$1.parseIdent(true)
|
2718 | if (this$1.eatContextual("as")) {
|
2719 | node$2.local = this$1.parseIdent()
|
2720 | } else {
|
2721 | node$2.local = node$2.imported
|
2722 | if (this$1.isKeyword(node$2.local.name)) this$1.unexpected(node$2.local.start)
|
2723 | if (this$1.reservedWordsStrict.test(node$2.local.name)) this$1.raise(node$2.local.start, "The keyword '" + node$2.local.name + "' is reserved")
|
2724 | }
|
2725 | this$1.checkLVal(node$2.local, true)
|
2726 | nodes.push(this$1.finishNode(node$2, "ImportSpecifier"))
|
2727 | }
|
2728 | return nodes
|
2729 | }
|
2730 |
|
2731 | var pp$2 = Parser.prototype
|
2732 |
|
2733 |
|
2734 |
|
2735 |
|
2736 | pp$2.toAssignable = function(node, isBinding) {
|
2737 | var this$1 = this;
|
2738 |
|
2739 | if (this.options.ecmaVersion >= 6 && node) {
|
2740 | switch (node.type) {
|
2741 | case "Identifier":
|
2742 | case "ObjectPattern":
|
2743 | case "ArrayPattern":
|
2744 | break
|
2745 |
|
2746 | case "ObjectExpression":
|
2747 | node.type = "ObjectPattern"
|
2748 | for (var i = 0; i < node.properties.length; i++) {
|
2749 | var prop = node.properties[i]
|
2750 | if (prop.kind !== "init") this$1.raise(prop.key.start, "Object pattern can't contain getter or setter")
|
2751 | this$1.toAssignable(prop.value, isBinding)
|
2752 | }
|
2753 | break
|
2754 |
|
2755 | case "ArrayExpression":
|
2756 | node.type = "ArrayPattern"
|
2757 | this.toAssignableList(node.elements, isBinding)
|
2758 | break
|
2759 |
|
2760 | case "AssignmentExpression":
|
2761 | if (node.operator === "=") {
|
2762 | node.type = "AssignmentPattern"
|
2763 | delete node.operator
|
2764 |
|
2765 | } else {
|
2766 | this.raise(node.left.end, "Only '=' operator can be used for specifying default value.")
|
2767 | break
|
2768 | }
|
2769 |
|
2770 | case "AssignmentPattern":
|
2771 | if (node.right.type === "YieldExpression")
|
2772 | this.raise(node.right.start, "Yield expression cannot be a default value")
|
2773 | break
|
2774 |
|
2775 | case "ParenthesizedExpression":
|
2776 | node.expression = this.toAssignable(node.expression, isBinding)
|
2777 | break
|
2778 |
|
2779 | case "MemberExpression":
|
2780 | if (!isBinding) break
|
2781 |
|
2782 | default:
|
2783 | this.raise(node.start, "Assigning to rvalue")
|
2784 | }
|
2785 | }
|
2786 | return node
|
2787 | }
|
2788 |
|
2789 |
|
2790 |
|
2791 | pp$2.toAssignableList = function(exprList, isBinding) {
|
2792 | var this$1 = this;
|
2793 |
|
2794 | var end = exprList.length
|
2795 | if (end) {
|
2796 | var last = exprList[end - 1]
|
2797 | if (last && last.type == "RestElement") {
|
2798 | --end
|
2799 | } else if (last && last.type == "SpreadElement") {
|
2800 | last.type = "RestElement"
|
2801 | var arg = last.argument
|
2802 | this.toAssignable(arg, isBinding)
|
2803 | if (arg.type !== "Identifier" && arg.type !== "MemberExpression" && arg.type !== "ArrayPattern")
|
2804 | this.unexpected(arg.start)
|
2805 | --end
|
2806 | }
|
2807 |
|
2808 | if (isBinding && last.type === "RestElement" && last.argument.type !== "Identifier")
|
2809 | this.unexpected(last.argument.start)
|
2810 | }
|
2811 | for (var i = 0; i < end; i++) {
|
2812 | var elt = exprList[i]
|
2813 | if (elt) this$1.toAssignable(elt, isBinding)
|
2814 | }
|
2815 | return exprList
|
2816 | }
|
2817 |
|
2818 |
|
2819 |
|
2820 | pp$2.parseSpread = function(refDestructuringErrors) {
|
2821 | var node = this.startNode()
|
2822 | this.next()
|
2823 | node.argument = this.parseMaybeAssign(refDestructuringErrors)
|
2824 | return this.finishNode(node, "SpreadElement")
|
2825 | }
|
2826 |
|
2827 | pp$2.parseRest = function(allowNonIdent) {
|
2828 | var node = this.startNode()
|
2829 | this.next()
|
2830 |
|
2831 |
|
2832 | if (allowNonIdent) node.argument = this.type === tt.name ? this.parseIdent() : this.unexpected()
|
2833 | else node.argument = this.type === tt.name || this.type === tt.bracketL ? this.parseBindingAtom() : this.unexpected()
|
2834 |
|
2835 | return this.finishNode(node, "RestElement")
|
2836 | }
|
2837 |
|
2838 |
|
2839 |
|
2840 | pp$2.parseBindingAtom = function() {
|
2841 | if (this.options.ecmaVersion < 6) return this.parseIdent()
|
2842 | switch (this.type) {
|
2843 | case tt.name:
|
2844 | return this.parseIdent()
|
2845 |
|
2846 | case tt.bracketL:
|
2847 | var node = this.startNode()
|
2848 | this.next()
|
2849 | node.elements = this.parseBindingList(tt.bracketR, true, true)
|
2850 | return this.finishNode(node, "ArrayPattern")
|
2851 |
|
2852 | case tt.braceL:
|
2853 | return this.parseObj(true)
|
2854 |
|
2855 | default:
|
2856 | this.unexpected()
|
2857 | }
|
2858 | }
|
2859 |
|
2860 | pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma, allowNonIdent) {
|
2861 | var this$1 = this;
|
2862 |
|
2863 | var elts = [], first = true
|
2864 | while (!this.eat(close)) {
|
2865 | if (first) first = false
|
2866 | else this$1.expect(tt.comma)
|
2867 | if (allowEmpty && this$1.type === tt.comma) {
|
2868 | elts.push(null)
|
2869 | } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
|
2870 | break
|
2871 | } else if (this$1.type === tt.ellipsis) {
|
2872 | var rest = this$1.parseRest(allowNonIdent)
|
2873 | this$1.parseBindingListItem(rest)
|
2874 | elts.push(rest)
|
2875 | if (this$1.type === tt.comma) this$1.raise(this$1.start, "Comma is not permitted after the rest element")
|
2876 | this$1.expect(close)
|
2877 | break
|
2878 | } else {
|
2879 | var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc)
|
2880 | this$1.parseBindingListItem(elem)
|
2881 | elts.push(elem)
|
2882 | }
|
2883 | }
|
2884 | return elts
|
2885 | }
|
2886 |
|
2887 | pp$2.parseBindingListItem = function(param) {
|
2888 | return param
|
2889 | }
|
2890 |
|
2891 |
|
2892 |
|
2893 | pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
|
2894 | left = left || this.parseBindingAtom()
|
2895 | if (this.options.ecmaVersion < 6 || !this.eat(tt.eq)) return left
|
2896 | var node = this.startNodeAt(startPos, startLoc)
|
2897 | node.left = left
|
2898 | node.right = this.parseMaybeAssign()
|
2899 | return this.finishNode(node, "AssignmentPattern")
|
2900 | }
|
2901 |
|
2902 |
|
2903 |
|
2904 |
|
2905 | pp$2.checkLVal = function(expr, isBinding, checkClashes) {
|
2906 | var this$1 = this;
|
2907 |
|
2908 | switch (expr.type) {
|
2909 | case "Identifier":
|
2910 | if (this.strict && this.reservedWordsStrictBind.test(expr.name))
|
2911 | this.raiseRecoverable(expr.start, (isBinding ? "Binding " : "Assigning to ") + expr.name + " in strict mode")
|
2912 | if (checkClashes) {
|
2913 | if (has(checkClashes, expr.name))
|
2914 | this.raiseRecoverable(expr.start, "Argument name clash")
|
2915 | checkClashes[expr.name] = true
|
2916 | }
|
2917 | break
|
2918 |
|
2919 | case "MemberExpression":
|
2920 | if (isBinding) this.raiseRecoverable(expr.start, (isBinding ? "Binding" : "Assigning to") + " member expression")
|
2921 | break
|
2922 |
|
2923 | case "ObjectPattern":
|
2924 | for (var i = 0; i < expr.properties.length; i++)
|
2925 | this$1.checkLVal(expr.properties[i].value, isBinding, checkClashes)
|
2926 | break
|
2927 |
|
2928 | case "ArrayPattern":
|
2929 | for (var i$1 = 0; i$1 < expr.elements.length; i$1++) {
|
2930 | var elem = expr.elements[i$1]
|
2931 | if (elem) this$1.checkLVal(elem, isBinding, checkClashes)
|
2932 | }
|
2933 | break
|
2934 |
|
2935 | case "AssignmentPattern":
|
2936 | this.checkLVal(expr.left, isBinding, checkClashes)
|
2937 | break
|
2938 |
|
2939 | case "RestElement":
|
2940 | this.checkLVal(expr.argument, isBinding, checkClashes)
|
2941 | break
|
2942 |
|
2943 | case "ParenthesizedExpression":
|
2944 | this.checkLVal(expr.expression, isBinding, checkClashes)
|
2945 | break
|
2946 |
|
2947 | default:
|
2948 | this.raise(expr.start, (isBinding ? "Binding" : "Assigning to") + " rvalue")
|
2949 | }
|
2950 | }
|
2951 |
|
2952 | var pp$3 = Parser.prototype
|
2953 |
|
2954 |
|
2955 |
|
2956 |
|
2957 |
|
2958 |
|
2959 | pp$3.checkPropClash = function(prop, propHash) {
|
2960 | if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
|
2961 | return
|
2962 | var key = prop.key;
|
2963 | var name
|
2964 | switch (key.type) {
|
2965 | case "Identifier": name = key.name; break
|
2966 | case "Literal": name = String(key.value); break
|
2967 | default: return
|
2968 | }
|
2969 | var kind = prop.kind;
|
2970 | if (this.options.ecmaVersion >= 6) {
|
2971 | if (name === "__proto__" && kind === "init") {
|
2972 | if (propHash.proto) this.raiseRecoverable(key.start, "Redefinition of __proto__ property")
|
2973 | propHash.proto = true
|
2974 | }
|
2975 | return
|
2976 | }
|
2977 | name = "$" + name
|
2978 | var other = propHash[name]
|
2979 | if (other) {
|
2980 | var isGetSet = kind !== "init"
|
2981 | if ((this.strict || isGetSet) && other[kind] || !(isGetSet ^ other.init))
|
2982 | this.raiseRecoverable(key.start, "Redefinition of property")
|
2983 | } else {
|
2984 | other = propHash[name] = {
|
2985 | init: false,
|
2986 | get: false,
|
2987 | set: false
|
2988 | }
|
2989 | }
|
2990 | other[kind] = true
|
2991 | }
|
2992 |
|
2993 | // ### Expression parsing
|
2994 |
|
2995 | // These nest, from the most general expression type at the top to
|
2996 | // 'atomic', nondivisible expression types at the bottom. Most of
|
2997 | // the functions will simply let the function(s) below them parse,
|
2998 | // and, *if* the syntactic construct they handle is present, wrap
|
2999 | // the AST node that the inner parser gave them in another node.
|
3000 |
|
3001 | // Parse a full expression. The optional arguments are used to
|
3002 | // forbid the `in` operator (in for loops initalization expressions)
|
3003 | // and provide reference for storing '=' operator inside shorthand
|
3004 | // property assignment in contexts where both object expression
|
3005 | // and object pattern might appear (so it's possible to raise
|
3006 | // delayed syntax error at correct position).
|
3007 |
|
3008 | pp$3.parseExpression = function(noIn, refDestructuringErrors) {
|
3009 | var this$1 = this;
|
3010 |
|
3011 | var startPos = this.start, startLoc = this.startLoc
|
3012 | var expr = this.parseMaybeAssign(noIn, refDestructuringErrors)
|
3013 | if (this.type === tt.comma) {
|
3014 | var node = this.startNodeAt(startPos, startLoc)
|
3015 | node.expressions = [expr]
|
3016 | while (this.eat(tt.comma)) node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors))
|
3017 | return this.finishNode(node, "SequenceExpression")
|
3018 | }
|
3019 | return expr
|
3020 | }
|
3021 |
|
3022 |
|
3023 |
|
3024 |
|
3025 | pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
|
3026 | if (this.inGenerator && this.isContextual("yield")) return this.parseYield()
|
3027 |
|
3028 | var ownDestructuringErrors = false
|
3029 | if (!refDestructuringErrors) {
|
3030 | refDestructuringErrors = new DestructuringErrors
|
3031 | ownDestructuringErrors = true
|
3032 | }
|
3033 | var startPos = this.start, startLoc = this.startLoc
|
3034 | if (this.type == tt.parenL || this.type == tt.name)
|
3035 | this.potentialArrowAt = this.start
|
3036 | var left = this.parseMaybeConditional(noIn, refDestructuringErrors)
|
3037 | if (afterLeftParse) left = afterLeftParse.call(this, left, startPos, startLoc)
|
3038 | if (this.type.isAssign) {
|
3039 | this.checkPatternErrors(refDestructuringErrors, true)
|
3040 | if (!ownDestructuringErrors) DestructuringErrors.call(refDestructuringErrors)
|
3041 | var node = this.startNodeAt(startPos, startLoc)
|
3042 | node.operator = this.value
|
3043 | node.left = this.type === tt.eq ? this.toAssignable(left) : left
|
3044 | refDestructuringErrors.shorthandAssign = 0
|
3045 | this.checkLVal(left)
|
3046 | this.next()
|
3047 | node.right = this.parseMaybeAssign(noIn)
|
3048 | return this.finishNode(node, "AssignmentExpression")
|
3049 | } else {
|
3050 | if (ownDestructuringErrors) this.checkExpressionErrors(refDestructuringErrors, true)
|
3051 | }
|
3052 | return left
|
3053 | }
|
3054 |
|
3055 |
|
3056 |
|
3057 | pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
|
3058 | var startPos = this.start, startLoc = this.startLoc
|
3059 | var expr = this.parseExprOps(noIn, refDestructuringErrors)
|
3060 | if (this.checkExpressionErrors(refDestructuringErrors)) return expr
|
3061 | if (this.eat(tt.question)) {
|
3062 | var node = this.startNodeAt(startPos, startLoc)
|
3063 | node.test = expr
|
3064 | node.consequent = this.parseMaybeAssign()
|
3065 | this.expect(tt.colon)
|
3066 | node.alternate = this.parseMaybeAssign(noIn)
|
3067 | return this.finishNode(node, "ConditionalExpression")
|
3068 | }
|
3069 | return expr
|
3070 | }
|
3071 |
|
3072 |
|
3073 |
|
3074 | pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
|
3075 | var startPos = this.start, startLoc = this.startLoc
|
3076 | var expr = this.parseMaybeUnary(refDestructuringErrors, false)
|
3077 | if (this.checkExpressionErrors(refDestructuringErrors)) return expr
|
3078 | return this.parseExprOp(expr, startPos, startLoc, -1, noIn)
|
3079 | }
|
3080 |
|
3081 |
|
3082 |
|
3083 |
|
3084 |
|
3085 |
|
3086 |
|
3087 | pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
|
3088 | var prec = this.type.binop
|
3089 | if (prec != null && (!noIn || this.type !== tt._in)) {
|
3090 | if (prec > minPrec) {
|
3091 | var logical = this.type === tt.logicalOR || this.type === tt.logicalAND
|
3092 | var op = this.value
|
3093 | this.next()
|
3094 | var startPos = this.start, startLoc = this.startLoc
|
3095 | var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn)
|
3096 | var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical)
|
3097 | return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
|
3098 | }
|
3099 | }
|
3100 | return left
|
3101 | }
|
3102 |
|
3103 | pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
|
3104 | var node = this.startNodeAt(startPos, startLoc)
|
3105 | node.left = left
|
3106 | node.operator = op
|
3107 | node.right = right
|
3108 | return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
|
3109 | }
|
3110 |
|
3111 |
|
3112 |
|
3113 | pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
|
3114 | var this$1 = this;
|
3115 |
|
3116 | var startPos = this.start, startLoc = this.startLoc, expr
|
3117 | if (this.type.prefix) {
|
3118 | var node = this.startNode(), update = this.type === tt.incDec
|
3119 | node.operator = this.value
|
3120 | node.prefix = true
|
3121 | this.next()
|
3122 | node.argument = this.parseMaybeUnary(null, true)
|
3123 | this.checkExpressionErrors(refDestructuringErrors, true)
|
3124 | if (update) this.checkLVal(node.argument)
|
3125 | else if (this.strict && node.operator === "delete" &&
|
3126 | node.argument.type === "Identifier")
|
3127 | this.raiseRecoverable(node.start, "Deleting local variable in strict mode")
|
3128 | else sawUnary = true
|
3129 | expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression")
|
3130 | } else {
|
3131 | expr = this.parseExprSubscripts(refDestructuringErrors)
|
3132 | if (this.checkExpressionErrors(refDestructuringErrors)) return expr
|
3133 | while (this.type.postfix && !this.canInsertSemicolon()) {
|
3134 | var node$1 = this$1.startNodeAt(startPos, startLoc)
|
3135 | node$1.operator = this$1.value
|
3136 | node$1.prefix = false
|
3137 | node$1.argument = expr
|
3138 | this$1.checkLVal(expr)
|
3139 | this$1.next()
|
3140 | expr = this$1.finishNode(node$1, "UpdateExpression")
|
3141 | }
|
3142 | }
|
3143 |
|
3144 | if (!sawUnary && this.eat(tt.starstar))
|
3145 | return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false)
|
3146 | else
|
3147 | return expr
|
3148 | }
|
3149 |
|
3150 |
|
3151 |
|
3152 | pp$3.parseExprSubscripts = function(refDestructuringErrors) {
|
3153 | var startPos = this.start, startLoc = this.startLoc
|
3154 | var expr = this.parseExprAtom(refDestructuringErrors)
|
3155 | var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")"
|
3156 | if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) return expr
|
3157 | return this.parseSubscripts(expr, startPos, startLoc)
|
3158 | }
|
3159 |
|
3160 | pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
|
3161 | var this$1 = this;
|
3162 |
|
3163 | for (;;) {
|
3164 | if (this$1.eat(tt.dot)) {
|
3165 | var node = this$1.startNodeAt(startPos, startLoc)
|
3166 | node.object = base
|
3167 | node.property = this$1.parseIdent(true)
|
3168 | node.computed = false
|
3169 | base = this$1.finishNode(node, "MemberExpression")
|
3170 | } else if (this$1.eat(tt.bracketL)) {
|
3171 | var node$1 = this$1.startNodeAt(startPos, startLoc)
|
3172 | node$1.object = base
|
3173 | node$1.property = this$1.parseExpression()
|
3174 | node$1.computed = true
|
3175 | this$1.expect(tt.bracketR)
|
3176 | base = this$1.finishNode(node$1, "MemberExpression")
|
3177 | } else if (!noCalls && this$1.eat(tt.parenL)) {
|
3178 | var node$2 = this$1.startNodeAt(startPos, startLoc)
|
3179 | node$2.callee = base
|
3180 | node$2.arguments = this$1.parseExprList(tt.parenR, false)
|
3181 | base = this$1.finishNode(node$2, "CallExpression")
|
3182 | } else if (this$1.type === tt.backQuote) {
|
3183 | var node$3 = this$1.startNodeAt(startPos, startLoc)
|
3184 | node$3.tag = base
|
3185 | node$3.quasi = this$1.parseTemplate()
|
3186 | base = this$1.finishNode(node$3, "TaggedTemplateExpression")
|
3187 | } else {
|
3188 | return base
|
3189 | }
|
3190 | }
|
3191 | }
|
3192 |
|
3193 |
|
3194 |
|
3195 |
|
3196 |
|
3197 |
|
3198 | pp$3.parseExprAtom = function(refDestructuringErrors) {
|
3199 | var node, canBeArrow = this.potentialArrowAt == this.start
|
3200 | switch (this.type) {
|
3201 | case tt._super:
|
3202 | if (!this.inFunction)
|
3203 | this.raise(this.start, "'super' outside of function or class")
|
3204 |
|
3205 | case tt._this:
|
3206 | var type = this.type === tt._this ? "ThisExpression" : "Super"
|
3207 | node = this.startNode()
|
3208 | this.next()
|
3209 | return this.finishNode(node, type)
|
3210 |
|
3211 | case tt.name:
|
3212 | var startPos = this.start, startLoc = this.startLoc
|
3213 | var id = this.parseIdent(this.type !== tt.name)
|
3214 | if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow))
|
3215 | return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id])
|
3216 | return id
|
3217 |
|
3218 | case tt.regexp:
|
3219 | var value = this.value
|
3220 | node = this.parseLiteral(value.value)
|
3221 | node.regex = {pattern: value.pattern, flags: value.flags}
|
3222 | return node
|
3223 |
|
3224 | case tt.num: case tt.string:
|
3225 | return this.parseLiteral(this.value)
|
3226 |
|
3227 | case tt._null: case tt._true: case tt._false:
|
3228 | node = this.startNode()
|
3229 | node.value = this.type === tt._null ? null : this.type === tt._true
|
3230 | node.raw = this.type.keyword
|
3231 | this.next()
|
3232 | return this.finishNode(node, "Literal")
|
3233 |
|
3234 | case tt.parenL:
|
3235 | return this.parseParenAndDistinguishExpression(canBeArrow)
|
3236 |
|
3237 | case tt.bracketL:
|
3238 | node = this.startNode()
|
3239 | this.next()
|
3240 | node.elements = this.parseExprList(tt.bracketR, true, true, refDestructuringErrors)
|
3241 | return this.finishNode(node, "ArrayExpression")
|
3242 |
|
3243 | case tt.braceL:
|
3244 | return this.parseObj(false, refDestructuringErrors)
|
3245 |
|
3246 | case tt._function:
|
3247 | node = this.startNode()
|
3248 | this.next()
|
3249 | return this.parseFunction(node, false)
|
3250 |
|
3251 | case tt._class:
|
3252 | return this.parseClass(this.startNode(), false)
|
3253 |
|
3254 | case tt._new:
|
3255 | return this.parseNew()
|
3256 |
|
3257 | case tt.backQuote:
|
3258 | return this.parseTemplate()
|
3259 |
|
3260 | default:
|
3261 | this.unexpected()
|
3262 | }
|
3263 | }
|
3264 |
|
3265 | pp$3.parseLiteral = function(value) {
|
3266 | var node = this.startNode()
|
3267 | node.value = value
|
3268 | node.raw = this.input.slice(this.start, this.end)
|
3269 | this.next()
|
3270 | return this.finishNode(node, "Literal")
|
3271 | }
|
3272 |
|
3273 | pp$3.parseParenExpression = function() {
|
3274 | this.expect(tt.parenL)
|
3275 | var val = this.parseExpression()
|
3276 | this.expect(tt.parenR)
|
3277 | return val
|
3278 | }
|
3279 |
|
3280 | pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
|
3281 | var this$1 = this;
|
3282 |
|
3283 | var startPos = this.start, startLoc = this.startLoc, val
|
3284 | if (this.options.ecmaVersion >= 6) {
|
3285 | this.next()
|
3286 |
|
3287 | var innerStartPos = this.start, innerStartLoc = this.startLoc
|
3288 | var exprList = [], first = true
|
3289 | var refDestructuringErrors = new DestructuringErrors, spreadStart, innerParenStart
|
3290 | while (this.type !== tt.parenR) {
|
3291 | first ? first = false : this$1.expect(tt.comma)
|
3292 | if (this$1.type === tt.ellipsis) {
|
3293 | spreadStart = this$1.start
|
3294 | exprList.push(this$1.parseParenItem(this$1.parseRest()))
|
3295 | break
|
3296 | } else {
|
3297 | if (this$1.type === tt.parenL && !innerParenStart) {
|
3298 | innerParenStart = this$1.start
|
3299 | }
|
3300 | exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem))
|
3301 | }
|
3302 | }
|
3303 | var innerEndPos = this.start, innerEndLoc = this.startLoc
|
3304 | this.expect(tt.parenR)
|
3305 |
|
3306 | if (canBeArrow && !this.canInsertSemicolon() && this.eat(tt.arrow)) {
|
3307 | this.checkPatternErrors(refDestructuringErrors, true)
|
3308 | if (innerParenStart) this.unexpected(innerParenStart)
|
3309 | return this.parseParenArrowList(startPos, startLoc, exprList)
|
3310 | }
|
3311 |
|
3312 | if (!exprList.length) this.unexpected(this.lastTokStart)
|
3313 | if (spreadStart) this.unexpected(spreadStart)
|
3314 | this.checkExpressionErrors(refDestructuringErrors, true)
|
3315 |
|
3316 | if (exprList.length > 1) {
|
3317 | val = this.startNodeAt(innerStartPos, innerStartLoc)
|
3318 | val.expressions = exprList
|
3319 | this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc)
|
3320 | } else {
|
3321 | val = exprList[0]
|
3322 | }
|
3323 | } else {
|
3324 | val = this.parseParenExpression()
|
3325 | }
|
3326 |
|
3327 | if (this.options.preserveParens) {
|
3328 | var par = this.startNodeAt(startPos, startLoc)
|
3329 | par.expression = val
|
3330 | return this.finishNode(par, "ParenthesizedExpression")
|
3331 | } else {
|
3332 | return val
|
3333 | }
|
3334 | }
|
3335 |
|
3336 | pp$3.parseParenItem = function(item) {
|
3337 | return item
|
3338 | }
|
3339 |
|
3340 | pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
|
3341 | return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
|
3342 | }
|
3343 |
|
3344 |
|
3345 |
|
3346 |
|
3347 |
|
3348 |
|
3349 |
|
3350 | var empty$1 = []
|
3351 |
|
3352 | pp$3.parseNew = function() {
|
3353 | var node = this.startNode()
|
3354 | var meta = this.parseIdent(true)
|
3355 | if (this.options.ecmaVersion >= 6 && this.eat(tt.dot)) {
|
3356 | node.meta = meta
|
3357 | node.property = this.parseIdent(true)
|
3358 | if (node.property.name !== "target")
|
3359 | this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target")
|
3360 | if (!this.inFunction)
|
3361 | this.raiseRecoverable(node.start, "new.target can only be used in functions")
|
3362 | return this.finishNode(node, "MetaProperty")
|
3363 | }
|
3364 | var startPos = this.start, startLoc = this.startLoc
|
3365 | node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true)
|
3366 | if (this.eat(tt.parenL)) node.arguments = this.parseExprList(tt.parenR, false)
|
3367 | else node.arguments = empty$1
|
3368 | return this.finishNode(node, "NewExpression")
|
3369 | }
|
3370 |
|
3371 |
|
3372 |
|
3373 | pp$3.parseTemplateElement = function() {
|
3374 | var elem = this.startNode()
|
3375 | elem.value = {
|
3376 | raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, '\n'),
|
3377 | cooked: this.value
|
3378 | }
|
3379 | this.next()
|
3380 | elem.tail = this.type === tt.backQuote
|
3381 | return this.finishNode(elem, "TemplateElement")
|
3382 | }
|
3383 |
|
3384 | pp$3.parseTemplate = function() {
|
3385 | var this$1 = this;
|
3386 |
|
3387 | var node = this.startNode()
|
3388 | this.next()
|
3389 | node.expressions = []
|
3390 | var curElt = this.parseTemplateElement()
|
3391 | node.quasis = [curElt]
|
3392 | while (!curElt.tail) {
|
3393 | this$1.expect(tt.dollarBraceL)
|
3394 | node.expressions.push(this$1.parseExpression())
|
3395 | this$1.expect(tt.braceR)
|
3396 | node.quasis.push(curElt = this$1.parseTemplateElement())
|
3397 | }
|
3398 | this.next()
|
3399 | return this.finishNode(node, "TemplateLiteral")
|
3400 | }
|
3401 |
|
3402 |
|
3403 |
|
3404 | pp$3.parseObj = function(isPattern, refDestructuringErrors) {
|
3405 | var this$1 = this;
|
3406 |
|
3407 | var node = this.startNode(), first = true, propHash = {}
|
3408 | node.properties = []
|
3409 | this.next()
|
3410 | while (!this.eat(tt.braceR)) {
|
3411 | if (!first) {
|
3412 | this$1.expect(tt.comma)
|
3413 | if (this$1.afterTrailingComma(tt.braceR)) break
|
3414 | } else first = false
|
3415 |
|
3416 | var prop = this$1.startNode(), isGenerator, startPos, startLoc
|
3417 | if (this$1.options.ecmaVersion >= 6) {
|
3418 | prop.method = false
|
3419 | prop.shorthand = false
|
3420 | if (isPattern || refDestructuringErrors) {
|
3421 | startPos = this$1.start
|
3422 | startLoc = this$1.startLoc
|
3423 | }
|
3424 | if (!isPattern)
|
3425 | isGenerator = this$1.eat(tt.star)
|
3426 | }
|
3427 | this$1.parsePropertyName(prop)
|
3428 | this$1.parsePropertyValue(prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors)
|
3429 | this$1.checkPropClash(prop, propHash)
|
3430 | node.properties.push(this$1.finishNode(prop, "Property"))
|
3431 | }
|
3432 | return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
|
3433 | }
|
3434 |
|
3435 | pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, startPos, startLoc, refDestructuringErrors) {
|
3436 | if (this.eat(tt.colon)) {
|
3437 | prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors)
|
3438 | prop.kind = "init"
|
3439 | } else if (this.options.ecmaVersion >= 6 && this.type === tt.parenL) {
|
3440 | if (isPattern) this.unexpected()
|
3441 | prop.kind = "init"
|
3442 | prop.method = true
|
3443 | prop.value = this.parseMethod(isGenerator)
|
3444 | } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
|
3445 | (prop.key.name === "get" || prop.key.name === "set") &&
|
3446 | (this.type != tt.comma && this.type != tt.braceR)) {
|
3447 | if (isGenerator || isPattern) this.unexpected()
|
3448 | prop.kind = prop.key.name
|
3449 | this.parsePropertyName(prop)
|
3450 | prop.value = this.parseMethod(false)
|
3451 | var paramCount = prop.kind === "get" ? 0 : 1
|
3452 | if (prop.value.params.length !== paramCount) {
|
3453 | var start = prop.value.start
|
3454 | if (prop.kind === "get")
|
3455 | this.raiseRecoverable(start, "getter should have no params")
|
3456 | else
|
3457 | this.raiseRecoverable(start, "setter should have exactly one param")
|
3458 | }
|
3459 | if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
|
3460 | this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params")
|
3461 | } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
|
3462 | if (this.keywords.test(prop.key.name) ||
|
3463 | (this.strict ? this.reservedWordsStrictBind : this.reservedWords).test(prop.key.name) ||
|
3464 | (this.inGenerator && prop.key.name == "yield"))
|
3465 | this.raiseRecoverable(prop.key.start, "'" + prop.key.name + "' can not be used as shorthand property")
|
3466 | prop.kind = "init"
|
3467 | if (isPattern) {
|
3468 | prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key)
|
3469 | } else if (this.type === tt.eq && refDestructuringErrors) {
|
3470 | if (!refDestructuringErrors.shorthandAssign)
|
3471 | refDestructuringErrors.shorthandAssign = this.start
|
3472 | prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key)
|
3473 | } else {
|
3474 | prop.value = prop.key
|
3475 | }
|
3476 | prop.shorthand = true
|
3477 | } else this.unexpected()
|
3478 | }
|
3479 |
|
3480 | pp$3.parsePropertyName = function(prop) {
|
3481 | if (this.options.ecmaVersion >= 6) {
|
3482 | if (this.eat(tt.bracketL)) {
|
3483 | prop.computed = true
|
3484 | prop.key = this.parseMaybeAssign()
|
3485 | this.expect(tt.bracketR)
|
3486 | return prop.key
|
3487 | } else {
|
3488 | prop.computed = false
|
3489 | }
|
3490 | }
|
3491 | return prop.key = this.type === tt.num || this.type === tt.string ? this.parseExprAtom() : this.parseIdent(true)
|
3492 | }
|
3493 |
|
3494 |
|
3495 |
|
3496 | pp$3.initFunction = function(node) {
|
3497 | node.id = null
|
3498 | if (this.options.ecmaVersion >= 6) {
|
3499 | node.generator = false
|
3500 | node.expression = false
|
3501 | }
|
3502 | }
|
3503 |
|
3504 |
|
3505 |
|
3506 | pp$3.parseMethod = function(isGenerator) {
|
3507 | var node = this.startNode(), oldInGen = this.inGenerator
|
3508 | this.inGenerator = isGenerator
|
3509 | this.initFunction(node)
|
3510 | this.expect(tt.parenL)
|
3511 | node.params = this.parseBindingList(tt.parenR, false, false)
|
3512 | if (this.options.ecmaVersion >= 6)
|
3513 | node.generator = isGenerator
|
3514 | this.parseFunctionBody(node, false)
|
3515 | this.inGenerator = oldInGen
|
3516 | return this.finishNode(node, "FunctionExpression")
|
3517 | }
|
3518 |
|
3519 |
|
3520 |
|
3521 | pp$3.parseArrowExpression = function(node, params) {
|
3522 | var oldInGen = this.inGenerator
|
3523 | this.inGenerator = false
|
3524 | this.initFunction(node)
|
3525 | node.params = this.toAssignableList(params, true)
|
3526 | this.parseFunctionBody(node, true)
|
3527 | this.inGenerator = oldInGen
|
3528 | return this.finishNode(node, "ArrowFunctionExpression")
|
3529 | }
|
3530 |
|
3531 |
|
3532 |
|
3533 | pp$3.parseFunctionBody = function(node, isArrowFunction) {
|
3534 | var isExpression = isArrowFunction && this.type !== tt.braceL
|
3535 |
|
3536 | if (isExpression) {
|
3537 | node.body = this.parseMaybeAssign()
|
3538 | node.expression = true
|
3539 | } else {
|
3540 |
|
3541 |
|
3542 | var oldInFunc = this.inFunction, oldLabels = this.labels
|
3543 | this.inFunction = true; this.labels = []
|
3544 | node.body = this.parseBlock(true)
|
3545 | node.expression = false
|
3546 | this.inFunction = oldInFunc; this.labels = oldLabels
|
3547 | }
|
3548 |
|
3549 |
|
3550 |
|
3551 |
|
3552 | if (this.strict || !isExpression && node.body.body.length && this.isUseStrict(node.body.body[0])) {
|
3553 | var oldStrict = this.strict
|
3554 | this.strict = true
|
3555 | if (node.id)
|
3556 | this.checkLVal(node.id, true)
|
3557 | this.checkParams(node)
|
3558 | this.strict = oldStrict
|
3559 | } else if (isArrowFunction) {
|
3560 | this.checkParams(node)
|
3561 | }
|
3562 | }
|
3563 |
|
3564 |
|
3565 |
|
3566 |
|
3567 | pp$3.checkParams = function(node) {
|
3568 | var this$1 = this;
|
3569 |
|
3570 | var nameHash = {}
|
3571 | for (var i = 0; i < node.params.length; i++)
|
3572 | this$1.checkLVal(node.params[i], true, nameHash)
|
3573 | }
|
3574 |
|
3575 |
|
3576 |
|
3577 |
|
3578 |
|
3579 |
|
3580 |
|
3581 | pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
|
3582 | var this$1 = this;
|
3583 |
|
3584 | var elts = [], first = true
|
3585 | while (!this.eat(close)) {
|
3586 | if (!first) {
|
3587 | this$1.expect(tt.comma)
|
3588 | if (allowTrailingComma && this$1.afterTrailingComma(close)) break
|
3589 | } else first = false
|
3590 |
|
3591 | var elt
|
3592 | if (allowEmpty && this$1.type === tt.comma)
|
3593 | elt = null
|
3594 | else if (this$1.type === tt.ellipsis) {
|
3595 | elt = this$1.parseSpread(refDestructuringErrors)
|
3596 | if (this$1.type === tt.comma && refDestructuringErrors && !refDestructuringErrors.trailingComma) {
|
3597 | refDestructuringErrors.trailingComma = this$1.lastTokStart
|
3598 | }
|
3599 | } else
|
3600 | elt = this$1.parseMaybeAssign(false, refDestructuringErrors)
|
3601 | elts.push(elt)
|
3602 | }
|
3603 | return elts
|
3604 | }
|
3605 |
|
3606 |
|
3607 |
|
3608 |
|
3609 |
|
3610 | pp$3.parseIdent = function(liberal) {
|
3611 | var node = this.startNode()
|
3612 | if (liberal && this.options.allowReserved == "never") liberal = false
|
3613 | if (this.type === tt.name) {
|
3614 | if (!liberal && (this.strict ? this.reservedWordsStrict : this.reservedWords).test(this.value) &&
|
3615 | (this.options.ecmaVersion >= 6 ||
|
3616 | this.input.slice(this.start, this.end).indexOf("\\") == -1))
|
3617 | this.raiseRecoverable(this.start, "The keyword '" + this.value + "' is reserved")
|
3618 | if (!liberal && this.inGenerator && this.value === "yield")
|
3619 | this.raiseRecoverable(this.start, "Can not use 'yield' as identifier inside a generator")
|
3620 | node.name = this.value
|
3621 | } else if (liberal && this.type.keyword) {
|
3622 | node.name = this.type.keyword
|
3623 | } else {
|
3624 | this.unexpected()
|
3625 | }
|
3626 | this.next()
|
3627 | return this.finishNode(node, "Identifier")
|
3628 | }
|
3629 |
|
3630 |
|
3631 |
|
3632 | pp$3.parseYield = function() {
|
3633 | var node = this.startNode()
|
3634 | this.next()
|
3635 | if (this.type == tt.semi || this.canInsertSemicolon() || (this.type != tt.star && !this.type.startsExpr)) {
|
3636 | node.delegate = false
|
3637 | node.argument = null
|
3638 | } else {
|
3639 | node.delegate = this.eat(tt.star)
|
3640 | node.argument = this.parseMaybeAssign()
|
3641 | }
|
3642 | return this.finishNode(node, "YieldExpression")
|
3643 | }
|
3644 |
|
3645 | var pp$4 = Parser.prototype
|
3646 |
|
3647 |
|
3648 |
|
3649 |
|
3650 |
|
3651 |
|
3652 |
|
3653 | pp$4.raise = function(pos, message) {
|
3654 | var loc = getLineInfo(this.input, pos)
|
3655 | message += " (" + loc.line + ":" + loc.column + ")"
|
3656 | var err = new SyntaxError(message)
|
3657 | err.pos = pos; err.loc = loc; err.raisedAt = this.pos
|
3658 | throw err
|
3659 | }
|
3660 |
|
3661 | pp$4.raiseRecoverable = pp$4.raise
|
3662 |
|
3663 | pp$4.curPosition = function() {
|
3664 | if (this.options.locations) {
|
3665 | return new Position(this.curLine, this.pos - this.lineStart)
|
3666 | }
|
3667 | }
|
3668 |
|
3669 | var Node = function Node(parser, pos, loc) {
|
3670 | this.type = ""
|
3671 | this.start = pos
|
3672 | this.end = 0
|
3673 | if (parser.options.locations)
|
3674 | this.loc = new SourceLocation(parser, loc)
|
3675 | if (parser.options.directSourceFile)
|
3676 | this.sourceFile = parser.options.directSourceFile
|
3677 | if (parser.options.ranges)
|
3678 | this.range = [pos, 0]
|
3679 | };
|
3680 |
|
3681 |
|
3682 |
|
3683 | var pp$5 = Parser.prototype
|
3684 |
|
3685 | pp$5.startNode = function() {
|
3686 | return new Node(this, this.start, this.startLoc)
|
3687 | }
|
3688 |
|
3689 | pp$5.startNodeAt = function(pos, loc) {
|
3690 | return new Node(this, pos, loc)
|
3691 | }
|
3692 |
|
3693 |
|
3694 |
|
3695 | function finishNodeAt(node, type, pos, loc) {
|
3696 | node.type = type
|
3697 | node.end = pos
|
3698 | if (this.options.locations)
|
3699 | node.loc.end = loc
|
3700 | if (this.options.ranges)
|
3701 | node.range[1] = pos
|
3702 | return node
|
3703 | }
|
3704 |
|
3705 | pp$5.finishNode = function(node, type) {
|
3706 | return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
|
3707 | }
|
3708 |
|
3709 |
|
3710 |
|
3711 | pp$5.finishNodeAt = function(node, type, pos, loc) {
|
3712 | return finishNodeAt.call(this, node, type, pos, loc)
|
3713 | }
|
3714 |
|
3715 | var TokContext = function TokContext(token, isExpr, preserveSpace, override) {
|
3716 | this.token = token
|
3717 | this.isExpr = !!isExpr
|
3718 | this.preserveSpace = !!preserveSpace
|
3719 | this.override = override
|
3720 | };
|
3721 |
|
3722 | var types = {
|
3723 | b_stat: new TokContext("{", false),
|
3724 | b_expr: new TokContext("{", true),
|
3725 | b_tmpl: new TokContext("${", true),
|
3726 | p_stat: new TokContext("(", false),
|
3727 | p_expr: new TokContext("(", true),
|
3728 | q_tmpl: new TokContext("`", true, true, function (p) { return p.readTmplToken(); }),
|
3729 | f_expr: new TokContext("function", true)
|
3730 | }
|
3731 |
|
3732 | var pp$6 = Parser.prototype
|
3733 |
|
3734 | pp$6.initialContext = function() {
|
3735 | return [types.b_stat]
|
3736 | }
|
3737 |
|
3738 | pp$6.braceIsBlock = function(prevType) {
|
3739 | if (prevType === tt.colon) {
|
3740 | var parent = this.curContext()
|
3741 | if (parent === types.b_stat || parent === types.b_expr)
|
3742 | return !parent.isExpr
|
3743 | }
|
3744 | if (prevType === tt._return)
|
3745 | return lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
|
3746 | if (prevType === tt._else || prevType === tt.semi || prevType === tt.eof || prevType === tt.parenR)
|
3747 | return true
|
3748 | if (prevType == tt.braceL)
|
3749 | return this.curContext() === types.b_stat
|
3750 | return !this.exprAllowed
|
3751 | }
|
3752 |
|
3753 | pp$6.updateContext = function(prevType) {
|
3754 | var update, type = this.type
|
3755 | if (type.keyword && prevType == tt.dot)
|
3756 | this.exprAllowed = false
|
3757 | else if (update = type.updateContext)
|
3758 | update.call(this, prevType)
|
3759 | else
|
3760 | this.exprAllowed = type.beforeExpr
|
3761 | }
|
3762 |
|
3763 |
|
3764 |
|
3765 | tt.parenR.updateContext = tt.braceR.updateContext = function() {
|
3766 | if (this.context.length == 1) {
|
3767 | this.exprAllowed = true
|
3768 | return
|
3769 | }
|
3770 | var out = this.context.pop()
|
3771 | if (out === types.b_stat && this.curContext() === types.f_expr) {
|
3772 | this.context.pop()
|
3773 | this.exprAllowed = false
|
3774 | } else if (out === types.b_tmpl) {
|
3775 | this.exprAllowed = true
|
3776 | } else {
|
3777 | this.exprAllowed = !out.isExpr
|
3778 | }
|
3779 | }
|
3780 |
|
3781 | tt.braceL.updateContext = function(prevType) {
|
3782 | this.context.push(this.braceIsBlock(prevType) ? types.b_stat : types.b_expr)
|
3783 | this.exprAllowed = true
|
3784 | }
|
3785 |
|
3786 | tt.dollarBraceL.updateContext = function() {
|
3787 | this.context.push(types.b_tmpl)
|
3788 | this.exprAllowed = true
|
3789 | }
|
3790 |
|
3791 | tt.parenL.updateContext = function(prevType) {
|
3792 | var statementParens = prevType === tt._if || prevType === tt._for || prevType === tt._with || prevType === tt._while
|
3793 | this.context.push(statementParens ? types.p_stat : types.p_expr)
|
3794 | this.exprAllowed = true
|
3795 | }
|
3796 |
|
3797 | tt.incDec.updateContext = function() {
|
3798 |
|
3799 | }
|
3800 |
|
3801 | tt._function.updateContext = function(prevType) {
|
3802 | if (prevType.beforeExpr && prevType !== tt.semi && prevType !== tt._else &&
|
3803 | (prevType !== tt.colon || this.curContext() !== types.b_stat))
|
3804 | this.context.push(types.f_expr)
|
3805 | this.exprAllowed = false
|
3806 | }
|
3807 |
|
3808 | tt.backQuote.updateContext = function() {
|
3809 | if (this.curContext() === types.q_tmpl)
|
3810 | this.context.pop()
|
3811 | else
|
3812 | this.context.push(types.q_tmpl)
|
3813 | this.exprAllowed = false
|
3814 | }
|
3815 |
|
3816 |
|
3817 |
|
3818 |
|
3819 |
|
3820 | var Token = function Token(p) {
|
3821 | this.type = p.type
|
3822 | this.value = p.value
|
3823 | this.start = p.start
|
3824 | this.end = p.end
|
3825 | if (p.options.locations)
|
3826 | this.loc = new SourceLocation(p, p.startLoc, p.endLoc)
|
3827 | if (p.options.ranges)
|
3828 | this.range = [p.start, p.end]
|
3829 | };
|
3830 |
|
3831 |
|
3832 |
|
3833 | var pp$7 = Parser.prototype
|
3834 |
|
3835 |
|
3836 | var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]"
|
3837 |
|
3838 |
|
3839 |
|
3840 | pp$7.next = function() {
|
3841 | if (this.options.onToken)
|
3842 | this.options.onToken(new Token(this))
|
3843 |
|
3844 | this.lastTokEnd = this.end
|
3845 | this.lastTokStart = this.start
|
3846 | this.lastTokEndLoc = this.endLoc
|
3847 | this.lastTokStartLoc = this.startLoc
|
3848 | this.nextToken()
|
3849 | }
|
3850 |
|
3851 | pp$7.getToken = function() {
|
3852 | this.next()
|
3853 | return new Token(this)
|
3854 | }
|
3855 |
|
3856 |
|
3857 | if (typeof Symbol !== "undefined")
|
3858 | pp$7[Symbol.iterator] = function () {
|
3859 | var self = this
|
3860 | return {next: function () {
|
3861 | var token = self.getToken()
|
3862 | return {
|
3863 | done: token.type === tt.eof,
|
3864 | value: token
|
3865 | }
|
3866 | }}
|
3867 | }
|
3868 |
|
3869 |
|
3870 |
|
3871 |
|
3872 | pp$7.setStrict = function(strict) {
|
3873 | var this$1 = this;
|
3874 |
|
3875 | this.strict = strict
|
3876 | if (this.type !== tt.num && this.type !== tt.string) return
|
3877 | this.pos = this.start
|
3878 | if (this.options.locations) {
|
3879 | while (this.pos < this.lineStart) {
|
3880 | this$1.lineStart = this$1.input.lastIndexOf("\n", this$1.lineStart - 2) + 1
|
3881 | --this$1.curLine
|
3882 | }
|
3883 | }
|
3884 | this.nextToken()
|
3885 | }
|
3886 |
|
3887 | pp$7.curContext = function() {
|
3888 | return this.context[this.context.length - 1]
|
3889 | }
|
3890 |
|
3891 |
|
3892 |
|
3893 |
|
3894 | pp$7.nextToken = function() {
|
3895 | var curContext = this.curContext()
|
3896 | if (!curContext || !curContext.preserveSpace) this.skipSpace()
|
3897 |
|
3898 | this.start = this.pos
|
3899 | if (this.options.locations) this.startLoc = this.curPosition()
|
3900 | if (this.pos >= this.input.length) return this.finishToken(tt.eof)
|
3901 |
|
3902 | if (curContext.override) return curContext.override(this)
|
3903 | else this.readToken(this.fullCharCodeAtPos())
|
3904 | }
|
3905 |
|
3906 | pp$7.readToken = function(code) {
|
3907 |
|
3908 |
|
3909 | if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 )
|
3910 | return this.readWord()
|
3911 |
|
3912 | return this.getTokenFromCode(code)
|
3913 | }
|
3914 |
|
3915 | pp$7.fullCharCodeAtPos = function() {
|
3916 | var code = this.input.charCodeAt(this.pos)
|
3917 | if (code <= 0xd7ff || code >= 0xe000) return code
|
3918 | var next = this.input.charCodeAt(this.pos + 1)
|
3919 | return (code << 10) + next - 0x35fdc00
|
3920 | }
|
3921 |
|
3922 | pp$7.skipBlockComment = function() {
|
3923 | var this$1 = this;
|
3924 |
|
3925 | var startLoc = this.options.onComment && this.curPosition()
|
3926 | var start = this.pos, end = this.input.indexOf("*/", this.pos += 2)
|
3927 | if (end === -1) this.raise(this.pos - 2, "Unterminated comment")
|
3928 | this.pos = end + 2
|
3929 | if (this.options.locations) {
|
3930 | lineBreakG.lastIndex = start
|
3931 | var match
|
3932 | while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
|
3933 | ++this$1.curLine
|
3934 | this$1.lineStart = match.index + match[0].length
|
3935 | }
|
3936 | }
|
3937 | if (this.options.onComment)
|
3938 | this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
|
3939 | startLoc, this.curPosition())
|
3940 | }
|
3941 |
|
3942 | pp$7.skipLineComment = function(startSkip) {
|
3943 | var this$1 = this;
|
3944 |
|
3945 | var start = this.pos
|
3946 | var startLoc = this.options.onComment && this.curPosition()
|
3947 | var ch = this.input.charCodeAt(this.pos+=startSkip)
|
3948 | while (this.pos < this.input.length && ch !== 10 && ch !== 13 && ch !== 8232 && ch !== 8233) {
|
3949 | ++this$1.pos
|
3950 | ch = this$1.input.charCodeAt(this$1.pos)
|
3951 | }
|
3952 | if (this.options.onComment)
|
3953 | this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
|
3954 | startLoc, this.curPosition())
|
3955 | }
|
3956 |
|
3957 |
|
3958 |
|
3959 |
|
3960 | pp$7.skipSpace = function() {
|
3961 | var this$1 = this;
|
3962 |
|
3963 | loop: while (this.pos < this.input.length) {
|
3964 | var ch = this$1.input.charCodeAt(this$1.pos)
|
3965 | switch (ch) {
|
3966 | case 32: case 160:
|
3967 | ++this$1.pos
|
3968 | break
|
3969 | case 13:
|
3970 | if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
|
3971 | ++this$1.pos
|
3972 | }
|
3973 | case 10: case 8232: case 8233:
|
3974 | ++this$1.pos
|
3975 | if (this$1.options.locations) {
|
3976 | ++this$1.curLine
|
3977 | this$1.lineStart = this$1.pos
|
3978 | }
|
3979 | break
|
3980 | case 47:
|
3981 | switch (this$1.input.charCodeAt(this$1.pos + 1)) {
|
3982 | case 42:
|
3983 | this$1.skipBlockComment()
|
3984 | break
|
3985 | case 47:
|
3986 | this$1.skipLineComment(2)
|
3987 | break
|
3988 | default:
|
3989 | break loop
|
3990 | }
|
3991 | break
|
3992 | default:
|
3993 | if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
|
3994 | ++this$1.pos
|
3995 | } else {
|
3996 | break loop
|
3997 | }
|
3998 | }
|
3999 | }
|
4000 | }
|
4001 |
|
4002 |
|
4003 |
|
4004 |
|
4005 |
|
4006 |
|
4007 | pp$7.finishToken = function(type, val) {
|
4008 | this.end = this.pos
|
4009 | if (this.options.locations) this.endLoc = this.curPosition()
|
4010 | var prevType = this.type
|
4011 | this.type = type
|
4012 | this.value = val
|
4013 |
|
4014 | this.updateContext(prevType)
|
4015 | }
|
4016 |
|
4017 |
|
4018 |
|
4019 |
|
4020 |
|
4021 |
|
4022 |
|
4023 |
|
4024 |
|
4025 |
|
4026 | pp$7.readToken_dot = function() {
|
4027 | var next = this.input.charCodeAt(this.pos + 1)
|
4028 | if (next >= 48 && next <= 57) return this.readNumber(true)
|
4029 | var next2 = this.input.charCodeAt(this.pos + 2)
|
4030 | if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) {
|
4031 | this.pos += 3
|
4032 | return this.finishToken(tt.ellipsis)
|
4033 | } else {
|
4034 | ++this.pos
|
4035 | return this.finishToken(tt.dot)
|
4036 | }
|
4037 | }
|
4038 |
|
4039 | pp$7.readToken_slash = function() {
|
4040 | var next = this.input.charCodeAt(this.pos + 1)
|
4041 | if (this.exprAllowed) {++this.pos; return this.readRegexp()}
|
4042 | if (next === 61) return this.finishOp(tt.assign, 2)
|
4043 | return this.finishOp(tt.slash, 1)
|
4044 | }
|
4045 |
|
4046 | pp$7.readToken_mult_modulo_exp = function(code) {
|
4047 | var next = this.input.charCodeAt(this.pos + 1)
|
4048 | var size = 1
|
4049 | var tokentype = code === 42 ? tt.star : tt.modulo
|
4050 |
|
4051 |
|
4052 | if (this.options.ecmaVersion >= 7 && next === 42) {
|
4053 | ++size
|
4054 | tokentype = tt.starstar
|
4055 | next = this.input.charCodeAt(this.pos + 2)
|
4056 | }
|
4057 |
|
4058 | if (next === 61) return this.finishOp(tt.assign, size + 1)
|
4059 | return this.finishOp(tokentype, size)
|
4060 | }
|
4061 |
|
4062 | pp$7.readToken_pipe_amp = function(code) {
|
4063 | var next = this.input.charCodeAt(this.pos + 1)
|
4064 | if (next === code) return this.finishOp(code === 124 ? tt.logicalOR : tt.logicalAND, 2)
|
4065 | if (next === 61) return this.finishOp(tt.assign, 2)
|
4066 | return this.finishOp(code === 124 ? tt.bitwiseOR : tt.bitwiseAND, 1)
|
4067 | }
|
4068 |
|
4069 | pp$7.readToken_caret = function() {
|
4070 | var next = this.input.charCodeAt(this.pos + 1)
|
4071 | if (next === 61) return this.finishOp(tt.assign, 2)
|
4072 | return this.finishOp(tt.bitwiseXOR, 1)
|
4073 | }
|
4074 |
|
4075 | pp$7.readToken_plus_min = function(code) {
|
4076 | var next = this.input.charCodeAt(this.pos + 1)
|
4077 | if (next === code) {
|
4078 | if (next == 45 && this.input.charCodeAt(this.pos + 2) == 62 &&
|
4079 | lineBreak.test(this.input.slice(this.lastTokEnd, this.pos))) {
|
4080 |
|
4081 | this.skipLineComment(3)
|
4082 | this.skipSpace()
|
4083 | return this.nextToken()
|
4084 | }
|
4085 | return this.finishOp(tt.incDec, 2)
|
4086 | }
|
4087 | if (next === 61) return this.finishOp(tt.assign, 2)
|
4088 | return this.finishOp(tt.plusMin, 1)
|
4089 | }
|
4090 |
|
4091 | pp$7.readToken_lt_gt = function(code) {
|
4092 | var next = this.input.charCodeAt(this.pos + 1)
|
4093 | var size = 1
|
4094 | if (next === code) {
|
4095 | size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2
|
4096 | if (this.input.charCodeAt(this.pos + size) === 61) return this.finishOp(tt.assign, size + 1)
|
4097 | return this.finishOp(tt.bitShift, size)
|
4098 | }
|
4099 | if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 &&
|
4100 | this.input.charCodeAt(this.pos + 3) == 45) {
|
4101 | if (this.inModule) this.unexpected()
|
4102 |
|
4103 | this.skipLineComment(4)
|
4104 | this.skipSpace()
|
4105 | return this.nextToken()
|
4106 | }
|
4107 | if (next === 61) size = 2
|
4108 | return this.finishOp(tt.relational, size)
|
4109 | }
|
4110 |
|
4111 | pp$7.readToken_eq_excl = function(code) {
|
4112 | var next = this.input.charCodeAt(this.pos + 1)
|
4113 | if (next === 61) return this.finishOp(tt.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2)
|
4114 | if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) {
|
4115 | this.pos += 2
|
4116 | return this.finishToken(tt.arrow)
|
4117 | }
|
4118 | return this.finishOp(code === 61 ? tt.eq : tt.prefix, 1)
|
4119 | }
|
4120 |
|
4121 | pp$7.getTokenFromCode = function(code) {
|
4122 | switch (code) {
|
4123 |
|
4124 |
|
4125 | case 46:
|
4126 | return this.readToken_dot()
|
4127 |
|
4128 |
|
4129 | case 40: ++this.pos; return this.finishToken(tt.parenL)
|
4130 | case 41: ++this.pos; return this.finishToken(tt.parenR)
|
4131 | case 59: ++this.pos; return this.finishToken(tt.semi)
|
4132 | case 44: ++this.pos; return this.finishToken(tt.comma)
|
4133 | case 91: ++this.pos; return this.finishToken(tt.bracketL)
|
4134 | case 93: ++this.pos; return this.finishToken(tt.bracketR)
|
4135 | case 123: ++this.pos; return this.finishToken(tt.braceL)
|
4136 | case 125: ++this.pos; return this.finishToken(tt.braceR)
|
4137 | case 58: ++this.pos; return this.finishToken(tt.colon)
|
4138 | case 63: ++this.pos; return this.finishToken(tt.question)
|
4139 |
|
4140 | case 96:
|
4141 | if (this.options.ecmaVersion < 6) break
|
4142 | ++this.pos
|
4143 | return this.finishToken(tt.backQuote)
|
4144 |
|
4145 | case 48:
|
4146 | var next = this.input.charCodeAt(this.pos + 1)
|
4147 | if (next === 120 || next === 88) return this.readRadixNumber(16)
|
4148 | if (this.options.ecmaVersion >= 6) {
|
4149 | if (next === 111 || next === 79) return this.readRadixNumber(8)
|
4150 | if (next === 98 || next === 66) return this.readRadixNumber(2)
|
4151 | }
|
4152 |
|
4153 |
|
4154 | case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57:
|
4155 | return this.readNumber(false)
|
4156 |
|
4157 |
|
4158 | case 34: case 39:
|
4159 | return this.readString(code)
|
4160 |
|
4161 |
|
4162 |
|
4163 |
|
4164 |
|
4165 |
|
4166 | case 47:
|
4167 | return this.readToken_slash()
|
4168 |
|
4169 | case 37: case 42:
|
4170 | return this.readToken_mult_modulo_exp(code)
|
4171 |
|
4172 | case 124: case 38:
|
4173 | return this.readToken_pipe_amp(code)
|
4174 |
|
4175 | case 94:
|
4176 | return this.readToken_caret()
|
4177 |
|
4178 | case 43: case 45:
|
4179 | return this.readToken_plus_min(code)
|
4180 |
|
4181 | case 60: case 62:
|
4182 | return this.readToken_lt_gt(code)
|
4183 |
|
4184 | case 61: case 33:
|
4185 | return this.readToken_eq_excl(code)
|
4186 |
|
4187 | case 126:
|
4188 | return this.finishOp(tt.prefix, 1)
|
4189 | }
|
4190 |
|
4191 | this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'")
|
4192 | }
|
4193 |
|
4194 | pp$7.finishOp = function(type, size) {
|
4195 | var str = this.input.slice(this.pos, this.pos + size)
|
4196 | this.pos += size
|
4197 | return this.finishToken(type, str)
|
4198 | }
|
4199 |
|
4200 |
|
4201 |
|
4202 |
|
4203 | function tryCreateRegexp(src, flags, throwErrorAt, parser) {
|
4204 | try {
|
4205 | return new RegExp(src, flags)
|
4206 | } catch (e) {
|
4207 | if (throwErrorAt !== undefined) {
|
4208 | if (e instanceof SyntaxError) parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message)
|
4209 | throw e
|
4210 | }
|
4211 | }
|
4212 | }
|
4213 |
|
4214 | var regexpUnicodeSupport = !!tryCreateRegexp("\uffff", "u")
|
4215 |
|
4216 | pp$7.readRegexp = function() {
|
4217 | var this$1 = this;
|
4218 |
|
4219 | var escaped, inClass, start = this.pos
|
4220 | for (;;) {
|
4221 | if (this$1.pos >= this$1.input.length) this$1.raise(start, "Unterminated regular expression")
|
4222 | var ch = this$1.input.charAt(this$1.pos)
|
4223 | if (lineBreak.test(ch)) this$1.raise(start, "Unterminated regular expression")
|
4224 | if (!escaped) {
|
4225 | if (ch === "[") inClass = true
|
4226 | else if (ch === "]" && inClass) inClass = false
|
4227 | else if (ch === "/" && !inClass) break
|
4228 | escaped = ch === "\\"
|
4229 | } else escaped = false
|
4230 | ++this$1.pos
|
4231 | }
|
4232 | var content = this.input.slice(start, this.pos)
|
4233 | ++this.pos
|
4234 |
|
4235 |
|
4236 | var mods = this.readWord1()
|
4237 | var tmp = content, tmpFlags = ""
|
4238 | if (mods) {
|
4239 | var validFlags = /^[gim]*$/
|
4240 | if (this.options.ecmaVersion >= 6) validFlags = /^[gimuy]*$/
|
4241 | if (!validFlags.test(mods)) this.raise(start, "Invalid regular expression flag")
|
4242 | if (mods.indexOf("u") >= 0) {
|
4243 | if (regexpUnicodeSupport) {
|
4244 | tmpFlags = "u"
|
4245 | } else {
|
4246 |
|
4247 |
|
4248 |
|
4249 |
|
4250 |
|
4251 |
|
4252 |
|
4253 |
|
4254 | tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, function (_match, code, offset) {
|
4255 | code = Number("0x" + code)
|
4256 | if (code > 0x10FFFF) this$1.raise(start + offset + 3, "Code point out of bounds")
|
4257 | return "x"
|
4258 | })
|
4259 | tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x")
|
4260 | tmpFlags = tmpFlags.replace("u", "")
|
4261 | }
|
4262 | }
|
4263 | }
|
4264 |
|
4265 | var value = null
|
4266 |
|
4267 |
|
4268 | if (!isRhino) {
|
4269 | tryCreateRegexp(tmp, tmpFlags, start, this)
|
4270 |
|
4271 |
|
4272 | value = tryCreateRegexp(content, mods)
|
4273 | }
|
4274 | return this.finishToken(tt.regexp, {pattern: content, flags: mods, value: value})
|
4275 | }
|
4276 |
|
4277 |
|
4278 |
|
4279 |
|
4280 |
|
4281 | pp$7.readInt = function(radix, len) {
|
4282 | var this$1 = this;
|
4283 |
|
4284 | var start = this.pos, total = 0
|
4285 | for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
|
4286 | var code = this$1.input.charCodeAt(this$1.pos), val
|
4287 | if (code >= 97) val = code - 97 + 10
|
4288 | else if (code >= 65) val = code - 65 + 10
|
4289 | else if (code >= 48 && code <= 57) val = code - 48
|
4290 | else val = Infinity
|
4291 | if (val >= radix) break
|
4292 | ++this$1.pos
|
4293 | total = total * radix + val
|
4294 | }
|
4295 | if (this.pos === start || len != null && this.pos - start !== len) return null
|
4296 |
|
4297 | return total
|
4298 | }
|
4299 |
|
4300 | pp$7.readRadixNumber = function(radix) {
|
4301 | this.pos += 2
|
4302 | var val = this.readInt(radix)
|
4303 | if (val == null) this.raise(this.start + 2, "Expected number in radix " + radix)
|
4304 | if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number")
|
4305 | return this.finishToken(tt.num, val)
|
4306 | }
|
4307 |
|
4308 |
|
4309 |
|
4310 | pp$7.readNumber = function(startsWithDot) {
|
4311 | var start = this.pos, isFloat = false, octal = this.input.charCodeAt(this.pos) === 48
|
4312 | if (!startsWithDot && this.readInt(10) === null) this.raise(start, "Invalid number")
|
4313 | var next = this.input.charCodeAt(this.pos)
|
4314 | if (next === 46) {
|
4315 | ++this.pos
|
4316 | this.readInt(10)
|
4317 | isFloat = true
|
4318 | next = this.input.charCodeAt(this.pos)
|
4319 | }
|
4320 | if (next === 69 || next === 101) {
|
4321 | next = this.input.charCodeAt(++this.pos)
|
4322 | if (next === 43 || next === 45) ++this.pos
|
4323 | if (this.readInt(10) === null) this.raise(start, "Invalid number")
|
4324 | isFloat = true
|
4325 | }
|
4326 | if (isIdentifierStart(this.fullCharCodeAtPos())) this.raise(this.pos, "Identifier directly after number")
|
4327 |
|
4328 | var str = this.input.slice(start, this.pos), val
|
4329 | if (isFloat) val = parseFloat(str)
|
4330 | else if (!octal || str.length === 1) val = parseInt(str, 10)
|
4331 | else if (/[89]/.test(str) || this.strict) this.raise(start, "Invalid number")
|
4332 | else val = parseInt(str, 8)
|
4333 | return this.finishToken(tt.num, val)
|
4334 | }
|
4335 |
|
4336 |
|
4337 |
|
4338 | pp$7.readCodePoint = function() {
|
4339 | var ch = this.input.charCodeAt(this.pos), code
|
4340 |
|
4341 | if (ch === 123) {
|
4342 | if (this.options.ecmaVersion < 6) this.unexpected()
|
4343 | var codePos = ++this.pos
|
4344 | code = this.readHexChar(this.input.indexOf('}', this.pos) - this.pos)
|
4345 | ++this.pos
|
4346 | if (code > 0x10FFFF) this.raise(codePos, "Code point out of bounds")
|
4347 | } else {
|
4348 | code = this.readHexChar(4)
|
4349 | }
|
4350 | return code
|
4351 | }
|
4352 |
|
4353 | function codePointToString(code) {
|
4354 |
|
4355 | if (code <= 0xFFFF) return String.fromCharCode(code)
|
4356 | code -= 0x10000
|
4357 | return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
|
4358 | }
|
4359 |
|
4360 | pp$7.readString = function(quote) {
|
4361 | var this$1 = this;
|
4362 |
|
4363 | var out = "", chunkStart = ++this.pos
|
4364 | for (;;) {
|
4365 | if (this$1.pos >= this$1.input.length) this$1.raise(this$1.start, "Unterminated string constant")
|
4366 | var ch = this$1.input.charCodeAt(this$1.pos)
|
4367 | if (ch === quote) break
|
4368 | if (ch === 92) {
|
4369 | out += this$1.input.slice(chunkStart, this$1.pos)
|
4370 | out += this$1.readEscapedChar(false)
|
4371 | chunkStart = this$1.pos
|
4372 | } else {
|
4373 | if (isNewLine(ch)) this$1.raise(this$1.start, "Unterminated string constant")
|
4374 | ++this$1.pos
|
4375 | }
|
4376 | }
|
4377 | out += this.input.slice(chunkStart, this.pos++)
|
4378 | return this.finishToken(tt.string, out)
|
4379 | }
|
4380 |
|
4381 |
|
4382 |
|
4383 | pp$7.readTmplToken = function() {
|
4384 | var this$1 = this;
|
4385 |
|
4386 | var out = "", chunkStart = this.pos
|
4387 | for (;;) {
|
4388 | if (this$1.pos >= this$1.input.length) this$1.raise(this$1.start, "Unterminated template")
|
4389 | var ch = this$1.input.charCodeAt(this$1.pos)
|
4390 | if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) {
|
4391 | if (this$1.pos === this$1.start && this$1.type === tt.template) {
|
4392 | if (ch === 36) {
|
4393 | this$1.pos += 2
|
4394 | return this$1.finishToken(tt.dollarBraceL)
|
4395 | } else {
|
4396 | ++this$1.pos
|
4397 | return this$1.finishToken(tt.backQuote)
|
4398 | }
|
4399 | }
|
4400 | out += this$1.input.slice(chunkStart, this$1.pos)
|
4401 | return this$1.finishToken(tt.template, out)
|
4402 | }
|
4403 | if (ch === 92) {
|
4404 | out += this$1.input.slice(chunkStart, this$1.pos)
|
4405 | out += this$1.readEscapedChar(true)
|
4406 | chunkStart = this$1.pos
|
4407 | } else if (isNewLine(ch)) {
|
4408 | out += this$1.input.slice(chunkStart, this$1.pos)
|
4409 | ++this$1.pos
|
4410 | switch (ch) {
|
4411 | case 13:
|
4412 | if (this$1.input.charCodeAt(this$1.pos) === 10) ++this$1.pos
|
4413 | case 10:
|
4414 | out += "\n"
|
4415 | break
|
4416 | default:
|
4417 | out += String.fromCharCode(ch)
|
4418 | break
|
4419 | }
|
4420 | if (this$1.options.locations) {
|
4421 | ++this$1.curLine
|
4422 | this$1.lineStart = this$1.pos
|
4423 | }
|
4424 | chunkStart = this$1.pos
|
4425 | } else {
|
4426 | ++this$1.pos
|
4427 | }
|
4428 | }
|
4429 | }
|
4430 |
|
4431 |
|
4432 |
|
4433 | pp$7.readEscapedChar = function(inTemplate) {
|
4434 | var ch = this.input.charCodeAt(++this.pos)
|
4435 | ++this.pos
|
4436 | switch (ch) {
|
4437 | case 110: return "\n"
|
4438 | case 114: return "\r"
|
4439 | case 120: return String.fromCharCode(this.readHexChar(2))
|
4440 | case 117: return codePointToString(this.readCodePoint())
|
4441 | case 116: return "\t"
|
4442 | case 98: return "\b"
|
4443 | case 118: return "\u000b"
|
4444 | case 102: return "\f"
|
4445 | case 13: if (this.input.charCodeAt(this.pos) === 10) ++this.pos
|
4446 | case 10:
|
4447 | if (this.options.locations) { this.lineStart = this.pos; ++this.curLine }
|
4448 | return ""
|
4449 | default:
|
4450 | if (ch >= 48 && ch <= 55) {
|
4451 | var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0]
|
4452 | var octal = parseInt(octalStr, 8)
|
4453 | if (octal > 255) {
|
4454 | octalStr = octalStr.slice(0, -1)
|
4455 | octal = parseInt(octalStr, 8)
|
4456 | }
|
4457 | if (octalStr !== "0" && (this.strict || inTemplate)) {
|
4458 | this.raise(this.pos - 2, "Octal literal in strict mode")
|
4459 | }
|
4460 | this.pos += octalStr.length - 1
|
4461 | return String.fromCharCode(octal)
|
4462 | }
|
4463 | return String.fromCharCode(ch)
|
4464 | }
|
4465 | }
|
4466 |
|
4467 |
|
4468 |
|
4469 | pp$7.readHexChar = function(len) {
|
4470 | var codePos = this.pos
|
4471 | var n = this.readInt(16, len)
|
4472 | if (n === null) this.raise(codePos, "Bad character escape sequence")
|
4473 | return n
|
4474 | }
|
4475 |
|
4476 |
|
4477 |
|
4478 |
|
4479 |
|
4480 |
|
4481 |
|
4482 | pp$7.readWord1 = function() {
|
4483 | var this$1 = this;
|
4484 |
|
4485 | this.containsEsc = false
|
4486 | var word = "", first = true, chunkStart = this.pos
|
4487 | var astral = this.options.ecmaVersion >= 6
|
4488 | while (this.pos < this.input.length) {
|
4489 | var ch = this$1.fullCharCodeAtPos()
|
4490 | if (isIdentifierChar(ch, astral)) {
|
4491 | this$1.pos += ch <= 0xffff ? 1 : 2
|
4492 | } else if (ch === 92) {
|
4493 | this$1.containsEsc = true
|
4494 | word += this$1.input.slice(chunkStart, this$1.pos)
|
4495 | var escStart = this$1.pos
|
4496 | if (this$1.input.charCodeAt(++this$1.pos) != 117)
|
4497 | this$1.raise(this$1.pos, "Expecting Unicode escape sequence \\uXXXX")
|
4498 | ++this$1.pos
|
4499 | var esc = this$1.readCodePoint()
|
4500 | if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
|
4501 | this$1.raise(escStart, "Invalid Unicode escape")
|
4502 | word += codePointToString(esc)
|
4503 | chunkStart = this$1.pos
|
4504 | } else {
|
4505 | break
|
4506 | }
|
4507 | first = false
|
4508 | }
|
4509 | return word + this.input.slice(chunkStart, this.pos)
|
4510 | }
|
4511 |
|
4512 |
|
4513 |
|
4514 |
|
4515 | pp$7.readWord = function() {
|
4516 | var word = this.readWord1()
|
4517 | var type = tt.name
|
4518 | if ((this.options.ecmaVersion >= 6 || !this.containsEsc) && this.keywords.test(word))
|
4519 | type = keywordTypes[word]
|
4520 | return this.finishToken(type, word)
|
4521 | }
|
4522 |
|
4523 |
|
4524 |
|
4525 |
|
4526 |
|
4527 |
|
4528 |
|
4529 |
|
4530 | function parse(input, options) {
|
4531 | return new Parser(options, input).parse()
|
4532 | }
|
4533 |
|
4534 | function walk ( ast, ref) {
|
4535 | var enter = ref.enter;
|
4536 | var leave = ref.leave;
|
4537 |
|
4538 | visit( ast, null, enter, leave );
|
4539 | }
|
4540 |
|
4541 | var context = {
|
4542 | skip: function () { return context.shouldSkip = true; },
|
4543 | shouldSkip: false
|
4544 | };
|
4545 |
|
4546 | var childKeys = {};
|
4547 |
|
4548 | var toString$1 = Object.prototype.toString;
|
4549 |
|
4550 | function isArray$1 ( thing ) {
|
4551 | return toString$1.call( thing ) === '[object Array]';
|
4552 | }
|
4553 |
|
4554 | function visit ( node, parent, enter, leave, prop, index ) {
|
4555 | if ( !node ) return;
|
4556 |
|
4557 | if ( enter ) {
|
4558 | context.shouldSkip = false;
|
4559 | enter.call( context, node, parent, prop, index );
|
4560 | if ( context.shouldSkip ) return;
|
4561 | }
|
4562 |
|
4563 | var keys = childKeys[ node.type ] || (
|
4564 | childKeys[ node.type ] = Object.keys( node ).filter( function ( key ) { return typeof node[ key ] === 'object'; } )
|
4565 | );
|
4566 |
|
4567 | var key, value, i, j;
|
4568 |
|
4569 | i = keys.length;
|
4570 | while ( i-- ) {
|
4571 | key = keys[i];
|
4572 | value = node[ key ];
|
4573 |
|
4574 | if ( isArray$1( value ) ) {
|
4575 | j = value.length;
|
4576 | while ( j-- ) {
|
4577 | visit( value[j], node, enter, leave, key, j );
|
4578 | }
|
4579 | }
|
4580 |
|
4581 | else if ( value && value.type ) {
|
4582 | visit( value, node, enter, leave, key, null );
|
4583 | }
|
4584 | }
|
4585 |
|
4586 | if ( leave ) {
|
4587 | leave( node, parent, prop, index );
|
4588 | }
|
4589 | }
|
4590 |
|
4591 | var reservedWords$1 = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'.split( ' ' );
|
4592 | var builtins = 'Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl'.split( ' ' );
|
4593 |
|
4594 | var blacklisted = blank();
|
4595 | reservedWords$1.concat( builtins ).forEach( function (word) { return blacklisted[ word ] = true; } );
|
4596 |
|
4597 |
|
4598 | function makeLegalIdentifier ( str ) {
|
4599 | str = str
|
4600 | .replace( /-(\w)/g, function ( _, letter ) { return letter.toUpperCase(); } )
|
4601 | .replace( /[^$_a-zA-Z0-9]/g, '_' );
|
4602 |
|
4603 | if ( /\d/.test( str[0] ) || blacklisted[ str ] ) str = "_" + str;
|
4604 |
|
4605 | return str;
|
4606 | }
|
4607 |
|
4608 | var modifierNodes = {
|
4609 | AssignmentExpression: 'left',
|
4610 | UpdateExpression: 'argument',
|
4611 | UnaryExpression: 'argument'
|
4612 | };
|
4613 |
|
4614 | function isModifierNode ( node ) {
|
4615 | if ( !( node.type in modifierNodes ) ) {
|
4616 | return false;
|
4617 | }
|
4618 |
|
4619 | if ( node.type === 'UnaryExpression' ) {
|
4620 | return node.operator === 'delete';
|
4621 | }
|
4622 |
|
4623 | return true;
|
4624 | }
|
4625 |
|
4626 | function isReference ( node, parent ) {
|
4627 | if ( node.type === 'MemberExpression' ) {
|
4628 | return !node.computed && isReference( node.object, node );
|
4629 | }
|
4630 |
|
4631 | if ( node.type === 'Identifier' ) {
|
4632 |
|
4633 |
|
4634 |
|
4635 | if ( !parent ) return true;
|
4636 |
|
4637 |
|
4638 | if ( parent.type === 'MemberExpression' || parent.type === 'MethodDefinition' ) {
|
4639 | return parent.computed || node === parent.object;
|
4640 | }
|
4641 |
|
4642 |
|
4643 | if ( parent.type === 'Property' ) return parent.computed || node === parent.value;
|
4644 |
|
4645 |
|
4646 | if ( parent.type === 'MethodDefinition' ) return false;
|
4647 |
|
4648 |
|
4649 | if ( parent.type === 'ExportSpecifier' && node !== parent.local ) return;
|
4650 |
|
4651 | return true;
|
4652 | }
|
4653 | }
|
4654 |
|
4655 | function flatten ( node ) {
|
4656 | var parts = [];
|
4657 | while ( node.type === 'MemberExpression' ) {
|
4658 | if ( node.computed ) return null;
|
4659 | parts.unshift( node.property.name );
|
4660 |
|
4661 | node = node.object;
|
4662 | }
|
4663 |
|
4664 | if ( node.type !== 'Identifier' ) return null;
|
4665 |
|
4666 | var name = node.name;
|
4667 | parts.unshift( name );
|
4668 |
|
4669 | return { name: name, keypath: parts.join( '.' ) };
|
4670 | }
|
4671 |
|
4672 | var pureFunctions = {};
|
4673 |
|
4674 | var arrayTypes = 'Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split( ' ' );
|
4675 | var simdTypes = 'Int8x16 Int16x8 Int32x4 Float32x4 Float64x2'.split( ' ' );
|
4676 | var simdMethods = 'abs add and bool check div equal extractLane fromFloat32x4 fromFloat32x4Bits fromFloat64x2 fromFloat64x2Bits fromInt16x8Bits fromInt32x4 fromInt32x4Bits fromInt8x16Bits greaterThan greaterThanOrEqual lessThan lessThanOrEqual load max maxNum min minNum mul neg not notEqual or reciprocalApproximation reciprocalSqrtApproximation replaceLane select selectBits shiftLeftByScalar shiftRightArithmeticByScalar shiftRightLogicalByScalar shuffle splat sqrt store sub swizzle xor'.split( ' ' );
|
4677 | var allSimdMethods = [];
|
4678 | simdTypes.forEach( function (t) {
|
4679 | simdMethods.forEach( function (m) {
|
4680 | allSimdMethods.push( ("SIMD." + t + "." + m) );
|
4681 | });
|
4682 | });
|
4683 |
|
4684 | [
|
4685 | 'Array.isArray',
|
4686 | 'Error', 'EvalError', 'InternalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError',
|
4687 | 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'escape', 'unescape',
|
4688 | 'Object', 'Object.create', 'Object.getNotifier', 'Object.getOwn', 'Object.getOwnPropertyDescriptor', 'Object.getOwnPropertyNames', 'Object.getOwnPropertySymbols', 'Object.getPrototypeOf', 'Object.is', 'Object.isExtensible', 'Object.isFrozen', 'Object.isSealed', 'Object.keys',
|
4689 | 'Function', 'Boolean',
|
4690 | 'Number', 'Number.isFinite', 'Number.isInteger', 'Number.isNaN', 'Number.isSafeInteger', 'Number.parseFloat', 'Number.parseInt',
|
4691 | 'Symbol', 'Symbol.for', 'Symbol.keyFor',
|
4692 | 'Math.abs', 'Math.acos', 'Math.acosh', 'Math.asin', 'Math.asinh', 'Math.atan', 'Math.atan2', 'Math.atanh', 'Math.cbrt', 'Math.ceil', 'Math.clz32', 'Math.cos', 'Math.cosh', 'Math.exp', 'Math.expm1', 'Math.floor', 'Math.fround', 'Math.hypot', 'Math.imul', 'Math.log', 'Math.log10', 'Math.log1p', 'Math.log2', 'Math.max', 'Math.min', 'Math.pow', 'Math.random', 'Math.round', 'Math.sign', 'Math.sin', 'Math.sinh', 'Math.sqrt', 'Math.tan', 'Math.tanh', 'Math.trunc',
|
4693 | 'Date', 'Date.UTC', 'Date.now', 'Date.parse',
|
4694 | 'String', 'String.fromCharCode', 'String.fromCodePoint', 'String.raw',
|
4695 | 'RegExp',
|
4696 | 'Map', 'Set', 'WeakMap', 'WeakSet',
|
4697 | 'ArrayBuffer', 'ArrayBuffer.isView',
|
4698 | 'DataView',
|
4699 | 'JSON.parse', 'JSON.stringify',
|
4700 | 'Promise', 'Promise.all', 'Promise.race', 'Promise.reject', 'Promise.resolve',
|
4701 | 'Intl.Collator', 'Intl.Collator.supportedLocalesOf', 'Intl.DateTimeFormat', 'Intl.DateTimeFormat.supportedLocalesOf', 'Intl.NumberFormat', 'Intl.NumberFormat.supportedLocalesOf'
|
4702 |
|
4703 |
|
4704 | ].concat(
|
4705 | arrayTypes,
|
4706 | arrayTypes.map( function (t) { return (t + ".from"); } ),
|
4707 | arrayTypes.map( function (t) { return (t + ".of"); } ),
|
4708 | simdTypes.map( function (t) { return ("SIMD." + t); } ),
|
4709 | allSimdMethods
|
4710 | ).forEach( function (name) { return pureFunctions[ name ] = true; } );
|
4711 |
|
4712 | function getLocation ( source, charIndex ) {
|
4713 | var lines = source.split( '\n' );
|
4714 | var len = lines.length;
|
4715 |
|
4716 | var lineStart = 0;
|
4717 | var i;
|
4718 |
|
4719 | for ( i = 0; i < len; i += 1 ) {
|
4720 | var line = lines[i];
|
4721 | var lineEnd = lineStart + line.length + 1;
|
4722 |
|
4723 | if ( lineEnd > charIndex ) {
|
4724 | return { line: i + 1, column: charIndex - lineStart };
|
4725 | }
|
4726 |
|
4727 | lineStart = lineEnd;
|
4728 | }
|
4729 |
|
4730 | throw new Error( 'Could not determine location of character' );
|
4731 | }
|
4732 |
|
4733 | function error ( props ) {
|
4734 | var err = new Error( props.message );
|
4735 |
|
4736 | Object.keys( props ).forEach( function (key) {
|
4737 | err[ key ] = props[ key ];
|
4738 | });
|
4739 |
|
4740 | throw err;
|
4741 | }
|
4742 |
|
4743 | function call ( callee, scope, statement, strongDependencies ) {
|
4744 | while ( callee.type === 'ParenthesizedExpression' ) callee = callee.expression;
|
4745 |
|
4746 | if ( callee.type === 'Identifier' ) {
|
4747 | var declaration = scope.findDeclaration( callee.name ) ||
|
4748 | statement.module.trace( callee.name );
|
4749 |
|
4750 | if ( declaration ) {
|
4751 | if ( declaration.isNamespace ) {
|
4752 | error({
|
4753 | message: ("Cannot call a namespace ('" + (callee.name) + "')"),
|
4754 | file: statement.module.id,
|
4755 | pos: callee.start,
|
4756 | loc: getLocation( statement.module.code, callee.start )
|
4757 | });
|
4758 | }
|
4759 |
|
4760 | return declaration.run( strongDependencies );
|
4761 | }
|
4762 |
|
4763 | return !pureFunctions[ callee.name ];
|
4764 | }
|
4765 |
|
4766 | if ( /FunctionExpression/.test( callee.type ) ) {
|
4767 | return run( callee.body, scope, statement, strongDependencies );
|
4768 | }
|
4769 |
|
4770 | if ( callee.type === 'MemberExpression' ) {
|
4771 | var flattened = flatten( callee );
|
4772 |
|
4773 | if ( flattened ) {
|
4774 |
|
4775 |
|
4776 | var declaration$1 = scope.findDeclaration( flattened.name ) || statement.module.trace( flattened.name );
|
4777 |
|
4778 | return ( !!declaration$1 || !pureFunctions[ flattened.keypath ] );
|
4779 | }
|
4780 | }
|
4781 |
|
4782 |
|
4783 |
|
4784 | return true;
|
4785 | }
|
4786 |
|
4787 | function run ( node, scope, statement, strongDependencies, force ) {
|
4788 | var hasSideEffect = false;
|
4789 |
|
4790 | walk( node, {
|
4791 | enter: function enter ( node, parent ) {
|
4792 | if ( !force && /Function/.test( node.type ) ) return this.skip();
|
4793 |
|
4794 | if ( node._scope ) scope = node._scope;
|
4795 |
|
4796 | if ( isReference( node, parent ) ) {
|
4797 | var flattened = flatten( node );
|
4798 |
|
4799 | if ( flattened.name === 'arguments' ) {
|
4800 | hasSideEffect = true;
|
4801 | }
|
4802 |
|
4803 | else if ( !scope.contains( flattened.name ) ) {
|
4804 | var declaration = statement.module.trace( flattened.name );
|
4805 | if ( declaration && !declaration.isExternal ) {
|
4806 | var module = declaration.module || declaration.statement.module;
|
4807 | if ( !module.isExternal && !~strongDependencies.indexOf( module ) ) strongDependencies.push( module );
|
4808 | }
|
4809 | }
|
4810 | }
|
4811 |
|
4812 | else if ( node.type === 'DebuggerStatement' ) {
|
4813 | hasSideEffect = true;
|
4814 | }
|
4815 |
|
4816 | else if ( node.type === 'ThrowStatement' ) {
|
4817 |
|
4818 |
|
4819 | if ( scope.isTopLevel ) hasSideEffect = true;
|
4820 | }
|
4821 |
|
4822 | else if ( node.type === 'CallExpression' || node.type === 'NewExpression' ) {
|
4823 | if ( call( node.callee, scope, statement, strongDependencies ) ) {
|
4824 | hasSideEffect = true;
|
4825 | }
|
4826 | }
|
4827 |
|
4828 | else if ( isModifierNode( node ) ) {
|
4829 | var subject = node[ modifierNodes[ node.type ] ];
|
4830 | while ( subject.type === 'MemberExpression' ) subject = subject.object;
|
4831 |
|
4832 | var declaration$1 = scope.findDeclaration( subject.name );
|
4833 |
|
4834 | if ( declaration$1 ) {
|
4835 | if ( declaration$1.isParam ) hasSideEffect = true;
|
4836 | } else if ( !scope.isTopLevel ) {
|
4837 | hasSideEffect = true;
|
4838 | } else {
|
4839 | declaration$1 = statement.module.trace( subject.name );
|
4840 |
|
4841 | if ( !declaration$1 || declaration$1.isExternal || declaration$1.isUsed || ( declaration$1.original && declaration$1.original.isUsed ) ) {
|
4842 | hasSideEffect = true;
|
4843 | }
|
4844 | }
|
4845 | }
|
4846 | },
|
4847 | leave: function leave ( node ) {
|
4848 | if ( node._scope ) scope = scope.parent;
|
4849 | }
|
4850 | });
|
4851 |
|
4852 | return hasSideEffect;
|
4853 | }
|
4854 |
|
4855 | var Reference = function Reference ( node, scope, statement ) {
|
4856 | var this$1 = this;
|
4857 |
|
4858 | this.node = node;
|
4859 | this.scope = scope;
|
4860 | this.statement = statement;
|
4861 |
|
4862 | this.declaration = null;
|
4863 |
|
4864 | this.parts = [];
|
4865 |
|
4866 | var root = node;
|
4867 | while ( root.type === 'MemberExpression' ) {
|
4868 | this$1.parts.unshift( root.property );
|
4869 | root = root.object;
|
4870 | }
|
4871 |
|
4872 | this.name = root.name;
|
4873 |
|
4874 | this.start = node.start;
|
4875 | this.end = node.start + this.name.length;
|
4876 | this.rewritten = false;
|
4877 | };
|
4878 |
|
4879 | var SyntheticReference = function SyntheticReference ( name ) {
|
4880 | this.name = name;
|
4881 | this.parts = [];
|
4882 | };
|
4883 |
|
4884 | var use = function (alias) { return alias.use(); };
|
4885 |
|
4886 | var Declaration = function Declaration ( node, isParam, statement ) {
|
4887 | if ( node ) {
|
4888 | if ( node.type === 'FunctionDeclaration' ) {
|
4889 | this.isFunctionDeclaration = true;
|
4890 | this.functionNode = node;
|
4891 | } else if ( node.type === 'VariableDeclarator' && node.init && /FunctionExpression/.test( node.init.type ) ) {
|
4892 | this.isFunctionDeclaration = true;
|
4893 | this.functionNode = node.init;
|
4894 | }
|
4895 | }
|
4896 |
|
4897 | this.statement = statement;
|
4898 | this.name = node.id ? node.id.name : node.name;
|
4899 | this.exportName = null;
|
4900 | this.isParam = isParam;
|
4901 |
|
4902 | this.isReassigned = false;
|
4903 | this.aliases = [];
|
4904 |
|
4905 | this.isUsed = false;
|
4906 | };
|
4907 |
|
4908 | Declaration.prototype.addAlias = function addAlias ( declaration ) {
|
4909 | this.aliases.push( declaration );
|
4910 | };
|
4911 |
|
4912 | Declaration.prototype.addReference = function addReference ( reference ) {
|
4913 | reference.declaration = this;
|
4914 |
|
4915 | if ( reference.name !== this.name ) {
|
4916 | this.name = makeLegalIdentifier( reference.name );
|
4917 | }
|
4918 |
|
4919 | if ( reference.isReassignment ) this.isReassigned = true;
|
4920 | };
|
4921 |
|
4922 | Declaration.prototype.render = function render ( es ) {
|
4923 | if ( es ) return this.name;
|
4924 | if ( !this.isReassigned || !this.exportName ) return this.name;
|
4925 |
|
4926 | return ("exports." + (this.exportName));
|
4927 | };
|
4928 |
|
4929 | Declaration.prototype.run = function run$1 ( strongDependencies ) {
|
4930 | if ( this.tested ) return this.hasSideEffects;
|
4931 |
|
4932 |
|
4933 | if ( !this.functionNode ) {
|
4934 | this.hasSideEffects = true;
|
4935 | } else {
|
4936 | if ( this.running ) return true;
|
4937 | this.running = true;
|
4938 |
|
4939 | this.hasSideEffects = run( this.functionNode.body, this.functionNode._scope, this.statement, strongDependencies, false );
|
4940 |
|
4941 | this.running = false;
|
4942 | }
|
4943 |
|
4944 | this.tested = true;
|
4945 | return this.hasSideEffects;
|
4946 | };
|
4947 |
|
4948 | Declaration.prototype.use = function use$1 () {
|
4949 | if ( this.isUsed ) return;
|
4950 |
|
4951 | this.isUsed = true;
|
4952 | if ( this.statement ) this.statement.mark();
|
4953 |
|
4954 | this.aliases.forEach( use );
|
4955 | };
|
4956 |
|
4957 | var SyntheticDefaultDeclaration = function SyntheticDefaultDeclaration ( node, statement, name ) {
|
4958 | this.node = node;
|
4959 | this.statement = statement;
|
4960 | this.name = name;
|
4961 |
|
4962 | this.original = null;
|
4963 | this.exportName = null;
|
4964 | this.aliases = [];
|
4965 | };
|
4966 |
|
4967 | SyntheticDefaultDeclaration.prototype.addAlias = function addAlias ( declaration ) {
|
4968 | this.aliases.push( declaration );
|
4969 | };
|
4970 |
|
4971 | SyntheticDefaultDeclaration.prototype.addReference = function addReference ( reference ) {
|
4972 |
|
4973 | reference.declaration = this;
|
4974 |
|
4975 |
|
4976 | if ( reference.name === 'default' ) return;
|
4977 |
|
4978 | this.name = reference.name;
|
4979 | };
|
4980 |
|
4981 | SyntheticDefaultDeclaration.prototype.bind = function bind ( declaration ) {
|
4982 | this.original = declaration;
|
4983 | };
|
4984 |
|
4985 | SyntheticDefaultDeclaration.prototype.render = function render () {
|
4986 | return !this.original || this.original.isReassigned ?
|
4987 | this.name :
|
4988 | this.original.render();
|
4989 | };
|
4990 |
|
4991 | SyntheticDefaultDeclaration.prototype.run = function run$2 ( strongDependencies ) {
|
4992 | if ( this.original ) {
|
4993 | return this.original.run( strongDependencies );
|
4994 | }
|
4995 |
|
4996 | var declaration = this.node.declaration;
|
4997 | while ( declaration.type === 'ParenthesizedExpression' ) declaration = declaration.expression;
|
4998 |
|
4999 | if ( /FunctionExpression/.test( declaration.type ) ) {
|
5000 | return run( declaration.body, this.statement.scope, this.statement, strongDependencies, false );
|
5001 | }
|
5002 |
|
5003 |
|
5004 | return true;
|
5005 | };
|
5006 |
|
5007 | SyntheticDefaultDeclaration.prototype.use = function use$2 () {
|
5008 | this.isUsed = true;
|
5009 | this.statement.mark();
|
5010 |
|
5011 | if ( this.original ) this.original.use();
|
5012 |
|
5013 | this.aliases.forEach( use );
|
5014 | };
|
5015 |
|
5016 | var SyntheticGlobalDeclaration = function SyntheticGlobalDeclaration ( name ) {
|
5017 | this.name = name;
|
5018 | this.isExternal = true;
|
5019 | this.isGlobal = true;
|
5020 | this.isReassigned = false;
|
5021 |
|
5022 | this.aliases = [];
|
5023 |
|
5024 | this.isUsed = false;
|
5025 | };
|
5026 |
|
5027 | SyntheticGlobalDeclaration.prototype.addAlias = function addAlias ( declaration ) {
|
5028 | this.aliases.push( declaration );
|
5029 | };
|
5030 |
|
5031 | SyntheticGlobalDeclaration.prototype.addReference = function addReference ( reference ) {
|
5032 | reference.declaration = this;
|
5033 | if ( reference.isReassignment ) this.isReassigned = true;
|
5034 | };
|
5035 |
|
5036 | SyntheticGlobalDeclaration.prototype.render = function render () {
|
5037 | return this.name;
|
5038 | };
|
5039 |
|
5040 | SyntheticGlobalDeclaration.prototype.run = function run$3 () {
|
5041 | return true;
|
5042 | };
|
5043 |
|
5044 | SyntheticGlobalDeclaration.prototype.use = function use$3 () {
|
5045 | if ( this.isUsed ) return;
|
5046 | this.isUsed = true;
|
5047 |
|
5048 | this.aliases.forEach( use );
|
5049 | };
|
5050 |
|
5051 | var SyntheticNamespaceDeclaration = function SyntheticNamespaceDeclaration ( module ) {
|
5052 | var this$1 = this;
|
5053 |
|
5054 | this.isNamespace = true;
|
5055 | this.module = module;
|
5056 | this.name = null;
|
5057 |
|
5058 | this.needsNamespaceBlock = false;
|
5059 | this.aliases = [];
|
5060 |
|
5061 | this.originals = blank();
|
5062 | module.getExports().forEach( function (name) {
|
5063 | this$1.originals[ name ] = module.traceExport( name );
|
5064 | });
|
5065 | };
|
5066 |
|
5067 | SyntheticNamespaceDeclaration.prototype.addAlias = function addAlias ( declaration ) {
|
5068 | this.aliases.push( declaration );
|
5069 | };
|
5070 |
|
5071 | SyntheticNamespaceDeclaration.prototype.addReference = function addReference ( reference ) {
|
5072 |
|
5073 |
|
5074 | if ( reference.parts.length ) {
|
5075 | var ref = reference.parts.shift();
|
5076 | reference.name = ref.name;
|
5077 | reference.end = ref.end;
|
5078 |
|
5079 | var original = this.originals[ reference.name ];
|
5080 |
|
5081 |
|
5082 | if ( !original ) {
|
5083 | this.module.bundle.onwarn( ("Export '" + (reference.name) + "' is not defined by '" + (this.module.id) + "'") );
|
5084 | reference.isUndefined = true;
|
5085 | return;
|
5086 | }
|
5087 |
|
5088 | original.addReference( reference );
|
5089 | return;
|
5090 | }
|
5091 |
|
5092 |
|
5093 |
|
5094 |
|
5095 | if ( !this.needsNamespaceBlock ) {
|
5096 | this.needsNamespaceBlock = true;
|
5097 | this.module.bundle.internalNamespaces.push( this );
|
5098 |
|
5099 |
|
5100 |
|
5101 | forOwn( this.originals, function ( original, name ) {
|
5102 | original.addReference( new SyntheticReference( name ) );
|
5103 | });
|
5104 | }
|
5105 |
|
5106 | reference.declaration = this;
|
5107 | this.name = reference.name;
|
5108 | };
|
5109 |
|
5110 | SyntheticNamespaceDeclaration.prototype.renderBlock = function renderBlock ( indentString ) {
|
5111 | var this$1 = this;
|
5112 |
|
5113 | var members = keys( this.originals ).map( function (name) {
|
5114 | var original = this$1.originals[ name ];
|
5115 |
|
5116 | if ( original.isReassigned ) {
|
5117 | return (indentString + "get " + name + " () { return " + (original.render()) + "; }");
|
5118 | }
|
5119 |
|
5120 | return ("" + indentString + name + ": " + (original.render()));
|
5121 | });
|
5122 |
|
5123 | return ((this.module.bundle.varOrConst) + " " + (this.render()) + " = Object.freeze({\n" + (members.join( ',\n' )) + "\n});\n\n");
|
5124 | };
|
5125 |
|
5126 | SyntheticNamespaceDeclaration.prototype.render = function render () {
|
5127 | return this.name;
|
5128 | };
|
5129 |
|
5130 | SyntheticNamespaceDeclaration.prototype.use = function use$4 () {
|
5131 | forOwn( this.originals, use );
|
5132 | this.aliases.forEach( use );
|
5133 | };
|
5134 |
|
5135 | var ExternalDeclaration = function ExternalDeclaration ( module, name ) {
|
5136 | this.module = module;
|
5137 | this.name = name;
|
5138 | this.safeName = null;
|
5139 | this.isExternal = true;
|
5140 |
|
5141 | this.isNamespace = name === '*';
|
5142 | };
|
5143 |
|
5144 | ExternalDeclaration.prototype.addAlias = function addAlias () {
|
5145 |
|
5146 | };
|
5147 |
|
5148 | ExternalDeclaration.prototype.addReference = function addReference ( reference ) {
|
5149 | reference.declaration = this;
|
5150 |
|
5151 | if ( this.name === 'default' || this.name === '*' ) {
|
5152 | this.module.suggestName( reference.name );
|
5153 | }
|
5154 | };
|
5155 |
|
5156 | ExternalDeclaration.prototype.render = function render ( es ) {
|
5157 | if ( this.name === '*' ) {
|
5158 | return this.module.name;
|
5159 | }
|
5160 |
|
5161 | if ( this.name === 'default' ) {
|
5162 | return this.module.exportsNamespace || ( !es && this.module.exportsNames ) ?
|
5163 | ((this.module.name) + "__default") :
|
5164 | this.module.name;
|
5165 | }
|
5166 |
|
5167 | return es ? this.safeName : ((this.module.name) + "." + (this.name));
|
5168 | };
|
5169 |
|
5170 | ExternalDeclaration.prototype.run = function run$4 () {
|
5171 | return true;
|
5172 | };
|
5173 |
|
5174 | ExternalDeclaration.prototype.setSafeName = function setSafeName ( name ) {
|
5175 | this.safeName = name;
|
5176 | };
|
5177 |
|
5178 | ExternalDeclaration.prototype.use = function use$5 () {
|
5179 |
|
5180 | };
|
5181 |
|
5182 | function extractNames ( param ) {
|
5183 | var names = [];
|
5184 | extractors[ param.type ]( names, param );
|
5185 | return names;
|
5186 | }
|
5187 |
|
5188 | var extractors = {
|
5189 | Identifier: function Identifier ( names, param ) {
|
5190 | names.push( param.name );
|
5191 | },
|
5192 |
|
5193 | ObjectPattern: function ObjectPattern ( names, param ) {
|
5194 | param.properties.forEach( function (prop) {
|
5195 | extractors[ prop.value.type ]( names, prop.value );
|
5196 | });
|
5197 | },
|
5198 |
|
5199 | ArrayPattern: function ArrayPattern ( names, param ) {
|
5200 | param.elements.forEach( function (element) {
|
5201 | if ( element ) extractors[ element.type ]( names, element );
|
5202 | });
|
5203 | },
|
5204 |
|
5205 | RestElement: function RestElement ( names, param ) {
|
5206 | extractors[ param.argument.type ]( names, param.argument );
|
5207 | },
|
5208 |
|
5209 | AssignmentPattern: function AssignmentPattern ( names, param ) {
|
5210 | extractors[ param.left.type ]( names, param.left );
|
5211 | }
|
5212 | };
|
5213 |
|
5214 | var Scope = function Scope ( options ) {
|
5215 | var this$1 = this;
|
5216 |
|
5217 | options = options || {};
|
5218 |
|
5219 | this.parent = options.parent;
|
5220 | this.statement = options.statement || this.parent.statement;
|
5221 | this.isBlockScope = !!options.block;
|
5222 | this.isTopLevel = !this.parent || ( this.parent.isTopLevel && this.isBlockScope );
|
5223 |
|
5224 | this.declarations = blank();
|
5225 |
|
5226 | if ( options.params ) {
|
5227 | options.params.forEach( function (param) {
|
5228 | extractNames( param ).forEach( function (name) {
|
5229 | this$1.declarations[ name ] = new Declaration( param, true, this$1.statement );
|
5230 | });
|
5231 | });
|
5232 | }
|
5233 | };
|
5234 |
|
5235 | Scope.prototype.addDeclaration = function addDeclaration ( node, isBlockDeclaration, isVar ) {
|
5236 | var this$1 = this;
|
5237 |
|
5238 | if ( !isBlockDeclaration && this.isBlockScope ) {
|
5239 |
|
5240 |
|
5241 | this.parent.addDeclaration( node, isBlockDeclaration, isVar );
|
5242 | } else {
|
5243 | extractNames( node.id ).forEach( function (name) {
|
5244 | this$1.declarations[ name ] = new Declaration( node, false, this$1.statement );
|
5245 | });
|
5246 | }
|
5247 | };
|
5248 |
|
5249 | Scope.prototype.contains = function contains ( name ) {
|
5250 | return this.declarations[ name ] ||
|
5251 | ( this.parent ? this.parent.contains( name ) : false );
|
5252 | };
|
5253 |
|
5254 | Scope.prototype.eachDeclaration = function eachDeclaration ( fn ) {
|
5255 | var this$1 = this;
|
5256 |
|
5257 | keys( this.declarations ).forEach( function (key) {
|
5258 | fn( key, this$1.declarations[ key ] );
|
5259 | });
|
5260 | };
|
5261 |
|
5262 | Scope.prototype.findDeclaration = function findDeclaration ( name ) {
|
5263 | return this.declarations[ name ] ||
|
5264 | ( this.parent && this.parent.findDeclaration( name ) );
|
5265 | };
|
5266 |
|
5267 | var blockDeclarations = {
|
5268 | 'const': true,
|
5269 | 'let': true
|
5270 | };
|
5271 |
|
5272 | function attachScopes ( statement ) {
|
5273 | var node = statement.node;
|
5274 | var scope = statement.scope;
|
5275 |
|
5276 | walk( node, {
|
5277 | enter: function enter ( node, parent ) {
|
5278 |
|
5279 |
|
5280 | if ( /(Function|Class)Declaration/.test( node.type ) ) {
|
5281 | scope.addDeclaration( node, false, false );
|
5282 | }
|
5283 |
|
5284 |
|
5285 | if ( node.type === 'VariableDeclaration' ) {
|
5286 | var isBlockDeclaration = blockDeclarations[ node.kind ];
|
5287 |
|
5288 | node.declarations.forEach( function (declarator) {
|
5289 | scope.addDeclaration( declarator, isBlockDeclaration, true );
|
5290 | });
|
5291 | }
|
5292 |
|
5293 | var newScope;
|
5294 |
|
5295 |
|
5296 | if ( /(Function|Class)/.test( node.type ) ) {
|
5297 | newScope = new Scope({
|
5298 | parent: scope,
|
5299 | block: false,
|
5300 | params: node.params
|
5301 | });
|
5302 |
|
5303 |
|
5304 |
|
5305 | if ( /(Function|Class)Expression/.test( node.type ) && node.id ) {
|
5306 | newScope.addDeclaration( node, false, false );
|
5307 | }
|
5308 | }
|
5309 |
|
5310 |
|
5311 | if ( node.type === 'BlockStatement' && ( !parent || !/Function/.test( parent.type ) ) ) {
|
5312 | newScope = new Scope({
|
5313 | parent: scope,
|
5314 | block: true
|
5315 | });
|
5316 | }
|
5317 |
|
5318 |
|
5319 | if ( node.type === 'CatchClause' ) {
|
5320 | newScope = new Scope({
|
5321 | parent: scope,
|
5322 | params: [ node.param ],
|
5323 | block: true
|
5324 | });
|
5325 | }
|
5326 |
|
5327 | if ( newScope ) {
|
5328 | Object.defineProperty( node, '_scope', {
|
5329 | value: newScope,
|
5330 | configurable: true
|
5331 | });
|
5332 |
|
5333 | scope = newScope;
|
5334 | }
|
5335 | },
|
5336 | leave: function leave ( node ) {
|
5337 | if ( node._scope ) {
|
5338 | scope = scope.parent;
|
5339 | }
|
5340 | }
|
5341 | });
|
5342 | }
|
5343 |
|
5344 | function isFunctionDeclaration ( node ) {
|
5345 | if ( !node ) return false;
|
5346 |
|
5347 | return node.type === 'FunctionDeclaration' ||
|
5348 | ( node.type === 'VariableDeclaration' && node.init && /FunctionExpression/.test( node.init.type ) );
|
5349 | }
|
5350 |
|
5351 | var Statement = function Statement ( node, module, start, end ) {
|
5352 | this.node = node;
|
5353 | this.module = module;
|
5354 | this.start = start;
|
5355 | this.end = end;
|
5356 | this.next = null;
|
5357 |
|
5358 | this.scope = new Scope({ statement: this });
|
5359 |
|
5360 | this.references = [];
|
5361 | this.stringLiteralRanges = [];
|
5362 |
|
5363 | this.isIncluded = false;
|
5364 | this.ran = false;
|
5365 |
|
5366 | this.isImportDeclaration = node.type === 'ImportDeclaration';
|
5367 | this.isExportDeclaration = /^Export/.test( node.type );
|
5368 | this.isReexportDeclaration = this.isExportDeclaration && !!node.source;
|
5369 |
|
5370 | this.isFunctionDeclaration = isFunctionDeclaration( node ) ||
|
5371 | this.isExportDeclaration && isFunctionDeclaration( node.declaration );
|
5372 | };
|
5373 |
|
5374 | Statement.prototype.firstPass = function firstPass () {
|
5375 | if ( this.isImportDeclaration ) return;
|
5376 |
|
5377 |
|
5378 | attachScopes( this );
|
5379 |
|
5380 |
|
5381 | var statement = this;
|
5382 | var ref = this;
|
5383 | var module = ref.module;
|
5384 | var references = ref.references;
|
5385 | var scope = ref.scope;
|
5386 | var stringLiteralRanges = ref.stringLiteralRanges;
|
5387 | var contextDepth = 0;
|
5388 |
|
5389 | walk( this.node, {
|
5390 | enter: function enter ( node, parent, prop ) {
|
5391 |
|
5392 | if ( node.type === 'CallExpression' && node.callee.name === 'eval' && !scope.contains( 'eval' ) ) {
|
5393 |
|
5394 | module.bundle.onwarn( ("Use of `eval` (in " + (module.id) + ") is strongly discouraged, as it poses security risks and may cause issues with minification. See https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval for more details") );
|
5395 | }
|
5396 |
|
5397 |
|
5398 | if ( node.type === 'ExportNamedDeclaration' && node.source ) return this.skip();
|
5399 |
|
5400 | if ( node.type === 'TemplateElement' ) stringLiteralRanges.push([ node.start, node.end ]);
|
5401 | if ( node.type === 'Literal' && typeof node.value === 'string' && /\n/.test( node.raw ) ) {
|
5402 | stringLiteralRanges.push([ node.start + 1, node.end - 1 ]);
|
5403 | }
|
5404 |
|
5405 | if ( node.type === 'ThisExpression' && contextDepth === 0 ) {
|
5406 | module.magicString.overwrite( node.start, node.end, 'undefined' );
|
5407 | module.bundle.onwarn( 'The `this` keyword is equivalent to `undefined` at the top level of an ES module, and has been rewritten' );
|
5408 | }
|
5409 |
|
5410 | if ( node._scope ) scope = node._scope;
|
5411 | if ( /^Function/.test( node.type ) ) contextDepth += 1;
|
5412 |
|
5413 | var isReassignment;
|
5414 |
|
5415 | if ( parent && isModifierNode( parent ) ) {
|
5416 | var subject = parent[ modifierNodes[ parent.type ] ];
|
5417 |
|
5418 | if ( node === subject ) {
|
5419 | var depth = 0;
|
5420 |
|
5421 | while ( subject.type === 'MemberExpression' ) {
|
5422 | subject = subject.object;
|
5423 | depth += 1;
|
5424 | }
|
5425 |
|
5426 | var importDeclaration = module.imports[ subject.name ];
|
5427 |
|
5428 | if ( !scope.contains( subject.name ) && importDeclaration ) {
|
5429 | var minDepth = importDeclaration.name === '*' ?
|
5430 | 2 :
|
5431 | 1;
|
5432 |
|
5433 | if ( depth < minDepth ) {
|
5434 | var err = new Error( ("Illegal reassignment to import '" + (subject.name) + "'") );
|
5435 | err.file = module.id;
|
5436 | err.loc = getLocation( module.magicString.original, subject.start );
|
5437 | throw err;
|
5438 | }
|
5439 | }
|
5440 |
|
5441 | isReassignment = !depth;
|
5442 | }
|
5443 | }
|
5444 |
|
5445 | if ( isReference( node, parent ) ) {
|
5446 |
|
5447 |
|
5448 | var referenceScope = parent.type === 'FunctionDeclaration' && node === parent.id ?
|
5449 | scope.parent :
|
5450 | scope;
|
5451 |
|
5452 | var isShorthandProperty = parent.type === 'Property' && parent.shorthand;
|
5453 |
|
5454 |
|
5455 |
|
5456 |
|
5457 |
|
5458 | if ( isShorthandProperty && parent.value === parent.key && prop === 'value' ) {
|
5459 | return;
|
5460 | }
|
5461 |
|
5462 | var reference = new Reference( node, referenceScope, statement );
|
5463 | reference.isReassignment = isReassignment;
|
5464 | reference.isShorthandProperty = isShorthandProperty;
|
5465 | references.push( reference );
|
5466 |
|
5467 | this.skip();
|
5468 | }
|
5469 | },
|
5470 | leave: function leave ( node ) {
|
5471 | if ( node._scope ) scope = scope.parent;
|
5472 | if ( /^Function/.test( node.type ) ) contextDepth -= 1;
|
5473 | }
|
5474 | });
|
5475 | };
|
5476 |
|
5477 | Statement.prototype.mark = function mark () {
|
5478 | if ( this.isIncluded ) return;
|
5479 | this.isIncluded = true;
|
5480 |
|
5481 | this.references.forEach( function (reference) {
|
5482 | if ( reference.declaration ) reference.declaration.use();
|
5483 | });
|
5484 | };
|
5485 |
|
5486 | Statement.prototype.run = function run$1 ( strongDependencies ) {
|
5487 | if ( ( this.ran && this.isIncluded ) || this.isImportDeclaration || this.isFunctionDeclaration ) return;
|
5488 | this.ran = true;
|
5489 |
|
5490 | if ( run( this.node, this.scope, this, strongDependencies, false ) ) {
|
5491 | this.mark();
|
5492 | return true;
|
5493 | }
|
5494 | };
|
5495 |
|
5496 | Statement.prototype.source = function source () {
|
5497 | return this.module.source.slice( this.start, this.end );
|
5498 | };
|
5499 |
|
5500 | Statement.prototype.toString = function toString () {
|
5501 | return this.module.magicString.slice( this.start, this.end );
|
5502 | };
|
5503 |
|
5504 | function isTruthy ( node ) {
|
5505 | if ( node.type === 'Literal' ) return !!node.value;
|
5506 | if ( node.type === 'ParenthesizedExpression' ) return isTruthy( node.expression );
|
5507 | if ( node.operator in operators ) return operators[ node.operator ]( node );
|
5508 | }
|
5509 |
|
5510 | function isFalsy ( node ) {
|
5511 | return not( isTruthy( node ) );
|
5512 | }
|
5513 |
|
5514 | function not ( value ) {
|
5515 | return value === undefined ? value : !value;
|
5516 | }
|
5517 |
|
5518 | function equals ( a, b, strict ) {
|
5519 | if ( a.type !== b.type ) return undefined;
|
5520 | if ( a.type === 'Literal' ) return strict ? a.value === b.value : a.value == b.value;
|
5521 | }
|
5522 |
|
5523 | var operators = {
|
5524 | '==': function (x) {
|
5525 | return equals( x.left, x.right, false );
|
5526 | },
|
5527 |
|
5528 | '!=': function (x) { return not( operators['==']( x ) ); },
|
5529 |
|
5530 | '===': function (x) {
|
5531 | return equals( x.left, x.right, true );
|
5532 | },
|
5533 |
|
5534 | '!==': function (x) { return not( operators['===']( x ) ); },
|
5535 |
|
5536 | '!': function (x) { return isFalsy( x.argument ); },
|
5537 |
|
5538 | '&&': function (x) { return isTruthy( x.left ) && isTruthy( x.right ); },
|
5539 |
|
5540 | '||': function (x) { return isTruthy( x.left ) || isTruthy( x.right ); }
|
5541 | };
|
5542 |
|
5543 | function emptyBlockStatement ( start, end ) {
|
5544 | return {
|
5545 | start: start, end: end,
|
5546 | type: 'BlockStatement',
|
5547 | body: []
|
5548 | };
|
5549 | }
|
5550 |
|
5551 | var Module = function Module (ref) {
|
5552 | var this$1 = this;
|
5553 | var id = ref.id;
|
5554 | var code = ref.code;
|
5555 | var originalCode = ref.originalCode;
|
5556 | var originalSourceMap = ref.originalSourceMap;
|
5557 | var ast = ref.ast;
|
5558 | var sourceMapChain = ref.sourceMapChain;
|
5559 | var bundle = ref.bundle;
|
5560 |
|
5561 | this.code = code;
|
5562 | this.originalCode = originalCode;
|
5563 | this.originalSourceMap = originalSourceMap;
|
5564 | this.sourceMapChain = sourceMapChain;
|
5565 |
|
5566 | this.bundle = bundle;
|
5567 | this.id = id;
|
5568 | this.excludeFromSourcemap = /\0/.test( id );
|
5569 |
|
5570 |
|
5571 | this.sources = [];
|
5572 | this.dependencies = [];
|
5573 | this.resolvedIds = blank();
|
5574 |
|
5575 |
|
5576 | this.imports = blank();
|
5577 | this.exports = blank();
|
5578 | this.reexports = blank();
|
5579 |
|
5580 | this.exportAllSources = [];
|
5581 | this.exportAllModules = null;
|
5582 |
|
5583 |
|
5584 |
|
5585 | this.magicString = new MagicString( code, {
|
5586 | filename: this.excludeFromSourcemap ? null : id,
|
5587 | indentExclusionRanges: []
|
5588 | });
|
5589 |
|
5590 |
|
5591 | var pattern = new RegExp( ("\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'g' );
|
5592 | var match;
|
5593 | while ( match = pattern.exec( code ) ) {
|
5594 | this$1.magicString.remove( match.index, match.index + match[0].length );
|
5595 | }
|
5596 |
|
5597 | this.comments = [];
|
5598 | this.ast = ast;
|
5599 | this.statements = this.parse();
|
5600 |
|
5601 | this.declarations = blank();
|
5602 | this.analyse();
|
5603 |
|
5604 | this.strongDependencies = [];
|
5605 | };
|
5606 |
|
5607 | Module.prototype.addExport = function addExport ( statement ) {
|
5608 | var this$1 = this;
|
5609 |
|
5610 | var node = statement.node;
|
5611 | var source = node.source && node.source.value;
|
5612 |
|
5613 |
|
5614 | if ( source ) {
|
5615 | if ( !~this.sources.indexOf( source ) ) this.sources.push( source );
|
5616 |
|
5617 | if ( node.type === 'ExportAllDeclaration' ) {
|
5618 |
|
5619 |
|
5620 | this.exportAllSources.push( source );
|
5621 | }
|
5622 |
|
5623 | else {
|
5624 | node.specifiers.forEach( function (specifier) {
|
5625 | var name = specifier.exported.name;
|
5626 |
|
5627 | if ( this$1.exports[ name ] || this$1.reexports[ name ] ) {
|
5628 | throw new Error( ("A module cannot have multiple exports with the same name ('" + name + "')") );
|
5629 | }
|
5630 |
|
5631 | this$1.reexports[ name ] = {
|
5632 | start: specifier.start,
|
5633 | source: source,
|
5634 | localName: specifier.local.name,
|
5635 | module: null
|
5636 | };
|
5637 | });
|
5638 | }
|
5639 | }
|
5640 |
|
5641 |
|
5642 |
|
5643 |
|
5644 | else if ( node.type === 'ExportDefaultDeclaration' ) {
|
5645 | var identifier = ( node.declaration.id && node.declaration.id.name ) || node.declaration.name;
|
5646 |
|
5647 | if ( this.exports.default ) {
|
5648 |
|
5649 | throw new Error( 'A module can only have one default export' );
|
5650 | }
|
5651 |
|
5652 | this.exports.default = {
|
5653 | localName: 'default',
|
5654 | identifier: identifier
|
5655 | };
|
5656 |
|
5657 |
|
5658 | this.declarations.default = new SyntheticDefaultDeclaration( node, statement, identifier || this.basename() );
|
5659 | }
|
5660 |
|
5661 |
|
5662 |
|
5663 |
|
5664 |
|
5665 | else if ( node.declaration ) {
|
5666 | var declaration = node.declaration;
|
5667 |
|
5668 | if ( declaration.type === 'VariableDeclaration' ) {
|
5669 | declaration.declarations.forEach( function (decl) {
|
5670 | extractNames( decl.id ).forEach( function (localName) {
|
5671 | this$1.exports[ localName ] = { localName: localName };
|
5672 | });
|
5673 | });
|
5674 | } else {
|
5675 |
|
5676 | var localName = declaration.id.name;
|
5677 | this.exports[ localName ] = { localName: localName };
|
5678 | }
|
5679 | }
|
5680 |
|
5681 |
|
5682 | else {
|
5683 | if ( node.specifiers.length ) {
|
5684 | node.specifiers.forEach( function (specifier) {
|
5685 | var localName = specifier.local.name;
|
5686 | var exportedName = specifier.exported.name;
|
5687 |
|
5688 | if ( this$1.exports[ exportedName ] || this$1.reexports[ exportedName ] ) {
|
5689 | throw new Error( ("A module cannot have multiple exports with the same name ('" + exportedName + "')") );
|
5690 | }
|
5691 |
|
5692 | this$1.exports[ exportedName ] = { localName: localName };
|
5693 | });
|
5694 | } else {
|
5695 | this.bundle.onwarn( ("Module " + (this.id) + " has an empty export declaration") );
|
5696 | }
|
5697 | }
|
5698 | };
|
5699 |
|
5700 | Module.prototype.addImport = function addImport ( statement ) {
|
5701 | var this$1 = this;
|
5702 |
|
5703 | var node = statement.node;
|
5704 | var source = node.source.value;
|
5705 |
|
5706 | if ( !~this.sources.indexOf( source ) ) this.sources.push( source );
|
5707 |
|
5708 | node.specifiers.forEach( function (specifier) {
|
5709 | var localName = specifier.local.name;
|
5710 |
|
5711 | if ( this$1.imports[ localName ] ) {
|
5712 | var err = new Error( ("Duplicated import '" + localName + "'") );
|
5713 | err.file = this$1.id;
|
5714 | err.loc = getLocation( this$1.code, specifier.start );
|
5715 | throw err;
|
5716 | }
|
5717 |
|
5718 | var isDefault = specifier.type === 'ImportDefaultSpecifier';
|
5719 | var isNamespace = specifier.type === 'ImportNamespaceSpecifier';
|
5720 |
|
5721 | var name = isDefault ? 'default' : isNamespace ? '*' : specifier.imported.name;
|
5722 | this$1.imports[ localName ] = { source: source, name: name, module: null };
|
5723 | });
|
5724 | };
|
5725 |
|
5726 | Module.prototype.analyse = function analyse () {
|
5727 | var this$1 = this;
|
5728 |
|
5729 |
|
5730 | this.statements.forEach( function (statement) {
|
5731 | if ( statement.isImportDeclaration ) this$1.addImport( statement );
|
5732 | else if ( statement.isExportDeclaration ) this$1.addExport( statement );
|
5733 |
|
5734 | statement.firstPass();
|
5735 |
|
5736 | statement.scope.eachDeclaration( function ( name, declaration ) {
|
5737 | this$1.declarations[ name ] = declaration;
|
5738 | });
|
5739 | });
|
5740 | };
|
5741 |
|
5742 | Module.prototype.basename = function basename$1 () {
|
5743 | var base = basename( this.id );
|
5744 | var ext = extname( this.id );
|
5745 |
|
5746 | return makeLegalIdentifier( ext ? base.slice( 0, -ext.length ) : base );
|
5747 | };
|
5748 |
|
5749 | Module.prototype.bindAliases = function bindAliases () {
|
5750 | var this$1 = this;
|
5751 |
|
5752 | keys( this.declarations ).forEach( function (name) {
|
5753 | if ( name === '*' ) return;
|
5754 |
|
5755 | var declaration = this$1.declarations[ name ];
|
5756 | var statement = declaration.statement;
|
5757 |
|
5758 | if ( !statement || statement.node.type !== 'VariableDeclaration' ) return;
|
5759 |
|
5760 | var init = statement.node.declarations[0].init;
|
5761 | if ( !init || init.type === 'FunctionExpression' ) return;
|
5762 |
|
5763 | statement.references.forEach( function (reference) {
|
5764 | if ( reference.name === name ) return;
|
5765 |
|
5766 | var otherDeclaration = this$1.trace( reference.name );
|
5767 | if ( otherDeclaration ) otherDeclaration.addAlias( declaration );
|
5768 | });
|
5769 | });
|
5770 | };
|
5771 |
|
5772 | Module.prototype.bindImportSpecifiers = function bindImportSpecifiers () {
|
5773 | var this$1 = this;
|
5774 |
|
5775 | [ this.imports, this.reexports ].forEach( function (specifiers) {
|
5776 | keys( specifiers ).forEach( function (name) {
|
5777 | var specifier = specifiers[ name ];
|
5778 |
|
5779 | var id = this$1.resolvedIds[ specifier.source ];
|
5780 | specifier.module = this$1.bundle.moduleById.get( id );
|
5781 | });
|
5782 | });
|
5783 |
|
5784 | this.exportAllModules = this.exportAllSources.map( function (source) {
|
5785 | var id = this$1.resolvedIds[ source ];
|
5786 | return this$1.bundle.moduleById.get( id );
|
5787 | });
|
5788 |
|
5789 | this.sources.forEach( function (source) {
|
5790 | var id = this$1.resolvedIds[ source ];
|
5791 | var module = this$1.bundle.moduleById.get( id );
|
5792 |
|
5793 | if ( !module.isExternal ) this$1.dependencies.push( module );
|
5794 | });
|
5795 | };
|
5796 |
|
5797 | Module.prototype.bindReferences = function bindReferences () {
|
5798 | var this$1 = this;
|
5799 |
|
5800 | if ( this.declarations.default ) {
|
5801 | if ( this.exports.default.identifier ) {
|
5802 | var declaration = this.trace( this.exports.default.identifier );
|
5803 | if ( declaration ) this.declarations.default.bind( declaration );
|
5804 | }
|
5805 | }
|
5806 |
|
5807 | this.statements.forEach( function (statement) {
|
5808 |
|
5809 | if ( statement.node.type === 'ExportNamedDeclaration' && statement.node.specifiers.length ) {
|
5810 |
|
5811 | if ( this$1 !== this$1.bundle.entryModule ) return;
|
5812 | }
|
5813 |
|
5814 | statement.references.forEach( function (reference) {
|
5815 | var declaration = reference.scope.findDeclaration( reference.name ) ||
|
5816 | this$1.trace( reference.name );
|
5817 |
|
5818 | if ( declaration ) {
|
5819 | declaration.addReference( reference );
|
5820 | } else {
|
5821 |
|
5822 | this$1.bundle.assumedGlobals[ reference.name ] = true;
|
5823 | }
|
5824 | });
|
5825 | });
|
5826 | };
|
5827 |
|
5828 | Module.prototype.getExports = function getExports () {
|
5829 | var exports = blank();
|
5830 |
|
5831 | keys( this.exports ).forEach( function (name) {
|
5832 | exports[ name ] = true;
|
5833 | });
|
5834 |
|
5835 | keys( this.reexports ).forEach( function (name) {
|
5836 | exports[ name ] = true;
|
5837 | });
|
5838 |
|
5839 | this.exportAllModules.forEach( function (module) {
|
5840 | module.getExports().forEach( function (name) {
|
5841 | if ( name !== 'default' ) exports[ name ] = true;
|
5842 | });
|
5843 | });
|
5844 |
|
5845 | return keys( exports );
|
5846 | };
|
5847 |
|
5848 | Module.prototype.namespace = function namespace () {
|
5849 | if ( !this.declarations['*'] ) {
|
5850 | this.declarations['*'] = new SyntheticNamespaceDeclaration( this );
|
5851 | }
|
5852 |
|
5853 | return this.declarations['*'];
|
5854 | };
|
5855 |
|
5856 | Module.prototype.parse = function parse$1 () {
|
5857 | var this$1 = this;
|
5858 |
|
5859 |
|
5860 | if ( !this.ast ) {
|
5861 |
|
5862 |
|
5863 | try {
|
5864 | this.ast = parse( this.code, assign({
|
5865 | ecmaVersion: 6,
|
5866 | sourceType: 'module',
|
5867 | onComment: function ( block, text, start, end ) { return this$1.comments.push({ block: block, text: text, start: start, end: end }); },
|
5868 | preserveParens: true
|
5869 | }, this.bundle.acornOptions ));
|
5870 | } catch ( err ) {
|
5871 | err.code = 'PARSE_ERROR';
|
5872 | err.file = this.id;
|
5873 | err.message += " in " + (this.id);
|
5874 | throw err;
|
5875 | }
|
5876 | }
|
5877 |
|
5878 | walk( this.ast, {
|
5879 | enter: function (node) {
|
5880 |
|
5881 | if ( node.type === 'IfStatement' ) {
|
5882 | if ( isFalsy( node.test ) ) {
|
5883 | this$1.magicString.overwrite( node.consequent.start, node.consequent.end, '{}' );
|
5884 | node.consequent = emptyBlockStatement( node.consequent.start, node.consequent.end );
|
5885 | } else if ( node.alternate && isTruthy( node.test ) ) {
|
5886 | this$1.magicString.overwrite( node.alternate.start, node.alternate.end, '{}' );
|
5887 | node.alternate = emptyBlockStatement( node.alternate.start, node.alternate.end );
|
5888 | }
|
5889 | }
|
5890 |
|
5891 | this$1.magicString.addSourcemapLocation( node.start );
|
5892 | this$1.magicString.addSourcemapLocation( node.end );
|
5893 | },
|
5894 |
|
5895 | leave: function ( node, parent, prop ) {
|
5896 |
|
5897 | if ( node.type === 'ConditionalExpression' ) {
|
5898 | if ( isFalsy( node.test ) ) {
|
5899 | this$1.magicString.remove( node.start, node.alternate.start );
|
5900 | parent[prop] = node.alternate;
|
5901 | } else if ( isTruthy( node.test ) ) {
|
5902 | this$1.magicString.remove( node.start, node.consequent.start );
|
5903 | this$1.magicString.remove( node.consequent.end, node.end );
|
5904 | parent[prop] = node.consequent;
|
5905 | }
|
5906 | }
|
5907 | }
|
5908 | });
|
5909 |
|
5910 | var statements = [];
|
5911 | var lastChar = 0;
|
5912 | var commentIndex = 0;
|
5913 |
|
5914 | this.ast.body.forEach( function (node) {
|
5915 | if ( node.type === 'EmptyStatement' ) return;
|
5916 |
|
5917 | if (
|
5918 | node.type === 'ExportNamedDeclaration' &&
|
5919 | node.declaration &&
|
5920 | node.declaration.type === 'VariableDeclaration' &&
|
5921 | node.declaration.declarations &&
|
5922 | node.declaration.declarations.length > 1
|
5923 | ) {
|
5924 |
|
5925 | var syntheticNode = {
|
5926 | type: 'ExportNamedDeclaration',
|
5927 | specifiers: node.declaration.declarations.map( function (declarator) {
|
5928 | var id = { name: declarator.id.name };
|
5929 | return {
|
5930 | local: id,
|
5931 | exported: id
|
5932 | };
|
5933 | }),
|
5934 | isSynthetic: true
|
5935 | };
|
5936 |
|
5937 | var statement = new Statement( syntheticNode, this$1, node.start, node.start );
|
5938 | statements.push( statement );
|
5939 |
|
5940 | this$1.magicString.remove( node.start, node.declaration.start );
|
5941 | node = node.declaration;
|
5942 | }
|
5943 |
|
5944 |
|
5945 |
|
5946 |
|
5947 | if ( node.type === 'VariableDeclaration' && node.declarations.length > 1 ) {
|
5948 |
|
5949 |
|
5950 | var lastStatement = statements[ statements.length - 1 ];
|
5951 | if ( !lastStatement || !lastStatement.node.isSynthetic ) {
|
5952 | this$1.magicString.remove( node.start, node.declarations[0].start );
|
5953 | }
|
5954 |
|
5955 | node.declarations.forEach( function (declarator) {
|
5956 | var start = declarator.start;
|
5957 | var end = declarator.end;
|
5958 |
|
5959 | var syntheticNode = {
|
5960 | type: 'VariableDeclaration',
|
5961 | kind: node.kind,
|
5962 | start: start,
|
5963 | end: end,
|
5964 | declarations: [ declarator ],
|
5965 | isSynthetic: true
|
5966 | };
|
5967 |
|
5968 | var statement = new Statement( syntheticNode, this$1, start, end );
|
5969 | statements.push( statement );
|
5970 | });
|
5971 |
|
5972 | lastChar = node.end;
|
5973 | }
|
5974 |
|
5975 | else {
|
5976 | var comment;
|
5977 | do {
|
5978 | comment = this$1.comments[ commentIndex ];
|
5979 | if ( !comment ) break;
|
5980 | if ( comment.start > node.start ) break;
|
5981 | commentIndex += 1;
|
5982 | } while ( comment.end < lastChar );
|
5983 |
|
5984 | var start = comment ? Math.min( comment.start, node.start ) : node.start;
|
5985 | var end = node.end;
|
5986 |
|
5987 | var statement$1 = new Statement( node, this$1, start, end );
|
5988 | statements.push( statement$1 );
|
5989 |
|
5990 | lastChar = end;
|
5991 | }
|
5992 | });
|
5993 |
|
5994 | var i = statements.length;
|
5995 | var next = this.code.length;
|
5996 | while ( i-- ) {
|
5997 | statements[i].next = next;
|
5998 | if ( !statements[i].isSynthetic ) next = statements[i].start;
|
5999 | }
|
6000 |
|
6001 | return statements;
|
6002 | };
|
6003 |
|
6004 | Module.prototype.render = function render ( es ) {
|
6005 | var this$1 = this;
|
6006 |
|
6007 | var magicString = this.magicString.clone();
|
6008 |
|
6009 | this.statements.forEach( function (statement) {
|
6010 | if ( !statement.isIncluded ) {
|
6011 | magicString.remove( statement.start, statement.next );
|
6012 | return;
|
6013 | }
|
6014 |
|
6015 | statement.stringLiteralRanges.forEach( function (range) { return magicString.indentExclusionRanges.push( range ); } );
|
6016 |
|
6017 |
|
6018 | if ( statement.node.type === 'ExportNamedDeclaration' ) {
|
6019 | if ( statement.node.isSynthetic ) return;
|
6020 |
|
6021 |
|
6022 | if ( statement.node.specifiers.length ) {
|
6023 | magicString.remove( statement.start, statement.next );
|
6024 | return;
|
6025 | }
|
6026 | }
|
6027 |
|
6028 |
|
6029 | if ( statement.node.type === 'VariableDeclaration' ) {
|
6030 | var declarator = statement.node.declarations[0];
|
6031 |
|
6032 | if ( declarator.id.type === 'Identifier' ) {
|
6033 | var declaration = this$1.declarations[ declarator.id.name ];
|
6034 |
|
6035 | if ( declaration.exportName && declaration.isReassigned ) {
|
6036 | magicString.remove( statement.start, declarator.init ? declarator.start : statement.next );
|
6037 | if ( !declarator.init ) return;
|
6038 | }
|
6039 | }
|
6040 |
|
6041 | else {
|
6042 |
|
6043 |
|
6044 |
|
6045 |
|
6046 | extractNames( declarator.id ).forEach( function (name) {
|
6047 | var declaration = this$1.declarations[ name ];
|
6048 |
|
6049 | if ( declaration.exportName && declaration.isReassigned ) {
|
6050 | magicString.insertLeft( statement.end, (";\nexports." + name + " = " + (declaration.render( es ))) );
|
6051 | }
|
6052 | });
|
6053 | }
|
6054 |
|
6055 | if ( statement.node.isSynthetic ) {
|
6056 |
|
6057 | magicString.insertRight( statement.start, ((statement.node.kind) + " ") );
|
6058 | magicString.insertLeft( statement.end, ';' );
|
6059 | magicString.overwrite( statement.end, statement.next, '\n' );
|
6060 | }
|
6061 | }
|
6062 |
|
6063 | var toDeshadow = blank();
|
6064 |
|
6065 | statement.references.forEach( function (reference) {
|
6066 | var start = reference.start;
|
6067 | var end = reference.end;
|
6068 |
|
6069 | if ( reference.isUndefined ) {
|
6070 | magicString.overwrite( start, end, 'undefined', true );
|
6071 | }
|
6072 |
|
6073 | var declaration = reference.declaration;
|
6074 |
|
6075 | if ( declaration ) {
|
6076 | var name = declaration.render( es );
|
6077 |
|
6078 |
|
6079 |
|
6080 | if ( reference.name === name && name.length === end - start ) return;
|
6081 |
|
6082 | reference.rewritten = true;
|
6083 |
|
6084 |
|
6085 | var identifier = name.match( /[^\.]+/ )[0];
|
6086 | if ( reference.scope.contains( identifier ) ) {
|
6087 | toDeshadow[ identifier ] = identifier + "$$";
|
6088 | }
|
6089 |
|
6090 | if ( reference.isShorthandProperty ) {
|
6091 | magicString.insertLeft( end, (": " + name) );
|
6092 | } else {
|
6093 | magicString.overwrite( start, end, name, true );
|
6094 | }
|
6095 | }
|
6096 | });
|
6097 |
|
6098 | if ( keys( toDeshadow ).length ) {
|
6099 | statement.references.forEach( function (reference) {
|
6100 | if ( !reference.rewritten && reference.name in toDeshadow ) {
|
6101 | var replacement = toDeshadow[ reference.name ];
|
6102 | magicString.overwrite( reference.start, reference.end, reference.isShorthandProperty ? ((reference.name) + ": " + replacement) : replacement, true );
|
6103 | }
|
6104 | });
|
6105 | }
|
6106 |
|
6107 |
|
6108 | if ( statement.isExportDeclaration ) {
|
6109 |
|
6110 |
|
6111 |
|
6112 | if ( statement.node.type === 'ExportNamedDeclaration' && statement.node.declaration.type === 'VariableDeclaration' ) {
|
6113 | var name = extractNames( statement.node.declaration.declarations[ 0 ].id )[ 0 ];
|
6114 | var declaration$1 = this$1.declarations[ name ];
|
6115 |
|
6116 | if ( !declaration$1 ) throw new Error( ("Missing declaration for " + name + "!") );
|
6117 |
|
6118 | var end = declaration$1.exportName && declaration$1.isReassigned ?
|
6119 | statement.node.declaration.declarations[0].start :
|
6120 | statement.node.declaration.start;
|
6121 |
|
6122 | magicString.remove( statement.node.start, end );
|
6123 | }
|
6124 |
|
6125 | else if ( statement.node.type === 'ExportAllDeclaration' ) {
|
6126 |
|
6127 | magicString.remove( statement.start, statement.next );
|
6128 | }
|
6129 |
|
6130 |
|
6131 |
|
6132 | else if ( statement.node.declaration.id ) {
|
6133 | magicString.remove( statement.node.start, statement.node.declaration.start );
|
6134 | }
|
6135 |
|
6136 | else if ( statement.node.type === 'ExportDefaultDeclaration' ) {
|
6137 | var defaultDeclaration = this$1.declarations.default;
|
6138 |
|
6139 |
|
6140 | if ( defaultDeclaration.original && !defaultDeclaration.original.isReassigned ) {
|
6141 | magicString.remove( statement.start, statement.next );
|
6142 | return;
|
6143 | }
|
6144 |
|
6145 | var defaultName = defaultDeclaration.render();
|
6146 |
|
6147 |
|
6148 | if ( !defaultDeclaration.exportName && !defaultDeclaration.isUsed ) {
|
6149 | magicString.remove( statement.start, statement.node.declaration.start );
|
6150 | return;
|
6151 | }
|
6152 |
|
6153 |
|
6154 | if ( statement.node.declaration.type === 'FunctionExpression' ) {
|
6155 | magicString.overwrite( statement.node.start, statement.node.declaration.start + 8, ("function " + defaultName) );
|
6156 | } else {
|
6157 | magicString.overwrite( statement.node.start, statement.node.declaration.start, ((this$1.bundle.varOrConst) + " " + defaultName + " = ") );
|
6158 | }
|
6159 | }
|
6160 |
|
6161 | else {
|
6162 | throw new Error( 'Unhandled export' );
|
6163 | }
|
6164 | }
|
6165 | });
|
6166 |
|
6167 |
|
6168 | var namespace = this.declarations['*'];
|
6169 | if ( namespace && namespace.needsNamespaceBlock ) {
|
6170 | magicString.append( '\n\n' + namespace.renderBlock( magicString.getIndentString() ) );
|
6171 | }
|
6172 |
|
6173 | return magicString.trim();
|
6174 | };
|
6175 |
|
6176 |
|
6177 |
|
6178 |
|
6179 |
|
6180 |
|
6181 |
|
6182 |
|
6183 | Module.prototype.run = function run ( treeshake ) {
|
6184 | var this$1 = this;
|
6185 |
|
6186 | if ( !treeshake ) {
|
6187 | this.statements.forEach( function (statement) {
|
6188 | if ( statement.isImportDeclaration || ( statement.isExportDeclaration && statement.node.isSynthetic ) ) return;
|
6189 |
|
6190 | statement.mark();
|
6191 | });
|
6192 | return false;
|
6193 | }
|
6194 |
|
6195 | var marked = false;
|
6196 |
|
6197 | this.statements.forEach( function (statement) {
|
6198 | marked = statement.run( this$1.strongDependencies ) || marked;
|
6199 | });
|
6200 |
|
6201 | return marked;
|
6202 | };
|
6203 |
|
6204 | Module.prototype.toJSON = function toJSON () {
|
6205 | return {
|
6206 | id: this.id,
|
6207 | code: this.code,
|
6208 | originalCode: this.originalCode,
|
6209 | ast: this.ast,
|
6210 | sourceMapChain: this.sourceMapChain
|
6211 | };
|
6212 | };
|
6213 |
|
6214 | Module.prototype.trace = function trace ( name ) {
|
6215 | if ( name in this.declarations ) return this.declarations[ name ];
|
6216 | if ( name in this.imports ) {
|
6217 | var importDeclaration = this.imports[ name ];
|
6218 | var otherModule = importDeclaration.module;
|
6219 |
|
6220 | if ( importDeclaration.name === '*' && !otherModule.isExternal ) {
|
6221 | return otherModule.namespace();
|
6222 | }
|
6223 |
|
6224 | var declaration = otherModule.traceExport( importDeclaration.name );
|
6225 |
|
6226 | if ( !declaration ) throw new Error( ("Module " + (otherModule.id) + " does not export " + (importDeclaration.name) + " (imported by " + (this.id) + ")") );
|
6227 | return declaration;
|
6228 | }
|
6229 |
|
6230 | return null;
|
6231 | };
|
6232 |
|
6233 | Module.prototype.traceExport = function traceExport ( name ) {
|
6234 | var this$1 = this;
|
6235 |
|
6236 |
|
6237 | var reexportDeclaration = this.reexports[ name ];
|
6238 | if ( reexportDeclaration ) {
|
6239 | var declaration = reexportDeclaration.module.traceExport( reexportDeclaration.localName );
|
6240 |
|
6241 | if ( !declaration ) {
|
6242 | var err = new Error( ("'" + (reexportDeclaration.localName) + "' is not exported by '" + (reexportDeclaration.module.id) + "' (imported by '" + (this.id) + "')") );
|
6243 | err.file = this.id;
|
6244 | err.loc = getLocation( this.code, reexportDeclaration.start );
|
6245 | throw err;
|
6246 | }
|
6247 |
|
6248 | return declaration;
|
6249 | }
|
6250 |
|
6251 | var exportDeclaration = this.exports[ name ];
|
6252 | if ( exportDeclaration ) {
|
6253 | var name$1 = exportDeclaration.localName;
|
6254 | var declaration$1 = this.trace( name$1 );
|
6255 |
|
6256 | if ( declaration$1 ) return declaration$1;
|
6257 |
|
6258 | this.bundle.assumedGlobals[ name$1 ] = true;
|
6259 | return ( this.declarations[ name$1 ] = new SyntheticGlobalDeclaration( name$1 ) );
|
6260 | }
|
6261 |
|
6262 | for ( var i = 0; i < this.exportAllModules.length; i += 1 ) {
|
6263 | var module = this$1.exportAllModules[i];
|
6264 | var declaration$2 = module.traceExport( name );
|
6265 |
|
6266 | if ( declaration$2 ) return declaration$2;
|
6267 | }
|
6268 | };
|
6269 |
|
6270 | var ExternalModule = function ExternalModule ( id ) {
|
6271 | this.id = id;
|
6272 | this.name = makeLegalIdentifier( id );
|
6273 |
|
6274 | this.nameSuggestions = blank();
|
6275 | this.mostCommonSuggestion = 0;
|
6276 |
|
6277 | this.isExternal = true;
|
6278 | this.declarations = blank();
|
6279 |
|
6280 | this.exportsNames = false;
|
6281 | };
|
6282 |
|
6283 | ExternalModule.prototype.suggestName = function suggestName ( name ) {
|
6284 | if ( !this.nameSuggestions[ name ] ) this.nameSuggestions[ name ] = 0;
|
6285 | this.nameSuggestions[ name ] += 1;
|
6286 |
|
6287 | if ( this.nameSuggestions[ name ] > this.mostCommonSuggestion ) {
|
6288 | this.mostCommonSuggestion = this.nameSuggestions[ name ];
|
6289 | this.name = name;
|
6290 | }
|
6291 | };
|
6292 |
|
6293 | ExternalModule.prototype.traceExport = function traceExport ( name ) {
|
6294 | if ( name !== 'default' && name !== '*' ) this.exportsNames = true;
|
6295 | if ( name === '*' ) this.exportsNamespace = true;
|
6296 |
|
6297 | return this.declarations[ name ] || (
|
6298 | this.declarations[ name ] = new ExternalDeclaration( this, name )
|
6299 | );
|
6300 | };
|
6301 |
|
6302 | function getName ( x ) {
|
6303 | return x.name;
|
6304 | }
|
6305 |
|
6306 | function quoteId ( x ) {
|
6307 | return ("'" + (x.id) + "'");
|
6308 | }
|
6309 |
|
6310 | function req ( x ) {
|
6311 | return ("require('" + (x.id) + "')");
|
6312 | }
|
6313 |
|
6314 | function getInteropBlock ( bundle ) {
|
6315 | return bundle.externalModules
|
6316 | .map( function (module) {
|
6317 | if ( !module.declarations.default ) return null;
|
6318 |
|
6319 | if ( module.exportsNamespace ) {
|
6320 | return ((bundle.varOrConst) + " " + (module.name) + "__default = " + (module.name) + "['default'];");
|
6321 | }
|
6322 |
|
6323 | if ( module.exportsNames ) {
|
6324 | return ((bundle.varOrConst) + " " + (module.name) + "__default = 'default' in " + (module.name) + " ? " + (module.name) + "['default'] : " + (module.name) + ";");
|
6325 | }
|
6326 |
|
6327 | return ((module.name) + " = 'default' in " + (module.name) + " ? " + (module.name) + "['default'] : " + (module.name) + ";");
|
6328 | })
|
6329 | .filter( Boolean )
|
6330 | .join( '\n' );
|
6331 | }
|
6332 |
|
6333 | function getExportBlock ( entryModule, exportMode, mechanism ) {
|
6334 | if ( mechanism === void 0 ) mechanism = 'return';
|
6335 |
|
6336 | if ( exportMode === 'default' ) {
|
6337 | return (mechanism + " " + (entryModule.traceExport( 'default' ).render( false )) + ";");
|
6338 | }
|
6339 |
|
6340 | return entryModule.getExports()
|
6341 | .map( function (name) {
|
6342 | var prop = name === 'default' ? "['default']" : ("." + name);
|
6343 | var declaration = entryModule.traceExport( name );
|
6344 |
|
6345 | var lhs = "exports" + prop;
|
6346 | var rhs = declaration.render( false );
|
6347 |
|
6348 |
|
6349 | if ( lhs === rhs ) return null;
|
6350 |
|
6351 | return (lhs + " = " + rhs + ";");
|
6352 | })
|
6353 | .filter( Boolean )
|
6354 | .join( '\n' );
|
6355 | }
|
6356 |
|
6357 | var esModuleExport = "Object.defineProperty(exports, '__esModule', { value: true });";
|
6358 |
|
6359 | function amd ( bundle, magicString, ref, options ) {
|
6360 | var exportMode = ref.exportMode;
|
6361 | var indentString = ref.indentString;
|
6362 |
|
6363 | var deps = bundle.externalModules.map( quoteId );
|
6364 | var args = bundle.externalModules.map( getName );
|
6365 |
|
6366 | if ( exportMode === 'named' ) {
|
6367 | args.unshift( "exports" );
|
6368 | deps.unshift( "'exports'" );
|
6369 | }
|
6370 |
|
6371 | var params =
|
6372 | ( options.moduleId ? ("'" + (options.moduleId) + "', ") : "" ) +
|
6373 | ( deps.length ? ("[" + (deps.join( ', ' )) + "], ") : "" );
|
6374 |
|
6375 | var useStrict = options.useStrict !== false ? " 'use strict';" : "";
|
6376 | var intro = "define(" + params + "function (" + (args.join( ', ' )) + ") {" + useStrict + "\n\n";
|
6377 |
|
6378 |
|
6379 | var interopBlock = getInteropBlock( bundle );
|
6380 | if ( interopBlock ) magicString.prepend( interopBlock + '\n\n' );
|
6381 |
|
6382 | var exportBlock = getExportBlock( bundle.entryModule, exportMode );
|
6383 | if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
|
6384 |
|
6385 | if ( exportMode === 'named' ) {
|
6386 | magicString.append( ("\n\n" + esModuleExport) );
|
6387 | }
|
6388 |
|
6389 | return magicString
|
6390 | .indent( indentString )
|
6391 | .append( '\n\n});' )
|
6392 | .prepend( intro );
|
6393 | }
|
6394 |
|
6395 | function cjs ( bundle, magicString, ref, options ) {
|
6396 | var exportMode = ref.exportMode;
|
6397 |
|
6398 | var intro = ( options.useStrict === false ? "" : "'use strict';\n\n" ) +
|
6399 | ( exportMode === 'named' ? (esModuleExport + "\n\n") : '' );
|
6400 |
|
6401 | var needsInterop = false;
|
6402 |
|
6403 | var varOrConst = bundle.varOrConst;
|
6404 |
|
6405 |
|
6406 | var importBlock = bundle.externalModules
|
6407 | .map( function (module) {
|
6408 | if ( module.declarations.default ) {
|
6409 | if ( module.exportsNamespace ) {
|
6410 | return varOrConst + " " + (module.name) + " = require('" + (module.id) + "');" +
|
6411 | "\n" + varOrConst + " " + (module.name) + "__default = " + (module.name) + "['default'];";
|
6412 | }
|
6413 |
|
6414 | needsInterop = true;
|
6415 |
|
6416 | if ( module.exportsNames ) {
|
6417 | return varOrConst + " " + (module.name) + " = require('" + (module.id) + "');" +
|
6418 | "\n" + varOrConst + " " + (module.name) + "__default = _interopDefault(" + (module.name) + ");";
|
6419 | }
|
6420 |
|
6421 | return (varOrConst + " " + (module.name) + " = _interopDefault(require('" + (module.id) + "'));");
|
6422 | } else {
|
6423 | return (varOrConst + " " + (module.name) + " = require('" + (module.id) + "');");
|
6424 | }
|
6425 | })
|
6426 | .join( '\n' );
|
6427 |
|
6428 | if ( needsInterop ) {
|
6429 | intro += "function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\n";
|
6430 | }
|
6431 |
|
6432 | if ( importBlock ) {
|
6433 | intro += importBlock + '\n\n';
|
6434 | }
|
6435 |
|
6436 | magicString.prepend( intro );
|
6437 |
|
6438 | var exportBlock = getExportBlock( bundle.entryModule, exportMode, 'module.exports =' );
|
6439 | if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
|
6440 |
|
6441 | return magicString;
|
6442 | }
|
6443 |
|
6444 | function notDefault ( name ) {
|
6445 | return name !== 'default';
|
6446 | }
|
6447 |
|
6448 | function es ( bundle, magicString ) {
|
6449 | var importBlock = bundle.externalModules
|
6450 | .map( function (module) {
|
6451 | var specifiers = [];
|
6452 | var specifiersList = [specifiers];
|
6453 | var importedNames = keys( module.declarations )
|
6454 | .filter( function (name) { return name !== '*' && name !== 'default'; } )
|
6455 | .map( function (name) {
|
6456 | var declaration = module.declarations[ name ];
|
6457 |
|
6458 | if ( declaration.name === declaration.safeName ) return declaration.name;
|
6459 | return ((declaration.name) + " as " + (declaration.safeName));
|
6460 | });
|
6461 |
|
6462 | if ( module.declarations.default ) {
|
6463 | if ( module.exportsNamespace ) {
|
6464 | specifiersList.push([ ((module.name) + "__default") ]);
|
6465 | } else {
|
6466 | specifiers.push( module.name );
|
6467 | }
|
6468 | }
|
6469 |
|
6470 | var namespaceSpecifier = module.declarations['*'] ? ("* as " + (module.name)) : null;
|
6471 | var namedSpecifier = importedNames.length ? ("{ " + (importedNames.join( ', ' )) + " }") : null;
|
6472 |
|
6473 | if ( namespaceSpecifier && namedSpecifier ) {
|
6474 |
|
6475 | specifiersList.push( [namespaceSpecifier] );
|
6476 | specifiers.push( namedSpecifier );
|
6477 | } else if ( namedSpecifier ) {
|
6478 | specifiers.push( namedSpecifier );
|
6479 | } else if ( namespaceSpecifier ) {
|
6480 | specifiers.push( namespaceSpecifier );
|
6481 | }
|
6482 |
|
6483 | return specifiersList
|
6484 | .map( function (specifiers) { return specifiers.length ?
|
6485 | ("import " + (specifiers.join( ', ' )) + " from '" + (module.id) + "';") :
|
6486 | ("import '" + (module.id) + "';"); }
|
6487 | )
|
6488 | .join( '\n' );
|
6489 | })
|
6490 | .join( '\n' );
|
6491 |
|
6492 | if ( importBlock ) {
|
6493 | magicString.prepend( importBlock + '\n\n' );
|
6494 | }
|
6495 |
|
6496 | var module = bundle.entryModule;
|
6497 |
|
6498 | var specifiers = module.getExports().filter( notDefault ).map( function (name) {
|
6499 | var declaration = module.traceExport( name );
|
6500 | var rendered = declaration.render( true );
|
6501 |
|
6502 | return rendered === name ?
|
6503 | name :
|
6504 | (rendered + " as " + name);
|
6505 | });
|
6506 |
|
6507 | var exportBlock = specifiers.length ? ("export { " + (specifiers.join(', ')) + " };") : '';
|
6508 |
|
6509 | var defaultExport = module.exports.default || module.reexports.default;
|
6510 | if ( defaultExport ) {
|
6511 | exportBlock += "export default " + (module.traceExport( 'default' ).render( true )) + ";";
|
6512 | }
|
6513 |
|
6514 | if ( exportBlock ) {
|
6515 | magicString.append( '\n\n' + exportBlock.trim() );
|
6516 | }
|
6517 |
|
6518 | return magicString.trim();
|
6519 | }
|
6520 |
|
6521 | function getGlobalNameMaker ( globals, onwarn ) {
|
6522 | var fn = typeof globals === 'function' ? globals : function (id) { return globals[ id ]; };
|
6523 |
|
6524 | return function ( module ) {
|
6525 | var name = fn( module.id );
|
6526 | if ( name ) return name;
|
6527 |
|
6528 | onwarn( ("No name was provided for external module '" + (module.id) + "' in options.globals – guessing '" + (module.name) + "'") );
|
6529 | return module.name;
|
6530 | };
|
6531 | }
|
6532 |
|
6533 | function setupNamespace ( keypath ) {
|
6534 | var parts = keypath.split( '.' );
|
6535 |
|
6536 | parts.pop();
|
6537 |
|
6538 | var acc = 'this';
|
6539 |
|
6540 | return parts
|
6541 | .map( function (part) { return ( acc += "." + part, (acc + " = " + acc + " || {};") ); } )
|
6542 | .join( '\n' ) + '\n';
|
6543 | }
|
6544 |
|
6545 | function iife ( bundle, magicString, ref, options ) {
|
6546 | var exportMode = ref.exportMode;
|
6547 | var indentString = ref.indentString;
|
6548 |
|
6549 | var globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn );
|
6550 |
|
6551 | var name = options.moduleName;
|
6552 | var isNamespaced = name && ~name.indexOf( '.' );
|
6553 |
|
6554 | var dependencies = bundle.externalModules.map( globalNameMaker );
|
6555 |
|
6556 | var args = bundle.externalModules.map( getName );
|
6557 |
|
6558 | if ( exportMode !== 'none' && !name ) {
|
6559 | throw new Error( 'You must supply options.moduleName for IIFE bundles' );
|
6560 | }
|
6561 |
|
6562 | if ( exportMode === 'named' ) {
|
6563 | dependencies.unshift( ("(this." + name + " = this." + name + " || {})") );
|
6564 | args.unshift( 'exports' );
|
6565 | }
|
6566 |
|
6567 | var useStrict = options.useStrict !== false ? "'use strict';" : "";
|
6568 |
|
6569 | var intro = "(function (" + args + ") {\n";
|
6570 | var outro = "\n\n}(" + dependencies + "));";
|
6571 |
|
6572 | if ( exportMode === 'default' ) {
|
6573 | intro = ( isNamespaced ? "this." : ((bundle.varOrConst) + " ") ) + name + " = " + intro;
|
6574 | }
|
6575 |
|
6576 | if ( isNamespaced ) {
|
6577 | intro = setupNamespace( name ) + intro;
|
6578 | }
|
6579 |
|
6580 |
|
6581 | var interopBlock = getInteropBlock( bundle );
|
6582 | if ( interopBlock ) magicString.prepend( interopBlock + '\n\n' );
|
6583 | if ( useStrict ) magicString.prepend( useStrict + '\n\n' );
|
6584 | var exportBlock = getExportBlock( bundle.entryModule, exportMode );
|
6585 | if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
|
6586 |
|
6587 | return magicString
|
6588 | .indent( indentString )
|
6589 | .prepend( intro )
|
6590 | .append( outro );
|
6591 | }
|
6592 |
|
6593 | function setupNamespace$1 ( name ) {
|
6594 | var parts = name.split( '.' );
|
6595 | parts.pop();
|
6596 |
|
6597 | var acc = 'global';
|
6598 | return parts
|
6599 | .map( function (part) { return ( acc += "." + part, (acc + " = " + acc + " || {}") ); } )
|
6600 | .concat( ("global." + name) )
|
6601 | .join( ', ' );
|
6602 | }
|
6603 |
|
6604 | function umd ( bundle, magicString, ref, options ) {
|
6605 | var exportMode = ref.exportMode;
|
6606 | var indentString = ref.indentString;
|
6607 |
|
6608 | if ( exportMode !== 'none' && !options.moduleName ) {
|
6609 | throw new Error( 'You must supply options.moduleName for UMD bundles' );
|
6610 | }
|
6611 |
|
6612 | var globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle.onwarn );
|
6613 |
|
6614 | var amdDeps = bundle.externalModules.map( quoteId );
|
6615 | var cjsDeps = bundle.externalModules.map( req );
|
6616 | var globalDeps = bundle.externalModules.map( function (module) { return ("global." + (globalNameMaker( module ))); } );
|
6617 |
|
6618 | var args = bundle.externalModules.map( getName );
|
6619 |
|
6620 | if ( exportMode === 'named' ) {
|
6621 | amdDeps.unshift( "'exports'" );
|
6622 | cjsDeps.unshift( "exports" );
|
6623 | globalDeps.unshift( ("(" + (setupNamespace$1(options.moduleName)) + " = global." + (options.moduleName) + " || {})") );
|
6624 |
|
6625 | args.unshift( 'exports' );
|
6626 | }
|
6627 |
|
6628 | var amdParams =
|
6629 | ( options.moduleId ? ("'" + (options.moduleId) + "', ") : "" ) +
|
6630 | ( amdDeps.length ? ("[" + (amdDeps.join( ', ' )) + "], ") : "" );
|
6631 |
|
6632 | var cjsExport = exportMode === 'default' ? "module.exports = " : "";
|
6633 | var defaultExport = exportMode === 'default' ? ((setupNamespace$1(options.moduleName)) + " = ") : '';
|
6634 |
|
6635 | var useStrict = options.useStrict !== false ? " 'use strict';" : "";
|
6636 |
|
6637 | var globalExport = options.noConflict === true ?
|
6638 | ("(function() {\n\t\t\t\tvar current = global." + (options.moduleName) + ";\n\t\t\t\tvar exports = factory(" + globalDeps + ");\n\t\t\t\tglobal." + (options.moduleName) + " = exports;\n\t\t\t\texports.noConflict = function() { global." + (options.moduleName) + " = current; return exports; };\n\t\t\t})()") : ("(" + defaultExport + "factory(" + globalDeps + "))");
|
6639 |
|
6640 | var intro =
|
6641 | ("(function (global, factory) {\n\t\t\ttypeof exports === 'object' && typeof module !== 'undefined' ? " + cjsExport + "factory(" + (cjsDeps.join( ', ' )) + ") :\n\t\t\ttypeof define === 'function' && define.amd ? define(" + amdParams + "factory) :\n\t\t\t" + globalExport + ";\n\t\t}(this, function (" + args + ") {" + useStrict + "\n\n\t\t").replace( /^\t\t/gm, '' ).replace( /^\t/gm, magicString.getIndentString() );
|
6642 |
|
6643 |
|
6644 | var interopBlock = getInteropBlock( bundle );
|
6645 | if ( interopBlock ) magicString.prepend( interopBlock + '\n\n' );
|
6646 |
|
6647 | var exportBlock = getExportBlock( bundle.entryModule, exportMode );
|
6648 | if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
|
6649 |
|
6650 | if (exportMode === 'named') {
|
6651 | magicString.append( ("\n\n" + esModuleExport) );
|
6652 | }
|
6653 |
|
6654 | return magicString
|
6655 | .trim()
|
6656 | .indent( indentString )
|
6657 | .append( '\n\n}));' )
|
6658 | .prepend( intro );
|
6659 | }
|
6660 |
|
6661 | var finalisers = { amd: amd, cjs: cjs, es: es, iife: iife, umd: umd };
|
6662 |
|
6663 | function ensureArray ( thing ) {
|
6664 | if ( Array.isArray( thing ) ) return thing;
|
6665 | if ( thing == undefined ) return [];
|
6666 | return [ thing ];
|
6667 | }
|
6668 |
|
6669 | function load ( id ) {
|
6670 | return readFileSync( id, 'utf-8' );
|
6671 | }
|
6672 |
|
6673 | function addJsExtensionIfNecessary ( file ) {
|
6674 | if ( isFile( file ) ) return file;
|
6675 |
|
6676 | file += '.js';
|
6677 | if ( isFile( file ) ) return file;
|
6678 |
|
6679 | return null;
|
6680 | }
|
6681 |
|
6682 | function resolveId ( importee, importer ) {
|
6683 | if ( typeof process === 'undefined' ) throw new Error( "It looks like you're using Rollup in a non-Node.js environment. This means you must supply a plugin with custom resolveId and load functions. See https://github.com/rollup/rollup/wiki/Plugins for more information" );
|
6684 |
|
6685 |
|
6686 | if ( isAbsolute( importee ) ) return addJsExtensionIfNecessary( resolve( importee ) );
|
6687 |
|
6688 |
|
6689 | if ( importer === undefined ) return addJsExtensionIfNecessary( resolve( process.cwd(), importee ) );
|
6690 |
|
6691 |
|
6692 | if ( importee[0] !== '.' ) return null;
|
6693 |
|
6694 | return addJsExtensionIfNecessary( resolve( dirname( importer ), importee ) );
|
6695 | }
|
6696 |
|
6697 |
|
6698 | function makeOnwarn () {
|
6699 | var warned = blank();
|
6700 |
|
6701 | return function (msg) {
|
6702 | if ( msg in warned ) return;
|
6703 | console.error( msg );
|
6704 | warned[ msg ] = true;
|
6705 | };
|
6706 | }
|
6707 |
|
6708 | function badExports ( option, keys ) {
|
6709 | throw new Error( ("'" + option + "' was specified for options.exports, but entry module has following exports: " + (keys.join(', '))) );
|
6710 | }
|
6711 |
|
6712 | function getExportMode ( bundle, exportMode, moduleName ) {
|
6713 | var exportKeys = keys( bundle.entryModule.exports )
|
6714 | .concat( keys( bundle.entryModule.reexports ) )
|
6715 | .concat( bundle.entryModule.exportAllSources );
|
6716 |
|
6717 | if ( exportMode === 'default' ) {
|
6718 | if ( exportKeys.length !== 1 || exportKeys[0] !== 'default' ) {
|
6719 | badExports( 'default', exportKeys );
|
6720 | }
|
6721 | } else if ( exportMode === 'none' && exportKeys.length ) {
|
6722 | badExports( 'none', exportKeys );
|
6723 | }
|
6724 |
|
6725 | if ( !exportMode || exportMode === 'auto' ) {
|
6726 | if ( exportKeys.length === 0 ) {
|
6727 | exportMode = 'none';
|
6728 | } else if ( exportKeys.length === 1 && exportKeys[0] === 'default' ) {
|
6729 | exportMode = 'default';
|
6730 | } else {
|
6731 | if ( bundle.entryModule.exports.default ) {
|
6732 | bundle.onwarn( ("Using named and default exports together. Consumers of your bundle will have to use " + (moduleName || 'bundle') + "['default'] to access the default export, which may not be what you want. Use `exports: 'named'` to disable this warning. See https://github.com/rollup/rollup/wiki/JavaScript-API#exports for more information") );
|
6733 | }
|
6734 | exportMode = 'named';
|
6735 | }
|
6736 | }
|
6737 |
|
6738 | if ( !/(?:default|named|none)/.test( exportMode ) ) {
|
6739 | throw new Error( "options.exports must be 'default', 'named', 'none', 'auto', or left unspecified (defaults to 'auto')" );
|
6740 | }
|
6741 |
|
6742 | return exportMode;
|
6743 | }
|
6744 |
|
6745 | function getIndentString ( magicString, options ) {
|
6746 | if ( !( 'indent' in options ) || options.indent === true ) {
|
6747 | return magicString.getIndentString();
|
6748 | }
|
6749 |
|
6750 | return options.indent || '';
|
6751 | }
|
6752 |
|
6753 | function unixizePath ( path ) {
|
6754 | return path.split( /[\/\\]/ ).join( '/' );
|
6755 | }
|
6756 |
|
6757 | function transform ( source, id, plugins ) {
|
6758 | var sourceMapChain = [];
|
6759 |
|
6760 | var originalSourceMap = typeof source.map === 'string' ? JSON.parse( source.map ) : source.map;
|
6761 |
|
6762 | var originalCode = source.code;
|
6763 | var ast = source.ast;
|
6764 |
|
6765 | return plugins.reduce( function ( promise, plugin ) {
|
6766 | return promise.then( function (previous) {
|
6767 | if ( !plugin.transform ) return previous;
|
6768 |
|
6769 | return Promise.resolve( plugin.transform( previous, id ) ).then( function (result) {
|
6770 | if ( result == null ) return previous;
|
6771 |
|
6772 | if ( typeof result === 'string' ) {
|
6773 | result = {
|
6774 | code: result,
|
6775 | ast: null,
|
6776 | map: null
|
6777 | };
|
6778 | }
|
6779 |
|
6780 | else if ( typeof result.map === 'string' ) {
|
6781 | result.map = JSON.parse( result.map );
|
6782 | }
|
6783 |
|
6784 | sourceMapChain.push( result.map || { missing: true, plugin: plugin.name });
|
6785 | ast = result.ast;
|
6786 |
|
6787 | return result.code;
|
6788 | });
|
6789 | }).catch( function (err) {
|
6790 | err.id = id;
|
6791 | err.plugin = plugin.name;
|
6792 | err.message = "Error transforming " + id + (plugin.name ? (" with '" + (plugin.name) + "' plugin") : '') + ": " + (err.message);
|
6793 | throw err;
|
6794 | });
|
6795 | }, Promise.resolve( source.code ) )
|
6796 |
|
6797 | .then( function (code) { return ({ code: code, originalCode: originalCode, originalSourceMap: originalSourceMap, ast: ast, sourceMapChain: sourceMapChain }); } );
|
6798 | }
|
6799 |
|
6800 | function transformBundle ( code, plugins, sourceMapChain ) {
|
6801 | return plugins.reduce( function ( code, plugin ) {
|
6802 | if ( !plugin.transformBundle ) return code;
|
6803 |
|
6804 | var result;
|
6805 |
|
6806 | try {
|
6807 | result = plugin.transformBundle( code );
|
6808 | } catch ( err ) {
|
6809 | err.plugin = plugin.name;
|
6810 | err.message = "Error transforming bundle" + (plugin.name ? (" with '" + (plugin.name) + "' plugin") : '') + ": " + (err.message);
|
6811 | throw err;
|
6812 | }
|
6813 |
|
6814 | if ( result == null ) return code;
|
6815 |
|
6816 | if ( typeof result === 'string' ) {
|
6817 | result = {
|
6818 | code: result,
|
6819 | map: null
|
6820 | };
|
6821 | }
|
6822 |
|
6823 | var map = typeof result.map === 'string' ? JSON.parse( result.map ) : result.map;
|
6824 | sourceMapChain.push( map );
|
6825 |
|
6826 | return result.code;
|
6827 | }, code );
|
6828 | }
|
6829 |
|
6830 | var charToInteger$1 = {};
|
6831 | var integerToChar$1 = {};
|
6832 |
|
6833 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
|
6834 | charToInteger$1[ char ] = i;
|
6835 | integerToChar$1[ i ] = char;
|
6836 | });
|
6837 |
|
6838 | function decode$1 ( string ) {
|
6839 | var result = [],
|
6840 | len = string.length,
|
6841 | i,
|
6842 | hasContinuationBit,
|
6843 | shift = 0,
|
6844 | value = 0,
|
6845 | integer,
|
6846 | shouldNegate;
|
6847 |
|
6848 | for ( i = 0; i < len; i += 1 ) {
|
6849 | integer = charToInteger$1[ string[i] ];
|
6850 |
|
6851 | if ( integer === undefined ) {
|
6852 | throw new Error( 'Invalid character (' + string[i] + ')' );
|
6853 | }
|
6854 |
|
6855 | hasContinuationBit = integer & 32;
|
6856 |
|
6857 | integer &= 31;
|
6858 | value += integer << shift;
|
6859 |
|
6860 | if ( hasContinuationBit ) {
|
6861 | shift += 5;
|
6862 | } else {
|
6863 | shouldNegate = value & 1;
|
6864 | value >>= 1;
|
6865 |
|
6866 | result.push( shouldNegate ? -value : value );
|
6867 |
|
6868 |
|
6869 | value = shift = 0;
|
6870 | }
|
6871 | }
|
6872 |
|
6873 | return result;
|
6874 | }
|
6875 |
|
6876 | function encode$1 ( value ) {
|
6877 | var result, i;
|
6878 |
|
6879 | if ( typeof value === 'number' ) {
|
6880 | result = encodeInteger$1( value );
|
6881 | } else {
|
6882 | result = '';
|
6883 | for ( i = 0; i < value.length; i += 1 ) {
|
6884 | result += encodeInteger$1( value[i] );
|
6885 | }
|
6886 | }
|
6887 |
|
6888 | return result;
|
6889 | }
|
6890 |
|
6891 | function encodeInteger$1 ( num ) {
|
6892 | var result = '', clamped;
|
6893 |
|
6894 | if ( num < 0 ) {
|
6895 | num = ( -num << 1 ) | 1;
|
6896 | } else {
|
6897 | num <<= 1;
|
6898 | }
|
6899 |
|
6900 | do {
|
6901 | clamped = num & 31;
|
6902 | num >>= 5;
|
6903 |
|
6904 | if ( num > 0 ) {
|
6905 | clamped |= 32;
|
6906 | }
|
6907 |
|
6908 | result += integerToChar$1[ clamped ];
|
6909 | } while ( num > 0 );
|
6910 |
|
6911 | return result;
|
6912 | }
|
6913 |
|
6914 | function decodeSegments(encodedSegments) {
|
6915 | var i = encodedSegments.length;
|
6916 | var segments = new Array(i);
|
6917 |
|
6918 | while (i--) {
|
6919 | segments[i] = decode$1(encodedSegments[i]);
|
6920 | }return segments;
|
6921 | }
|
6922 |
|
6923 | function decode$1$1(mappings) {
|
6924 | var sourceFileIndex = 0;
|
6925 | var sourceCodeLine = 0;
|
6926 | var sourceCodeColumn = 0;
|
6927 | var nameIndex = 0;
|
6928 |
|
6929 | var lines = mappings.split(';');
|
6930 | var numLines = lines.length;
|
6931 | var decoded = new Array(numLines);
|
6932 |
|
6933 | var i = undefined;
|
6934 | var j = undefined;
|
6935 | var line = undefined;
|
6936 | var generatedCodeColumn = undefined;
|
6937 | var decodedLine = undefined;
|
6938 | var segments = undefined;
|
6939 | var segment = undefined;
|
6940 | var result = undefined;
|
6941 |
|
6942 | for (i = 0; i < numLines; i += 1) {
|
6943 | line = lines[i];
|
6944 |
|
6945 | generatedCodeColumn = 0;
|
6946 | decodedLine = [];
|
6947 |
|
6948 | segments = decodeSegments(line.split(','));
|
6949 |
|
6950 | for (j = 0; j < segments.length; j += 1) {
|
6951 | segment = segments[j];
|
6952 |
|
6953 | if (!segment.length) {
|
6954 | break;
|
6955 | }
|
6956 |
|
6957 | generatedCodeColumn += segment[0];
|
6958 |
|
6959 | result = [generatedCodeColumn];
|
6960 | decodedLine.push(result);
|
6961 |
|
6962 | if (segment.length === 1) {
|
6963 |
|
6964 | continue;
|
6965 | }
|
6966 |
|
6967 | sourceFileIndex += segment[1];
|
6968 | sourceCodeLine += segment[2];
|
6969 | sourceCodeColumn += segment[3];
|
6970 |
|
6971 | result.push(sourceFileIndex, sourceCodeLine, sourceCodeColumn);
|
6972 |
|
6973 | if (segment.length === 5) {
|
6974 | nameIndex += segment[4];
|
6975 | result.push(nameIndex);
|
6976 | }
|
6977 | }
|
6978 |
|
6979 | decoded[i] = decodedLine;
|
6980 | }
|
6981 |
|
6982 | return decoded;
|
6983 | }
|
6984 |
|
6985 | function encode$1$1(decoded) {
|
6986 | var offsets = {
|
6987 | generatedCodeColumn: 0,
|
6988 | sourceFileIndex: 0,
|
6989 | sourceCodeLine: 0,
|
6990 | sourceCodeColumn: 0,
|
6991 | nameIndex: 0
|
6992 | };
|
6993 |
|
6994 | return decoded.map(function (line) {
|
6995 | offsets.generatedCodeColumn = 0;
|
6996 | return line.map(encodeSegment).join(',');
|
6997 | }).join(';');
|
6998 |
|
6999 | function encodeSegment(segment) {
|
7000 | if (!segment.length) {
|
7001 | return segment;
|
7002 | }
|
7003 |
|
7004 | var result = new Array(segment.length);
|
7005 |
|
7006 | result[0] = segment[0] - offsets.generatedCodeColumn;
|
7007 | offsets.generatedCodeColumn = segment[0];
|
7008 |
|
7009 | if (segment.length === 1) {
|
7010 |
|
7011 | return encode$1(result);
|
7012 | }
|
7013 |
|
7014 | result[1] = segment[1] - offsets.sourceFileIndex;
|
7015 | result[2] = segment[2] - offsets.sourceCodeLine;
|
7016 | result[3] = segment[3] - offsets.sourceCodeColumn;
|
7017 |
|
7018 | offsets.sourceFileIndex = segment[1];
|
7019 | offsets.sourceCodeLine = segment[2];
|
7020 | offsets.sourceCodeColumn = segment[3];
|
7021 |
|
7022 | if (segment.length === 5) {
|
7023 | result[4] = segment[4] - offsets.nameIndex;
|
7024 | offsets.nameIndex = segment[4];
|
7025 | }
|
7026 |
|
7027 | return encode$1(result);
|
7028 | }
|
7029 | }
|
7030 |
|
7031 | var Source = function Source ( filename, content ) {
|
7032 | this.isOriginal = true;
|
7033 | this.filename = filename;
|
7034 | this.content = content;
|
7035 | };
|
7036 |
|
7037 | Source.prototype.traceSegment = function traceSegment ( line, column, name ) {
|
7038 | return { line: line, column: column, name: name, source: this };
|
7039 | };
|
7040 |
|
7041 | var Link = function Link ( map, sources ) {
|
7042 | this.sources = sources;
|
7043 | this.names = map.names;
|
7044 | this.mappings = decode$1$1( map.mappings );
|
7045 | };
|
7046 |
|
7047 | Link.prototype.traceMappings = function traceMappings () {
|
7048 | var this$1 = this;
|
7049 |
|
7050 | var sources = [], sourcesContent = [], names = [];
|
7051 |
|
7052 | var mappings = this.mappings.map( function (line) {
|
7053 | var tracedLine = [];
|
7054 |
|
7055 | line.forEach( function (segment) {
|
7056 | var source = this$1.sources[ segment[1] ];
|
7057 | var traced = source.traceSegment( segment[2], segment[3], this$1.names[ segment[4] ] );
|
7058 |
|
7059 | if ( traced ) {
|
7060 | var sourceIndex = null, nameIndex = null;
|
7061 | segment = [
|
7062 | segment[0],
|
7063 | null,
|
7064 | traced.line,
|
7065 | traced.column
|
7066 | ];
|
7067 |
|
7068 |
|
7069 | sourceIndex = sources.lastIndexOf( traced.source.filename );
|
7070 | if ( sourceIndex === -1 ) {
|
7071 | sourceIndex = sources.length;
|
7072 | sources.push( traced.source.filename );
|
7073 | sourcesContent[ sourceIndex ] = traced.source.content;
|
7074 | } else if ( sourcesContent[ sourceIndex ] == null ) {
|
7075 | sourcesContent[ sourceIndex ] = traced.source.content;
|
7076 | } else if ( traced.source.content != null && sourcesContent[ sourceIndex ] !== traced.source.content ) {
|
7077 | throw new Error( ("Multiple conflicting contents for sourcemap source " + (source.filename)) );
|
7078 | }
|
7079 |
|
7080 | segment[1] = sourceIndex;
|
7081 |
|
7082 | if ( traced.name ) {
|
7083 | nameIndex = names.indexOf( traced.name );
|
7084 | if ( nameIndex === -1 ) {
|
7085 | nameIndex = names.length;
|
7086 | names.push( traced.name );
|
7087 | }
|
7088 |
|
7089 | segment[4] = nameIndex;
|
7090 | }
|
7091 |
|
7092 | tracedLine.push( segment );
|
7093 | }
|
7094 | });
|
7095 |
|
7096 | return tracedLine;
|
7097 | });
|
7098 |
|
7099 | return { sources: sources, sourcesContent: sourcesContent, names: names, mappings: mappings };
|
7100 | };
|
7101 |
|
7102 | Link.prototype.traceSegment = function traceSegment ( line, column, name ) {
|
7103 | var this$1 = this;
|
7104 |
|
7105 | var segments = this.mappings[ line ];
|
7106 |
|
7107 | if ( !segments ) return null;
|
7108 |
|
7109 | for ( var i = 0; i < segments.length; i += 1 ) {
|
7110 | var segment = segments[i];
|
7111 |
|
7112 | if ( segment[0] > column ) return null;
|
7113 |
|
7114 | if ( segment[0] === column ) {
|
7115 | var source = this$1.sources[ segment[1] ];
|
7116 | if ( !source ) return null;
|
7117 |
|
7118 | return source.traceSegment( segment[2], segment[3], this$1.names[ segment[4] ] || name );
|
7119 | }
|
7120 | }
|
7121 |
|
7122 | return null;
|
7123 | };
|
7124 |
|
7125 | function collapseSourcemaps ( file, map, modules, bundleSourcemapChain, onwarn ) {
|
7126 | var moduleSources = modules.filter( function (module) { return !module.excludeFromSourcemap; } ).map( function (module) {
|
7127 | var sourceMapChain = module.sourceMapChain;
|
7128 |
|
7129 | var source;
|
7130 | if ( module.originalSourceMap == null ) {
|
7131 | source = new Source( module.id, module.originalCode );
|
7132 | } else {
|
7133 | var sources = module.originalSourceMap.sources;
|
7134 | var sourcesContent = module.originalSourceMap.sourcesContent || [];
|
7135 |
|
7136 | if ( sources == null || ( sources.length <= 1 && sources[0] == null ) ) {
|
7137 | source = new Source( module.id, sourcesContent[0] );
|
7138 | sourceMapChain = [ module.originalSourceMap ].concat( sourceMapChain );
|
7139 | } else {
|
7140 |
|
7141 | var directory = dirname( module.id ) || '.';
|
7142 | var sourceRoot = module.originalSourceMap.sourceRoot || '.';
|
7143 |
|
7144 | var baseSources = sources.map( function (source, i) {
|
7145 | return new Source( resolve( directory, sourceRoot, source ), sourcesContent[i] );
|
7146 | });
|
7147 |
|
7148 | source = new Link( module.originalSourceMap, baseSources );
|
7149 | }
|
7150 | }
|
7151 |
|
7152 | sourceMapChain.forEach( function (map) {
|
7153 | if ( map.missing ) {
|
7154 | onwarn( ("Sourcemap is likely to be incorrect: a plugin" + (map.plugin ? (" ('" + (map.plugin) + "')") : "") + " was used to transform files, but didn't generate a sourcemap for the transformation. Consult https://github.com/rollup/rollup/wiki/Troubleshooting and the plugin documentation for more information") );
|
7155 |
|
7156 | map = {
|
7157 | names: [],
|
7158 | mappings: ''
|
7159 | };
|
7160 | }
|
7161 |
|
7162 | source = new Link( map, [ source ]);
|
7163 | });
|
7164 |
|
7165 | return source;
|
7166 | });
|
7167 |
|
7168 | var source = new Link( map, moduleSources );
|
7169 |
|
7170 | bundleSourcemapChain.forEach( function (map) {
|
7171 | source = new Link( map, [ source ] );
|
7172 | });
|
7173 |
|
7174 | var ref = source.traceMappings();
|
7175 | var sources = ref.sources;
|
7176 | var sourcesContent = ref.sourcesContent;
|
7177 | var names = ref.names;
|
7178 | var mappings = ref.mappings;
|
7179 |
|
7180 | if ( file ) {
|
7181 | var directory = dirname( file );
|
7182 | sources = sources.map( function (source) { return relative( directory, source ); } );
|
7183 | }
|
7184 |
|
7185 |
|
7186 | map.sources = sources;
|
7187 | map.sourcesContent = sourcesContent;
|
7188 | map.names = names;
|
7189 | map.mappings = encode$1$1( mappings );
|
7190 |
|
7191 | return map;
|
7192 | }
|
7193 |
|
7194 | function callIfFunction ( thing ) {
|
7195 | return typeof thing === 'function' ? thing() : thing;
|
7196 | }
|
7197 |
|
7198 | var Bundle = function Bundle ( options ) {
|
7199 | var this$1 = this;
|
7200 |
|
7201 | this.cachedModules = new Map();
|
7202 | if ( options.cache ) {
|
7203 | options.cache.modules.forEach( function (module) {
|
7204 | this$1.cachedModules.set( module.id, module );
|
7205 | });
|
7206 | }
|
7207 |
|
7208 | this.plugins = ensureArray( options.plugins );
|
7209 |
|
7210 | this.plugins.forEach( function (plugin) {
|
7211 | if ( plugin.options ) {
|
7212 | options = plugin.options( options ) || options;
|
7213 | }
|
7214 | });
|
7215 |
|
7216 | this.entry = unixizePath( options.entry );
|
7217 | this.entryId = null;
|
7218 | this.entryModule = null;
|
7219 |
|
7220 | this.treeshake = options.treeshake !== false;
|
7221 |
|
7222 | this.resolveId = first(
|
7223 | [ function (id) { return this$1.isExternal( id ) ? false : null; } ]
|
7224 | .concat( this.plugins.map( function (plugin) { return plugin.resolveId; } ).filter( Boolean ) )
|
7225 | .concat( resolveId )
|
7226 | );
|
7227 |
|
7228 | var loaders = this.plugins
|
7229 | .map( function (plugin) { return plugin.load; } )
|
7230 | .filter( Boolean );
|
7231 | this.hasLoaders = loaders.length !== 0;
|
7232 | this.load = first( loaders.concat( load ) );
|
7233 |
|
7234 | this.moduleById = new Map();
|
7235 | this.modules = [];
|
7236 |
|
7237 | this.externalModules = [];
|
7238 | this.internalNamespaces = [];
|
7239 |
|
7240 | this.assumedGlobals = blank();
|
7241 |
|
7242 | if ( typeof options.external === 'function' ) {
|
7243 | this.isExternal = options.external;
|
7244 | } else {
|
7245 | var ids = ensureArray( options.external ).map( function (id) { return id.replace( /[\/\\]/g, '/' ); } );
|
7246 | this.isExternal = function (id) { return ids.indexOf( id ) !== -1; };
|
7247 | }
|
7248 |
|
7249 | this.onwarn = options.onwarn || makeOnwarn();
|
7250 |
|
7251 |
|
7252 | [ 'module', 'exports', '_interopDefault' ].forEach( function (global) { return this$1.assumedGlobals[ global ] = true; } );
|
7253 |
|
7254 | this.varOrConst = options.preferConst ? 'const' : 'var';
|
7255 | this.acornOptions = options.acorn || {};
|
7256 | };
|
7257 |
|
7258 | Bundle.prototype.build = function build () {
|
7259 | var this$1 = this;
|
7260 |
|
7261 |
|
7262 |
|
7263 |
|
7264 | return this.resolveId( this.entry, undefined )
|
7265 | .then( function (id) {
|
7266 | this$1.entryId = id;
|
7267 | return this$1.fetchModule( id, undefined );
|
7268 | })
|
7269 | .then( function (entryModule) {
|
7270 | this$1.entryModule = entryModule;
|
7271 |
|
7272 |
|
7273 |
|
7274 | this$1.modules.forEach( function (module) { return module.bindImportSpecifiers(); } );
|
7275 | this$1.modules.forEach( function (module) { return module.bindAliases(); } );
|
7276 | this$1.modules.forEach( function (module) { return module.bindReferences(); } );
|
7277 |
|
7278 |
|
7279 |
|
7280 |
|
7281 |
|
7282 | entryModule.getExports().forEach( function (name) {
|
7283 | var declaration = entryModule.traceExport( name );
|
7284 | declaration.exportName = name;
|
7285 |
|
7286 | declaration.use();
|
7287 | });
|
7288 |
|
7289 |
|
7290 | var settled = false;
|
7291 | while ( !settled ) {
|
7292 | settled = true;
|
7293 |
|
7294 | this$1.modules.forEach( function (module) {
|
7295 | if ( module.run( this$1.treeshake ) ) settled = false;
|
7296 | });
|
7297 | }
|
7298 |
|
7299 |
|
7300 |
|
7301 |
|
7302 | this$1.orderedModules = this$1.sort();
|
7303 | this$1.deconflict();
|
7304 | });
|
7305 | };
|
7306 |
|
7307 | Bundle.prototype.deconflict = function deconflict () {
|
7308 | var used = blank();
|
7309 |
|
7310 |
|
7311 | keys( this.assumedGlobals ).forEach( function (name) { return used[ name ] = 1; } );
|
7312 |
|
7313 | function getSafeName ( name ) {
|
7314 | while ( used[ name ] ) {
|
7315 | name += "$" + (used[name]++);
|
7316 | }
|
7317 |
|
7318 | used[ name ] = 1;
|
7319 | return name;
|
7320 | }
|
7321 |
|
7322 | this.externalModules.forEach( function (module) {
|
7323 | module.name = getSafeName( module.name );
|
7324 |
|
7325 |
|
7326 |
|
7327 | forOwn( module.declarations, function ( declaration, name ) {
|
7328 | declaration.setSafeName( getSafeName( name ) );
|
7329 | });
|
7330 | });
|
7331 |
|
7332 | this.modules.forEach( function (module) {
|
7333 | forOwn( module.declarations, function ( declaration, originalName ) {
|
7334 | if ( declaration.isGlobal ) return;
|
7335 |
|
7336 | if ( originalName === 'default' ) {
|
7337 | if ( declaration.original && !declaration.original.isReassigned ) return;
|
7338 | }
|
7339 |
|
7340 | declaration.name = getSafeName( declaration.name );
|
7341 | });
|
7342 | });
|
7343 | };
|
7344 |
|
7345 | Bundle.prototype.fetchModule = function fetchModule ( id, importer ) {
|
7346 | var this$1 = this;
|
7347 |
|
7348 |
|
7349 | if ( this.moduleById.has( id ) ) return null;
|
7350 | this.moduleById.set( id, null );
|
7351 |
|
7352 | return this.load( id )
|
7353 | .catch( function (err) {
|
7354 | var msg = "Could not load " + id;
|
7355 | if ( importer ) msg += " (imported by " + importer + ")";
|
7356 |
|
7357 | msg += ": " + (err.message);
|
7358 | throw new Error( msg );
|
7359 | })
|
7360 | .then( function (source) {
|
7361 | if ( typeof source === 'string' ) return source;
|
7362 | if ( source && typeof source === 'object' && source.code ) return source;
|
7363 |
|
7364 | throw new Error( ("Error loading " + id + ": load hook should return a string, a { code, map } object, or nothing/null") );
|
7365 | })
|
7366 | .then( function (source) {
|
7367 | if ( typeof source === 'string' ) {
|
7368 | source = {
|
7369 | code: source,
|
7370 | ast: null
|
7371 | };
|
7372 | }
|
7373 |
|
7374 | if ( this$1.cachedModules.has( id ) && this$1.cachedModules.get( id ).originalCode === source.code ) {
|
7375 | return this$1.cachedModules.get( id );
|
7376 | }
|
7377 |
|
7378 | return transform( source, id, this$1.plugins );
|
7379 | })
|
7380 | .then( function (source) {
|
7381 | var code = source.code;
|
7382 | var originalCode = source.originalCode;
|
7383 | var originalSourceMap = source.originalSourceMap;
|
7384 | var ast = source.ast;
|
7385 | var sourceMapChain = source.sourceMapChain;
|
7386 |
|
7387 | var module = new Module({ id: id, code: code, originalCode: originalCode, originalSourceMap: originalSourceMap, ast: ast, sourceMapChain: sourceMapChain, bundle: this$1 });
|
7388 |
|
7389 | this$1.modules.push( module );
|
7390 | this$1.moduleById.set( id, module );
|
7391 |
|
7392 | return this$1.fetchAllDependencies( module ).then( function () {
|
7393 | module.exportsAll = blank();
|
7394 | keys( module.exports ).forEach( function (name) {
|
7395 | module.exportsAll[name] = module.id;
|
7396 | });
|
7397 | module.exportAllSources.forEach( function (source) {
|
7398 | var id = module.resolvedIds[ source ];
|
7399 | var exportAllModule = this$1.moduleById.get( id );
|
7400 | keys( exportAllModule.exportsAll ).forEach( function (name) {
|
7401 | if ( name in module.exportsAll ) {
|
7402 | this$1.onwarn( ("Conflicting namespaces: " + (module.id) + " re-exports '" + name + "' from both " + (module.exportsAll[ name ]) + " (will be ignored) and " + (exportAllModule.exportsAll[ name ]) + ".") );
|
7403 | }
|
7404 | module.exportsAll[ name ] = exportAllModule.exportsAll[ name ];
|
7405 | });
|
7406 | });
|
7407 | return module;
|
7408 | });
|
7409 | });
|
7410 | };
|
7411 |
|
7412 | Bundle.prototype.fetchAllDependencies = function fetchAllDependencies ( module ) {
|
7413 | var this$1 = this;
|
7414 |
|
7415 | return mapSequence( module.sources, function (source) {
|
7416 | return this$1.resolveId( source, module.id )
|
7417 | .then( function (resolvedId) {
|
7418 | var externalName;
|
7419 | if ( resolvedId ) {
|
7420 |
|
7421 | externalName = resolvedId.replace( /[\/\\]/g, '/' );
|
7422 | } else if ( isRelative( source ) ) {
|
7423 |
|
7424 | externalName = resolve( module.id, '..', source );
|
7425 | }
|
7426 | var forcedExternal = externalName && this$1.isExternal( externalName );
|
7427 |
|
7428 | if ( !resolvedId || forcedExternal ) {
|
7429 | var normalizedExternal = source;
|
7430 |
|
7431 | if ( !forcedExternal ) {
|
7432 | if ( isRelative( source ) ) throw new Error( ("Could not resolve " + source + " from " + (module.id)) );
|
7433 | if ( !this$1.isExternal( source ) ) this$1.onwarn( ("Treating '" + source + "' as external dependency") );
|
7434 | } else if ( resolvedId ) {
|
7435 | if ( isRelative(resolvedId) || isAbsolute(resolvedId) ) {
|
7436 |
|
7437 | normalizedExternal = this$1.getPathRelativeToEntryDirname( resolvedId );
|
7438 | } else {
|
7439 | normalizedExternal = resolvedId;
|
7440 | }
|
7441 | }
|
7442 | module.resolvedIds[ source ] = normalizedExternal;
|
7443 |
|
7444 | if ( !this$1.moduleById.has( normalizedExternal ) ) {
|
7445 | var module$1 = new ExternalModule( normalizedExternal );
|
7446 | this$1.externalModules.push( module$1 );
|
7447 | this$1.moduleById.set( normalizedExternal, module$1 );
|
7448 | }
|
7449 | }
|
7450 |
|
7451 | else {
|
7452 | if ( resolvedId === module.id ) {
|
7453 | throw new Error( ("A module cannot import itself (" + resolvedId + ")") );
|
7454 | }
|
7455 |
|
7456 | module.resolvedIds[ source ] = resolvedId;
|
7457 | return this$1.fetchModule( resolvedId, module.id );
|
7458 | }
|
7459 | });
|
7460 | });
|
7461 | };
|
7462 |
|
7463 | Bundle.prototype.getPathRelativeToEntryDirname = function getPathRelativeToEntryDirname ( resolvedId ) {
|
7464 |
|
7465 | var entryDirname = dirname( this.entryId );
|
7466 | var relativeToEntry = relative( entryDirname, resolvedId );
|
7467 |
|
7468 | if ( isRelative( relativeToEntry )) {
|
7469 | return relativeToEntry;
|
7470 | }
|
7471 |
|
7472 |
|
7473 | return ("./" + relativeToEntry);
|
7474 | };
|
7475 |
|
7476 | Bundle.prototype.render = function render ( options ) {
|
7477 | if ( options === void 0 ) options = {};
|
7478 |
|
7479 | if ( options.format === 'es6' ) {
|
7480 | this.onwarn( 'The es6 format is deprecated – use `es` instead' );
|
7481 | options.format = 'es';
|
7482 | }
|
7483 |
|
7484 | var format = options.format || 'es';
|
7485 |
|
7486 |
|
7487 | var exportMode = getExportMode( this, options.exports, options.moduleName );
|
7488 |
|
7489 | var magicString = new Bundle$1({ separator: '\n\n' });
|
7490 | var usedModules = [];
|
7491 |
|
7492 | this.orderedModules.forEach( function (module) {
|
7493 | var source = module.render( format === 'es' );
|
7494 | if ( source.toString().length ) {
|
7495 | magicString.addSource( source );
|
7496 | usedModules.push( module );
|
7497 | }
|
7498 | });
|
7499 |
|
7500 | var intro = [ options.intro ]
|
7501 | .concat(
|
7502 | this.plugins.map( function (plugin) { return plugin.intro && plugin.intro(); } )
|
7503 | )
|
7504 | .filter( Boolean )
|
7505 | .join( '\n\n' );
|
7506 |
|
7507 | if ( intro ) magicString.prepend( intro + '\n' );
|
7508 | if ( options.outro ) magicString.append( '\n' + options.outro );
|
7509 |
|
7510 | var indentString = getIndentString( magicString, options );
|
7511 |
|
7512 | var finalise = finalisers[ format ];
|
7513 | if ( !finalise ) throw new Error( ("You must specify an output type - valid options are " + (keys( finalisers ).join( ', ' ))) );
|
7514 |
|
7515 | magicString = finalise( this, magicString.trim(), { exportMode: exportMode, indentString: indentString }, options );
|
7516 |
|
7517 | var banner = [ options.banner ]
|
7518 | .concat( this.plugins.map( function (plugin) { return plugin.banner; } ) )
|
7519 | .map( callIfFunction )
|
7520 | .filter( Boolean )
|
7521 | .join( '\n' );
|
7522 |
|
7523 | var footer = [ options.footer ]
|
7524 | .concat( this.plugins.map( function (plugin) { return plugin.footer; } ) )
|
7525 | .map( callIfFunction )
|
7526 | .filter( Boolean )
|
7527 | .join( '\n' );
|
7528 |
|
7529 | if ( banner ) magicString.prepend( banner + '\n' );
|
7530 | if ( footer ) magicString.append( '\n' + footer );
|
7531 |
|
7532 | var code = magicString.toString();
|
7533 | var map = null;
|
7534 | var bundleSourcemapChain = [];
|
7535 |
|
7536 | code = transformBundle( code, this.plugins, bundleSourcemapChain )
|
7537 | .replace( new RegExp( ("\\/\\/#\\s+" + SOURCEMAPPING_URL$1 + "=.+\\n?"), 'g' ), '' );
|
7538 |
|
7539 | if ( options.sourceMap ) {
|
7540 | var file = options.sourceMapFile || options.dest;
|
7541 | if ( file ) file = resolve( typeof process !== 'undefined' ? process.cwd() : '', file );
|
7542 |
|
7543 | if ( this.hasLoaders || find( this.plugins, function (plugin) { return plugin.transform || plugin.transformBundle; } ) ) {
|
7544 | map = magicString.generateMap( {} );
|
7545 | map = collapseSourcemaps( file, map, usedModules, bundleSourcemapChain, this.onwarn );
|
7546 | } else {
|
7547 | map = magicString.generateMap({ file: file, includeContent: true });
|
7548 | }
|
7549 |
|
7550 | map.sources = map.sources.map( unixizePath );
|
7551 | }
|
7552 |
|
7553 | return { code: code, map: map };
|
7554 | };
|
7555 |
|
7556 | Bundle.prototype.sort = function sort () {
|
7557 | var this$1 = this;
|
7558 |
|
7559 | var seen = {};
|
7560 | var hasCycles;
|
7561 | var ordered = [];
|
7562 |
|
7563 | var stronglyDependsOn = blank();
|
7564 | var dependsOn = blank();
|
7565 |
|
7566 | this.modules.forEach( function (module) {
|
7567 | stronglyDependsOn[ module.id ] = blank();
|
7568 | dependsOn[ module.id ] = blank();
|
7569 | });
|
7570 |
|
7571 | this.modules.forEach( function (module) {
|
7572 | function processStrongDependency ( dependency ) {
|
7573 | if ( dependency === module || stronglyDependsOn[ module.id ][ dependency.id ] ) return;
|
7574 |
|
7575 | stronglyDependsOn[ module.id ][ dependency.id ] = true;
|
7576 | dependency.strongDependencies.forEach( processStrongDependency );
|
7577 | }
|
7578 |
|
7579 | function processDependency ( dependency ) {
|
7580 | if ( dependency === module || dependsOn[ module.id ][ dependency.id ] ) return;
|
7581 |
|
7582 | dependsOn[ module.id ][ dependency.id ] = true;
|
7583 | dependency.dependencies.forEach( processDependency );
|
7584 | }
|
7585 |
|
7586 | module.strongDependencies.forEach( processStrongDependency );
|
7587 | module.dependencies.forEach( processDependency );
|
7588 | });
|
7589 |
|
7590 | var visit = function (module) {
|
7591 | if ( seen[ module.id ] ) {
|
7592 | hasCycles = true;
|
7593 | return;
|
7594 | }
|
7595 |
|
7596 | seen[ module.id ] = true;
|
7597 |
|
7598 | module.dependencies.forEach( visit );
|
7599 | ordered.push( module );
|
7600 | };
|
7601 |
|
7602 | visit( this.entryModule );
|
7603 |
|
7604 | if ( hasCycles ) {
|
7605 | ordered.forEach( function ( a, i ) {
|
7606 | var loop = function ( ) {
|
7607 | var b = ordered[i];
|
7608 |
|
7609 | if ( stronglyDependsOn[ a.id ][ b.id ] ) {
|
7610 |
|
7611 |
|
7612 |
|
7613 | var parent = '[[unknown]]';
|
7614 |
|
7615 | var findParent = function (module) {
|
7616 | if ( dependsOn[ module.id ][ a.id ] && dependsOn[ module.id ][ b.id ] ) {
|
7617 | parent = module.id;
|
7618 | } else {
|
7619 | for ( var i = 0; i < module.dependencies.length; i += 1 ) {
|
7620 | var dependency = module.dependencies[i];
|
7621 | if ( findParent( dependency ) ) return;
|
7622 | }
|
7623 | }
|
7624 | };
|
7625 |
|
7626 | findParent( this$1.entryModule );
|
7627 |
|
7628 | this$1.onwarn(
|
7629 | ("Module " + (a.id) + " may be unable to evaluate without " + (b.id) + ", but is included first due to a cyclical dependency. Consider swapping the import statements in " + parent + " to ensure correct ordering")
|
7630 | );
|
7631 | }
|
7632 | };
|
7633 |
|
7634 | for ( i += 1; i < ordered.length; i += 1 ) loop( );
|
7635 | });
|
7636 | }
|
7637 |
|
7638 | return ordered;
|
7639 | };
|
7640 |
|
7641 | var VERSION = '0.33.2';
|
7642 |
|
7643 | var ALLOWED_KEYS = [
|
7644 | 'acorn',
|
7645 | 'banner',
|
7646 | 'cache',
|
7647 | 'dest',
|
7648 | 'entry',
|
7649 | 'exports',
|
7650 | 'external',
|
7651 | 'footer',
|
7652 | 'format',
|
7653 | 'globals',
|
7654 | 'indent',
|
7655 | 'intro',
|
7656 | 'moduleId',
|
7657 | 'moduleName',
|
7658 | 'noConflict',
|
7659 | 'onwarn',
|
7660 | 'outro',
|
7661 | 'plugins',
|
7662 | 'preferConst',
|
7663 | 'sourceMap',
|
7664 | 'sourceMapFile',
|
7665 | 'targets',
|
7666 | 'treeshake',
|
7667 | 'useStrict'
|
7668 | ];
|
7669 |
|
7670 | function rollup ( options ) {
|
7671 | if ( !options || !options.entry ) {
|
7672 | return Promise.reject( new Error( 'You must supply options.entry to rollup' ) );
|
7673 | }
|
7674 |
|
7675 | if ( options.transform || options.load || options.resolveId || options.resolveExternal ) {
|
7676 | return Promise.reject( new Error( 'The `transform`, `load`, `resolveId` and `resolveExternal` options are deprecated in favour of a unified plugin API. See https://github.com/rollup/rollup/wiki/Plugins for details' ) );
|
7677 | }
|
7678 |
|
7679 | var error = validateKeys( options, ALLOWED_KEYS );
|
7680 |
|
7681 | if ( error ) {
|
7682 | return Promise.reject( error );
|
7683 | }
|
7684 |
|
7685 | var bundle = new Bundle( options );
|
7686 |
|
7687 | return bundle.build().then( function () {
|
7688 | function generate ( options ) {
|
7689 | var rendered = bundle.render( options );
|
7690 |
|
7691 | bundle.plugins.forEach( function (plugin) {
|
7692 | if ( plugin.ongenerate ) {
|
7693 | plugin.ongenerate( assign({
|
7694 | bundle: result
|
7695 | }, options ), rendered);
|
7696 | }
|
7697 | });
|
7698 |
|
7699 | return rendered;
|
7700 | }
|
7701 |
|
7702 | var result = {
|
7703 | imports: bundle.externalModules.map( function (module) { return module.id; } ),
|
7704 | exports: keys( bundle.entryModule.exports ),
|
7705 | modules: bundle.orderedModules.map( function (module) { return module.toJSON(); } ),
|
7706 |
|
7707 | generate: generate,
|
7708 | write: function (options) {
|
7709 | if ( !options || !options.dest ) {
|
7710 | throw new Error( 'You must supply options.dest to bundle.write' );
|
7711 | }
|
7712 |
|
7713 | var dest = options.dest;
|
7714 | var output = generate( options );
|
7715 | var code = output.code;
|
7716 | var map = output.map;
|
7717 |
|
7718 | var promises = [];
|
7719 |
|
7720 | if ( options.sourceMap ) {
|
7721 | var url;
|
7722 |
|
7723 | if ( options.sourceMap === 'inline' ) {
|
7724 | url = map.toUrl();
|
7725 | } else {
|
7726 | url = (basename( dest )) + ".map";
|
7727 | promises.push( writeFile( dest + '.map', map.toString() ) );
|
7728 | }
|
7729 |
|
7730 | code += "\n//# " + SOURCEMAPPING_URL$1 + "=" + url;
|
7731 | }
|
7732 |
|
7733 | promises.push( writeFile( dest, code ) );
|
7734 | return Promise.all( promises ).then( function () {
|
7735 | return mapSequence( bundle.plugins.filter( function (plugin) { return plugin.onwrite; } ), function (plugin) {
|
7736 | return Promise.resolve( plugin.onwrite( assign({
|
7737 | bundle: result
|
7738 | }, options ), output));
|
7739 | });
|
7740 | });
|
7741 | }
|
7742 | };
|
7743 |
|
7744 | return result;
|
7745 | });
|
7746 | }
|
7747 |
|
7748 | export { VERSION, rollup };
|
7749 |
|
\ | No newline at end of file |