UNPKG

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