1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | (function (global, factory) {
|
12 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
13 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
14 | (factory((global.rollup = {})));
|
15 | }(this, (function (exports) { 'use strict';
|
16 |
|
17 | var DEBUG = false;
|
18 | var map = new Map;
|
19 |
|
20 | var timeStartHelper;
|
21 | var timeEndHelper;
|
22 |
|
23 | if ( typeof process === 'undefined' || typeof process.hrtime === 'undefined' ) {
|
24 | timeStartHelper = function timeStartHelper () {
|
25 | return window.performance.now();
|
26 | };
|
27 |
|
28 | timeEndHelper = function timeEndHelper ( previous ) {
|
29 | return window.performance.now() - previous;
|
30 | };
|
31 | } else {
|
32 | timeStartHelper = function timeStartHelper () {
|
33 | return process.hrtime();
|
34 | };
|
35 |
|
36 | timeEndHelper = function timeEndHelper ( previous ) {
|
37 | var hrtime = process.hrtime( previous );
|
38 | return hrtime[0] * 1e3 + Math.floor( hrtime[1] / 1e6 );
|
39 | };
|
40 | }
|
41 |
|
42 | function timeStart ( label ) {
|
43 | if ( !map.has( label ) ) {
|
44 | map.set( label, {
|
45 | time: 0
|
46 | });
|
47 | }
|
48 | map.get( label ).start = timeStartHelper();
|
49 | }
|
50 |
|
51 | function timeEnd ( label ) {
|
52 | if ( map.has( label ) ) {
|
53 | var item = map.get( label );
|
54 | item.time += timeEndHelper( item.start );
|
55 | }
|
56 | }
|
57 |
|
58 | function flushTime ( log ) {
|
59 | if ( log === void 0 ) log = defaultLog;
|
60 |
|
61 | for ( var item of map.entries() ) {
|
62 | log( item[0], item[1].time );
|
63 | }
|
64 | map.clear();
|
65 | }
|
66 |
|
67 | function defaultLog ( label, time ) {
|
68 | if ( DEBUG ) {
|
69 |
|
70 | console.info( '%dms: %s', time, label );
|
71 |
|
72 | }
|
73 | }
|
74 |
|
75 | var absolutePath = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/;
|
76 | var relativePath = /^\.?\.\//;
|
77 |
|
78 | function isAbsolute ( path ) {
|
79 | return absolutePath.test( path );
|
80 | }
|
81 |
|
82 | function isRelative ( path ) {
|
83 | return relativePath.test( path );
|
84 | }
|
85 |
|
86 | function normalize ( path ) {
|
87 | return path.replace( /\\/g, '/' );
|
88 | }
|
89 |
|
90 | function basename ( path ) {
|
91 | return path.split( /(\/|\\)/ ).pop();
|
92 | }
|
93 |
|
94 | function dirname ( path ) {
|
95 | var match = /(\/|\\)[^/\\]*$/.exec( path );
|
96 | if ( !match ) { return '.'; }
|
97 |
|
98 | var dir = path.slice( 0, -match[0].length );
|
99 |
|
100 |
|
101 | return dir ? dir : '/';
|
102 | }
|
103 |
|
104 | function extname ( path ) {
|
105 | var match = /\.[^.]+$/.exec( basename( path ) );
|
106 | if ( !match ) { return ''; }
|
107 | return match[0];
|
108 | }
|
109 |
|
110 | function relative ( from, to ) {
|
111 | var fromParts = from.split( /[/\\]/ ).filter( Boolean );
|
112 | var toParts = to.split( /[/\\]/ ).filter( Boolean );
|
113 |
|
114 | while ( fromParts[0] && toParts[0] && fromParts[0] === toParts[0] ) {
|
115 | fromParts.shift();
|
116 | toParts.shift();
|
117 | }
|
118 |
|
119 | while ( toParts[0] === '.' || toParts[0] === '..' ) {
|
120 | var toPart = toParts.shift();
|
121 | if ( toPart === '..' ) {
|
122 | fromParts.pop();
|
123 | }
|
124 | }
|
125 |
|
126 | while ( fromParts.pop() ) {
|
127 | toParts.unshift( '..' );
|
128 | }
|
129 |
|
130 | return toParts.join( '/' );
|
131 | }
|
132 |
|
133 | function resolve () {
|
134 | var paths = [], len = arguments.length;
|
135 | while ( len-- ) paths[ len ] = arguments[ len ];
|
136 |
|
137 | var resolvedParts = paths.shift().split( /[/\\]/ );
|
138 |
|
139 | paths.forEach( function (path) {
|
140 | if ( isAbsolute( path ) ) {
|
141 | resolvedParts = path.split( /[/\\]/ );
|
142 | } else {
|
143 | var parts = path.split( /[/\\]/ );
|
144 |
|
145 | while ( parts[0] === '.' || parts[0] === '..' ) {
|
146 | var part = parts.shift();
|
147 | if ( part === '..' ) {
|
148 | resolvedParts.pop();
|
149 | }
|
150 | }
|
151 |
|
152 | resolvedParts.push.apply( resolvedParts, parts );
|
153 | }
|
154 | });
|
155 |
|
156 | return resolvedParts.join( '/' );
|
157 | }
|
158 |
|
159 | var nope = function (method) { return ("Cannot use fs." + method + " inside browser"); };
|
160 |
|
161 | var lstatSync = nope( 'lstatSync' );
|
162 | var readdirSync = nope( 'readdirSync' );
|
163 | var readFileSync = nope( 'readFileSync' );
|
164 | var realpathSync = nope( 'realpathSync' );
|
165 | var writeFile = nope( 'writeFile' );
|
166 |
|
167 | var keys = Object.keys;
|
168 |
|
169 | function blank () {
|
170 | return Object.create( null );
|
171 | }
|
172 |
|
173 | function forOwn ( object, func ) {
|
174 | Object.keys( object ).forEach( function (key) { return func( object[ key ], key ); } );
|
175 | }
|
176 |
|
177 | function assign ( target ) {
|
178 | var sources = [], len = arguments.length - 1;
|
179 | while ( len-- > 0 ) sources[ len ] = arguments[ len + 1 ];
|
180 |
|
181 | sources.forEach( function (source) {
|
182 | for ( var key in source ) {
|
183 | if ( source.hasOwnProperty( key ) ) { target[ key ] = source[ key ]; }
|
184 | }
|
185 | });
|
186 |
|
187 | return target;
|
188 | }
|
189 |
|
190 | function mapSequence ( array, fn ) {
|
191 | var results = [];
|
192 | var promise = Promise.resolve();
|
193 |
|
194 | function next ( member, i ) {
|
195 | return fn( member ).then( function (value) { return results[i] = value; } );
|
196 | }
|
197 |
|
198 | var loop = function ( i ) {
|
199 | promise = promise.then( function () { return next( array[i], i ); } );
|
200 | };
|
201 |
|
202 | for ( var i = 0; i < array.length; i += 1 ) loop( i );
|
203 |
|
204 | return promise.then( function () { return results; } );
|
205 | }
|
206 |
|
207 | function validateKeys ( actualKeys, allowedKeys ) {
|
208 | var i = actualKeys.length;
|
209 |
|
210 | while ( i-- ) {
|
211 | var key = actualKeys[i];
|
212 |
|
213 | if ( allowedKeys.indexOf( key ) === -1 ) {
|
214 | return new Error(
|
215 | ("Unexpected key '" + key + "' found, expected one of: " + (allowedKeys.join( ', ' )))
|
216 | );
|
217 | }
|
218 | }
|
219 | }
|
220 |
|
221 | function error ( props ) {
|
222 |
|
223 |
|
224 |
|
225 |
|
226 |
|
227 | var constructor = (props instanceof Error) ? props.constructor : Error;
|
228 | var err = new constructor( props.message );
|
229 |
|
230 | Object.keys( props ).forEach( function (key) {
|
231 | err[ key ] = props[ key ];
|
232 | });
|
233 |
|
234 | throw err;
|
235 | }
|
236 |
|
237 |
|
238 |
|
239 | var SOURCEMAPPING_URL = 'sourceMa';
|
240 | SOURCEMAPPING_URL += 'ppingURL';
|
241 |
|
242 | var SOURCEMAPPING_URL_RE = new RegExp( ("^#\\s+" + SOURCEMAPPING_URL + "=.+\\n?") );
|
243 |
|
244 | var charToInteger = {};
|
245 | var integerToChar = {};
|
246 |
|
247 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
|
248 | charToInteger[ char ] = i;
|
249 | integerToChar[ i ] = char;
|
250 | });
|
251 |
|
252 | function decode$1 ( string ) {
|
253 | var result = [],
|
254 | len = string.length,
|
255 | i,
|
256 | hasContinuationBit,
|
257 | shift = 0,
|
258 | value = 0,
|
259 | integer,
|
260 | shouldNegate;
|
261 |
|
262 | for ( i = 0; i < len; i += 1 ) {
|
263 | integer = charToInteger[ string[i] ];
|
264 |
|
265 | if ( integer === undefined ) {
|
266 | throw new Error( 'Invalid character (' + string[i] + ')' );
|
267 | }
|
268 |
|
269 | hasContinuationBit = integer & 32;
|
270 |
|
271 | integer &= 31;
|
272 | value += integer << shift;
|
273 |
|
274 | if ( hasContinuationBit ) {
|
275 | shift += 5;
|
276 | } else {
|
277 | shouldNegate = value & 1;
|
278 | value >>= 1;
|
279 |
|
280 | result.push( shouldNegate ? -value : value );
|
281 |
|
282 |
|
283 | value = shift = 0;
|
284 | }
|
285 | }
|
286 |
|
287 | return result;
|
288 | }
|
289 |
|
290 | function encode$1 ( value ) {
|
291 | var result, i;
|
292 |
|
293 | if ( typeof value === 'number' ) {
|
294 | result = encodeInteger( value );
|
295 | } else {
|
296 | result = '';
|
297 | for ( i = 0; i < value.length; i += 1 ) {
|
298 | result += encodeInteger( value[i] );
|
299 | }
|
300 | }
|
301 |
|
302 | return result;
|
303 | }
|
304 |
|
305 | function encodeInteger ( num ) {
|
306 | var result = '', clamped;
|
307 |
|
308 | if ( num < 0 ) {
|
309 | num = ( -num << 1 ) | 1;
|
310 | } else {
|
311 | num <<= 1;
|
312 | }
|
313 |
|
314 | do {
|
315 | clamped = num & 31;
|
316 | num >>= 5;
|
317 |
|
318 | if ( num > 0 ) {
|
319 | clamped |= 32;
|
320 | }
|
321 |
|
322 | result += integerToChar[ clamped ];
|
323 | } while ( num > 0 );
|
324 |
|
325 | return result;
|
326 | }
|
327 |
|
328 | function decodeSegments ( encodedSegments ) {
|
329 | var i = encodedSegments.length;
|
330 | var segments = new Array( i );
|
331 |
|
332 | while ( i-- ) { segments[i] = decode$1( encodedSegments[i] ); }
|
333 | return segments;
|
334 | }
|
335 |
|
336 | function decode$$1 ( mappings ) {
|
337 | var sourceFileIndex = 0;
|
338 | var sourceCodeLine = 0;
|
339 | var sourceCodeColumn = 0;
|
340 | var nameIndex = 0;
|
341 |
|
342 | var lines = mappings.split( ';' );
|
343 | var numLines = lines.length;
|
344 | var decoded = new Array( numLines );
|
345 |
|
346 | var i;
|
347 | var j;
|
348 | var line;
|
349 | var generatedCodeColumn;
|
350 | var decodedLine;
|
351 | var segments;
|
352 | var segment;
|
353 | var result;
|
354 |
|
355 | for ( i = 0; i < numLines; i += 1 ) {
|
356 | line = lines[i];
|
357 |
|
358 | generatedCodeColumn = 0;
|
359 | decodedLine = [];
|
360 |
|
361 | segments = decodeSegments( line.split( ',' ) );
|
362 |
|
363 | for ( j = 0; j < segments.length; j += 1 ) {
|
364 | segment = segments[j];
|
365 |
|
366 | if ( !segment.length ) {
|
367 | break;
|
368 | }
|
369 |
|
370 | generatedCodeColumn += segment[0];
|
371 |
|
372 | result = [ generatedCodeColumn ];
|
373 | decodedLine.push( result );
|
374 |
|
375 | if ( segment.length === 1 ) {
|
376 |
|
377 | continue;
|
378 | }
|
379 |
|
380 | sourceFileIndex += segment[1];
|
381 | sourceCodeLine += segment[2];
|
382 | sourceCodeColumn += segment[3];
|
383 |
|
384 | result.push( sourceFileIndex, sourceCodeLine, sourceCodeColumn );
|
385 |
|
386 | if ( segment.length === 5 ) {
|
387 | nameIndex += segment[4];
|
388 | result.push( nameIndex );
|
389 | }
|
390 | }
|
391 |
|
392 | decoded[i] = decodedLine;
|
393 | }
|
394 |
|
395 | return decoded;
|
396 | }
|
397 |
|
398 | function encode$$1 ( decoded ) {
|
399 | var offsets = {
|
400 | generatedCodeColumn: 0,
|
401 | sourceFileIndex: 0,
|
402 | sourceCodeLine: 0,
|
403 | sourceCodeColumn: 0,
|
404 | nameIndex: 0
|
405 | };
|
406 |
|
407 | return decoded.map( function (line) {
|
408 | offsets.generatedCodeColumn = 0;
|
409 | return line.map( encodeSegment ).join( ',' );
|
410 | }).join( ';' );
|
411 |
|
412 | function encodeSegment ( segment ) {
|
413 | if ( !segment.length ) {
|
414 | return segment;
|
415 | }
|
416 |
|
417 | var result = new Array( segment.length );
|
418 |
|
419 | result[0] = segment[0] - offsets.generatedCodeColumn;
|
420 | offsets.generatedCodeColumn = segment[0];
|
421 |
|
422 | if ( segment.length === 1 ) {
|
423 |
|
424 | return encode$1( result );
|
425 | }
|
426 |
|
427 | result[1] = segment[1] - offsets.sourceFileIndex;
|
428 | result[2] = segment[2] - offsets.sourceCodeLine;
|
429 | result[3] = segment[3] - offsets.sourceCodeColumn;
|
430 |
|
431 | offsets.sourceFileIndex = segment[1];
|
432 | offsets.sourceCodeLine = segment[2];
|
433 | offsets.sourceCodeColumn = segment[3];
|
434 |
|
435 | if ( segment.length === 5 ) {
|
436 | result[4] = segment[4] - offsets.nameIndex;
|
437 | offsets.nameIndex = segment[4];
|
438 | }
|
439 |
|
440 | return encode$1( result );
|
441 | }
|
442 | }
|
443 |
|
444 | var charToInteger$1 = {};
|
445 | var integerToChar$1 = {};
|
446 |
|
447 | 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='.split( '' ).forEach( function ( char, i ) {
|
448 | charToInteger$1[ char ] = i;
|
449 | integerToChar$1[ i ] = char;
|
450 | });
|
451 |
|
452 |
|
453 |
|
454 | function encode ( value ) {
|
455 | var result;
|
456 |
|
457 | if ( typeof value === 'number' ) {
|
458 | result = encodeInteger$1( value );
|
459 | } else {
|
460 | result = '';
|
461 | for ( var i = 0; i < value.length; i += 1 ) {
|
462 | result += encodeInteger$1( value[i] );
|
463 | }
|
464 | }
|
465 |
|
466 | return result;
|
467 | }
|
468 |
|
469 | function encodeInteger$1 ( num ) {
|
470 | var result = '';
|
471 |
|
472 | if ( num < 0 ) {
|
473 | num = ( -num << 1 ) | 1;
|
474 | } else {
|
475 | num <<= 1;
|
476 | }
|
477 |
|
478 | do {
|
479 | var clamped = num & 31;
|
480 | num >>= 5;
|
481 |
|
482 | if ( num > 0 ) {
|
483 | clamped |= 32;
|
484 | }
|
485 |
|
486 | result += integerToChar$1[ clamped ];
|
487 | } while ( num > 0 );
|
488 |
|
489 | return result;
|
490 | }
|
491 |
|
492 | function Chunk ( start, end, content ) {
|
493 | this.start = start;
|
494 | this.end = end;
|
495 | this.original = content;
|
496 |
|
497 | this.intro = '';
|
498 | this.outro = '';
|
499 |
|
500 | this.content = content;
|
501 | this.storeName = false;
|
502 | this.edited = false;
|
503 |
|
504 |
|
505 | Object.defineProperties( this, {
|
506 | previous: { writable: true, value: null },
|
507 | next: { writable: true, value: null }
|
508 | });
|
509 | }
|
510 |
|
511 | Chunk.prototype = {
|
512 | appendLeft: function appendLeft ( content ) {
|
513 | this.outro += content;
|
514 | },
|
515 |
|
516 | appendRight: function appendRight ( content ) {
|
517 | this.intro = this.intro + content;
|
518 | },
|
519 |
|
520 | clone: function clone () {
|
521 | var chunk = new Chunk( this.start, this.end, this.original );
|
522 |
|
523 | chunk.intro = this.intro;
|
524 | chunk.outro = this.outro;
|
525 | chunk.content = this.content;
|
526 | chunk.storeName = this.storeName;
|
527 | chunk.edited = this.edited;
|
528 |
|
529 | return chunk;
|
530 | },
|
531 |
|
532 | contains: function contains ( index ) {
|
533 | return this.start < index && index < this.end;
|
534 | },
|
535 |
|
536 | eachNext: function eachNext ( fn ) {
|
537 | var chunk = this;
|
538 | while ( chunk ) {
|
539 | fn( chunk );
|
540 | chunk = chunk.next;
|
541 | }
|
542 | },
|
543 |
|
544 | eachPrevious: function eachPrevious ( fn ) {
|
545 | var chunk = this;
|
546 | while ( chunk ) {
|
547 | fn( chunk );
|
548 | chunk = chunk.previous;
|
549 | }
|
550 | },
|
551 |
|
552 | edit: function edit ( content, storeName, contentOnly ) {
|
553 | this.content = content;
|
554 | if ( !contentOnly ) {
|
555 | this.intro = '';
|
556 | this.outro = '';
|
557 | }
|
558 | this.storeName = storeName;
|
559 |
|
560 | this.edited = true;
|
561 |
|
562 | return this;
|
563 | },
|
564 |
|
565 | prependLeft: function prependLeft ( content ) {
|
566 | this.outro = content + this.outro;
|
567 | },
|
568 |
|
569 | prependRight: function prependRight ( content ) {
|
570 | this.intro = content + this.intro;
|
571 | },
|
572 |
|
573 | split: function split ( index ) {
|
574 | var sliceIndex = index - this.start;
|
575 |
|
576 | var originalBefore = this.original.slice( 0, sliceIndex );
|
577 | var originalAfter = this.original.slice( sliceIndex );
|
578 |
|
579 | this.original = originalBefore;
|
580 |
|
581 | var newChunk = new Chunk( index, this.end, originalAfter );
|
582 | newChunk.outro = this.outro;
|
583 | this.outro = '';
|
584 |
|
585 | this.end = index;
|
586 |
|
587 | if ( this.edited ) {
|
588 |
|
589 | newChunk.edit( '', false );
|
590 | this.content = '';
|
591 | } else {
|
592 | this.content = originalBefore;
|
593 | }
|
594 |
|
595 | newChunk.next = this.next;
|
596 | if ( newChunk.next ) { newChunk.next.previous = newChunk; }
|
597 | newChunk.previous = this;
|
598 | this.next = newChunk;
|
599 |
|
600 | return newChunk;
|
601 | },
|
602 |
|
603 | toString: function toString () {
|
604 | return this.intro + this.content + this.outro;
|
605 | },
|
606 |
|
607 | trimEnd: function trimEnd ( rx ) {
|
608 | this.outro = this.outro.replace( rx, '' );
|
609 | if ( this.outro.length ) { return true; }
|
610 |
|
611 | var trimmed = this.content.replace( rx, '' );
|
612 |
|
613 | if ( trimmed.length ) {
|
614 | if ( trimmed !== this.content ) {
|
615 | this.split( this.start + trimmed.length ).edit( '', false );
|
616 | }
|
617 |
|
618 | return true;
|
619 | } else {
|
620 | this.edit( '', false );
|
621 |
|
622 | this.intro = this.intro.replace( rx, '' );
|
623 | if ( this.intro.length ) { return true; }
|
624 | }
|
625 | },
|
626 |
|
627 | trimStart: function trimStart ( rx ) {
|
628 | this.intro = this.intro.replace( rx, '' );
|
629 | if ( this.intro.length ) { return true; }
|
630 |
|
631 | var trimmed = this.content.replace( rx, '' );
|
632 |
|
633 | if ( trimmed.length ) {
|
634 | if ( trimmed !== this.content ) {
|
635 | this.split( this.end - trimmed.length );
|
636 | this.edit( '', false );
|
637 | }
|
638 |
|
639 | return true;
|
640 | } else {
|
641 | this.edit( '', false );
|
642 |
|
643 | this.outro = this.outro.replace( rx, '' );
|
644 | if ( this.outro.length ) { return true; }
|
645 | }
|
646 | }
|
647 | };
|
648 |
|
649 | var _btoa;
|
650 |
|
651 | if ( typeof window !== 'undefined' && typeof window.btoa === 'function' ) {
|
652 | _btoa = window.btoa;
|
653 | } else if ( typeof Buffer === 'function' ) {
|
654 | _btoa = function (str) { return new Buffer( str ).toString( 'base64' ); };
|
655 | } else {
|
656 | _btoa = function () {
|
657 | throw new Error( 'Unsupported environment: `window.btoa` or `Buffer` should be supported.' );
|
658 | };
|
659 | }
|
660 |
|
661 | var btoa = _btoa;
|
662 |
|
663 | function SourceMap ( properties ) {
|
664 | this.version = 3;
|
665 |
|
666 | this.file = properties.file;
|
667 | this.sources = properties.sources;
|
668 | this.sourcesContent = properties.sourcesContent;
|
669 | this.names = properties.names;
|
670 | this.mappings = properties.mappings;
|
671 | }
|
672 |
|
673 | SourceMap.prototype = {
|
674 | toString: function toString () {
|
675 | return JSON.stringify( this );
|
676 | },
|
677 |
|
678 | toUrl: function toUrl () {
|
679 | return 'data:application/json;charset=utf-8;base64,' + btoa( this.toString() );
|
680 | }
|
681 | };
|
682 |
|
683 | function guessIndent ( code ) {
|
684 | var lines = code.split( '\n' );
|
685 |
|
686 | var tabbed = lines.filter( function (line) { return /^\t+/.test( line ); } );
|
687 | var spaced = lines.filter( function (line) { return /^ {2,}/.test( line ); } );
|
688 |
|
689 | if ( tabbed.length === 0 && spaced.length === 0 ) {
|
690 | return null;
|
691 | }
|
692 |
|
693 |
|
694 |
|
695 |
|
696 | if ( tabbed.length >= spaced.length ) {
|
697 | return '\t';
|
698 | }
|
699 |
|
700 |
|
701 | var min = spaced.reduce( function ( previous, current ) {
|
702 | var numSpaces = /^ +/.exec( current )[0].length;
|
703 | return Math.min( numSpaces, previous );
|
704 | }, Infinity );
|
705 |
|
706 | return new Array( min + 1 ).join( ' ' );
|
707 | }
|
708 |
|
709 | function getRelativePath ( from, to ) {
|
710 | var fromParts = from.split( /[\/\\]/ );
|
711 | var toParts = to.split( /[\/\\]/ );
|
712 |
|
713 | fromParts.pop();
|
714 |
|
715 | while ( fromParts[0] === toParts[0] ) {
|
716 | fromParts.shift();
|
717 | toParts.shift();
|
718 | }
|
719 |
|
720 | if ( fromParts.length ) {
|
721 | var i = fromParts.length;
|
722 | while ( i-- ) { fromParts[i] = '..'; }
|
723 | }
|
724 |
|
725 | return fromParts.concat( toParts ).join( '/' );
|
726 | }
|
727 |
|
728 | var toString$1 = Object.prototype.toString;
|
729 |
|
730 | function isObject ( thing ) {
|
731 | return toString$1.call( thing ) === '[object Object]';
|
732 | }
|
733 |
|
734 | function getLocator ( source ) {
|
735 | var originalLines = source.split( '\n' );
|
736 |
|
737 | var start = 0;
|
738 | var lineRanges = originalLines.map( function ( line, i ) {
|
739 | var end = start + line.length + 1;
|
740 | var range = { start: start, end: end, line: i };
|
741 |
|
742 | start = end;
|
743 | return range;
|
744 | });
|
745 |
|
746 | var i = 0;
|
747 |
|
748 | function rangeContains ( range, index ) {
|
749 | return range.start <= index && index < range.end;
|
750 | }
|
751 |
|
752 | function getLocation ( range, index ) {
|
753 | return { line: range.line, column: index - range.start };
|
754 | }
|
755 |
|
756 | return function locate ( index ) {
|
757 | var range = lineRanges[i];
|
758 |
|
759 | var d = index >= range.end ? 1 : -1;
|
760 |
|
761 | while ( range ) {
|
762 | if ( rangeContains( range, index ) ) { return getLocation( range, index ); }
|
763 |
|
764 | i += d;
|
765 | range = lineRanges[i];
|
766 | }
|
767 | };
|
768 | }
|
769 |
|
770 | function Mappings ( hires ) {
|
771 | var this$1 = this;
|
772 |
|
773 | var offsets = {
|
774 | generatedCodeColumn: 0,
|
775 | sourceIndex: 0,
|
776 | sourceCodeLine: 0,
|
777 | sourceCodeColumn: 0,
|
778 | sourceCodeName: 0
|
779 | };
|
780 |
|
781 | var generatedCodeLine = 0;
|
782 | var generatedCodeColumn = 0;
|
783 |
|
784 | this.raw = [];
|
785 | var rawSegments = this.raw[ generatedCodeLine ] = [];
|
786 |
|
787 | var pending = null;
|
788 |
|
789 | this.addEdit = function ( sourceIndex, content, original, loc, nameIndex ) {
|
790 | if ( content.length ) {
|
791 | rawSegments.push([
|
792 | generatedCodeColumn,
|
793 | sourceIndex,
|
794 | loc.line,
|
795 | loc.column,
|
796 | nameIndex ]);
|
797 | } else if ( pending ) {
|
798 | rawSegments.push( pending );
|
799 | }
|
800 |
|
801 | this$1.advance( content );
|
802 | pending = null;
|
803 | };
|
804 |
|
805 | this.addUneditedChunk = function ( sourceIndex, chunk, original, loc, sourcemapLocations ) {
|
806 | var originalCharIndex = chunk.start;
|
807 | var first = true;
|
808 |
|
809 | while ( originalCharIndex < chunk.end ) {
|
810 | if ( hires || first || sourcemapLocations[ originalCharIndex ] ) {
|
811 | rawSegments.push([
|
812 | generatedCodeColumn,
|
813 | sourceIndex,
|
814 | loc.line,
|
815 | loc.column,
|
816 | -1
|
817 | ]);
|
818 | }
|
819 |
|
820 | if ( original[ originalCharIndex ] === '\n' ) {
|
821 | loc.line += 1;
|
822 | loc.column = 0;
|
823 | generatedCodeLine += 1;
|
824 | this$1.raw[ generatedCodeLine ] = rawSegments = [];
|
825 | generatedCodeColumn = 0;
|
826 | } else {
|
827 | loc.column += 1;
|
828 | generatedCodeColumn += 1;
|
829 | }
|
830 |
|
831 | originalCharIndex += 1;
|
832 | first = false;
|
833 | }
|
834 |
|
835 | pending = [
|
836 | generatedCodeColumn,
|
837 | sourceIndex,
|
838 | loc.line,
|
839 | loc.column,
|
840 | -1 ];
|
841 | };
|
842 |
|
843 | this.advance = function (str) {
|
844 | if ( !str ) { return; }
|
845 |
|
846 | var lines = str.split( '\n' );
|
847 | var lastLine = lines.pop();
|
848 |
|
849 | if ( lines.length ) {
|
850 | generatedCodeLine += lines.length;
|
851 | this$1.raw[ generatedCodeLine ] = rawSegments = [];
|
852 | generatedCodeColumn = lastLine.length;
|
853 | } else {
|
854 | generatedCodeColumn += lastLine.length;
|
855 | }
|
856 | };
|
857 |
|
858 | this.encode = function () {
|
859 | return this$1.raw.map( function (segments) {
|
860 | var generatedCodeColumn = 0;
|
861 |
|
862 | return segments.map( function (segment) {
|
863 | var arr = [
|
864 | segment[0] - generatedCodeColumn,
|
865 | segment[1] - offsets.sourceIndex,
|
866 | segment[2] - offsets.sourceCodeLine,
|
867 | segment[3] - offsets.sourceCodeColumn
|
868 | ];
|
869 |
|
870 | generatedCodeColumn = segment[0];
|
871 | offsets.sourceIndex = segment[1];
|
872 | offsets.sourceCodeLine = segment[2];
|
873 | offsets.sourceCodeColumn = segment[3];
|
874 |
|
875 | if ( ~segment[4] ) {
|
876 | arr.push( segment[4] - offsets.sourceCodeName );
|
877 | offsets.sourceCodeName = segment[4];
|
878 | }
|
879 |
|
880 | return encode( arr );
|
881 | }).join( ',' );
|
882 | }).join( ';' );
|
883 | };
|
884 | }
|
885 |
|
886 | var Stats = function Stats () {
|
887 | Object.defineProperties( this, {
|
888 | startTimes: { value: {} }
|
889 | });
|
890 | };
|
891 |
|
892 | Stats.prototype.time = function time ( label ) {
|
893 | this.startTimes[ label ] = process.hrtime();
|
894 | };
|
895 |
|
896 | Stats.prototype.timeEnd = function timeEnd ( label ) {
|
897 | var elapsed = process.hrtime( this.startTimes[ label ] );
|
898 |
|
899 | if ( !this[ label ] ) { this[ label ] = 0; }
|
900 | this[ label ] += elapsed[0] * 1e3 + elapsed[1] * 1e-6;
|
901 | };
|
902 |
|
903 | var warned = {
|
904 | insertLeft: false,
|
905 | insertRight: false,
|
906 | storeName: false
|
907 | };
|
908 |
|
909 | function MagicString$1 ( string, options ) {
|
910 | if ( options === void 0 ) options = {};
|
911 |
|
912 | var chunk = new Chunk( 0, string.length, string );
|
913 |
|
914 | Object.defineProperties( this, {
|
915 | original: { writable: true, value: string },
|
916 | outro: { writable: true, value: '' },
|
917 | intro: { writable: true, value: '' },
|
918 | firstChunk: { writable: true, value: chunk },
|
919 | lastChunk: { writable: true, value: chunk },
|
920 | lastSearchedChunk: { writable: true, value: chunk },
|
921 | byStart: { writable: true, value: {} },
|
922 | byEnd: { writable: true, value: {} },
|
923 | filename: { writable: true, value: options.filename },
|
924 | indentExclusionRanges: { writable: true, value: options.indentExclusionRanges },
|
925 | sourcemapLocations: { writable: true, value: {} },
|
926 | storedNames: { writable: true, value: {} },
|
927 | indentStr: { writable: true, value: guessIndent( string ) }
|
928 | });
|
929 |
|
930 | this.byStart[ 0 ] = chunk;
|
931 | this.byEnd[ string.length ] = chunk;
|
932 | }
|
933 |
|
934 | MagicString$1.prototype = {
|
935 | addSourcemapLocation: function addSourcemapLocation ( char ) {
|
936 | this.sourcemapLocations[ char ] = true;
|
937 | },
|
938 |
|
939 | append: function append ( content ) {
|
940 | if ( typeof content !== 'string' ) { throw new TypeError( 'outro content must be a string' ); }
|
941 |
|
942 | this.outro += content;
|
943 | return this;
|
944 | },
|
945 |
|
946 | appendLeft: function appendLeft ( index, content ) {
|
947 | if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
|
948 |
|
949 | this._split( index );
|
950 |
|
951 | var chunk = this.byEnd[ index ];
|
952 |
|
953 | if ( chunk ) {
|
954 | chunk.appendLeft( content );
|
955 | } else {
|
956 | this.intro += content;
|
957 | }
|
958 |
|
959 | return this;
|
960 | },
|
961 |
|
962 | appendRight: function appendRight ( index, content ) {
|
963 | if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
|
964 |
|
965 | this._split( index );
|
966 |
|
967 | var chunk = this.byStart[ index ];
|
968 |
|
969 | if ( chunk ) {
|
970 | chunk.appendRight( content );
|
971 | } else {
|
972 | this.outro += content;
|
973 | }
|
974 |
|
975 | return this;
|
976 | },
|
977 |
|
978 | clone: function clone () {
|
979 | var cloned = new MagicString$1( this.original, { filename: this.filename });
|
980 |
|
981 | var originalChunk = this.firstChunk;
|
982 | var clonedChunk = cloned.firstChunk = cloned.lastSearchedChunk = originalChunk.clone();
|
983 |
|
984 | while ( originalChunk ) {
|
985 | cloned.byStart[ clonedChunk.start ] = clonedChunk;
|
986 | cloned.byEnd[ clonedChunk.end ] = clonedChunk;
|
987 |
|
988 | var nextOriginalChunk = originalChunk.next;
|
989 | var nextClonedChunk = nextOriginalChunk && nextOriginalChunk.clone();
|
990 |
|
991 | if ( nextClonedChunk ) {
|
992 | clonedChunk.next = nextClonedChunk;
|
993 | nextClonedChunk.previous = clonedChunk;
|
994 |
|
995 | clonedChunk = nextClonedChunk;
|
996 | }
|
997 |
|
998 | originalChunk = nextOriginalChunk;
|
999 | }
|
1000 |
|
1001 | cloned.lastChunk = clonedChunk;
|
1002 |
|
1003 | if ( this.indentExclusionRanges ) {
|
1004 | cloned.indentExclusionRanges = this.indentExclusionRanges.slice();
|
1005 | }
|
1006 |
|
1007 | Object.keys( this.sourcemapLocations ).forEach( function (loc) {
|
1008 | cloned.sourcemapLocations[ loc ] = true;
|
1009 | });
|
1010 |
|
1011 | return cloned;
|
1012 | },
|
1013 |
|
1014 | generateMap: function generateMap ( options ) {
|
1015 | var this$1 = this;
|
1016 |
|
1017 | options = options || {};
|
1018 |
|
1019 | var sourceIndex = 0;
|
1020 | var names = Object.keys( this.storedNames );
|
1021 | var mappings = new Mappings( options.hires );
|
1022 |
|
1023 | var locate = getLocator( this.original );
|
1024 |
|
1025 | if ( this.intro ) {
|
1026 | mappings.advance( this.intro );
|
1027 | }
|
1028 |
|
1029 | this.firstChunk.eachNext( function (chunk) {
|
1030 | var loc = locate( chunk.start );
|
1031 |
|
1032 | if ( chunk.intro.length ) { mappings.advance( chunk.intro ); }
|
1033 |
|
1034 | if ( chunk.edited ) {
|
1035 | mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
|
1036 | } else {
|
1037 | mappings.addUneditedChunk( sourceIndex, chunk, this$1.original, loc, this$1.sourcemapLocations );
|
1038 | }
|
1039 |
|
1040 | if ( chunk.outro.length ) { mappings.advance( chunk.outro ); }
|
1041 | });
|
1042 |
|
1043 | var map = new SourceMap({
|
1044 | file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
|
1045 | sources: [ options.source ? getRelativePath( options.file || '', options.source ) : null ],
|
1046 | sourcesContent: options.includeContent ? [ this.original ] : [ null ],
|
1047 | names: names,
|
1048 | mappings: mappings.encode()
|
1049 | });
|
1050 | return map;
|
1051 | },
|
1052 |
|
1053 | getIndentString: function getIndentString () {
|
1054 | return this.indentStr === null ? '\t' : this.indentStr;
|
1055 | },
|
1056 |
|
1057 | indent: function indent ( indentStr, options ) {
|
1058 | var this$1 = this;
|
1059 |
|
1060 | var pattern = /^[^\r\n]/gm;
|
1061 |
|
1062 | if ( isObject( indentStr ) ) {
|
1063 | options = indentStr;
|
1064 | indentStr = undefined;
|
1065 | }
|
1066 |
|
1067 | indentStr = indentStr !== undefined ? indentStr : ( this.indentStr || '\t' );
|
1068 |
|
1069 | if ( indentStr === '' ) { return this; }
|
1070 |
|
1071 | options = options || {};
|
1072 |
|
1073 |
|
1074 | var isExcluded = {};
|
1075 |
|
1076 | if ( options.exclude ) {
|
1077 | var exclusions = typeof options.exclude[0] === 'number' ? [ options.exclude ] : options.exclude;
|
1078 | exclusions.forEach( function (exclusion) {
|
1079 | for ( var i = exclusion[0]; i < exclusion[1]; i += 1 ) {
|
1080 | isExcluded[i] = true;
|
1081 | }
|
1082 | });
|
1083 | }
|
1084 |
|
1085 | var shouldIndentNextCharacter = options.indentStart !== false;
|
1086 | var replacer = function (match) {
|
1087 | if ( shouldIndentNextCharacter ) { return ("" + indentStr + match); }
|
1088 | shouldIndentNextCharacter = true;
|
1089 | return match;
|
1090 | };
|
1091 |
|
1092 | this.intro = this.intro.replace( pattern, replacer );
|
1093 |
|
1094 | var charIndex = 0;
|
1095 |
|
1096 | var chunk = this.firstChunk;
|
1097 |
|
1098 | while ( chunk ) {
|
1099 | var end = chunk.end;
|
1100 |
|
1101 | if ( chunk.edited ) {
|
1102 | if ( !isExcluded[ charIndex ] ) {
|
1103 | chunk.content = chunk.content.replace( pattern, replacer );
|
1104 |
|
1105 | if ( chunk.content.length ) {
|
1106 | shouldIndentNextCharacter = chunk.content[ chunk.content.length - 1 ] === '\n';
|
1107 | }
|
1108 | }
|
1109 | } else {
|
1110 | charIndex = chunk.start;
|
1111 |
|
1112 | while ( charIndex < end ) {
|
1113 | if ( !isExcluded[ charIndex ] ) {
|
1114 | var char = this$1.original[ charIndex ];
|
1115 |
|
1116 | if ( char === '\n' ) {
|
1117 | shouldIndentNextCharacter = true;
|
1118 | } else if ( char !== '\r' && shouldIndentNextCharacter ) {
|
1119 | shouldIndentNextCharacter = false;
|
1120 |
|
1121 | if ( charIndex === chunk.start ) {
|
1122 | chunk.prependRight( indentStr );
|
1123 | } else {
|
1124 | this$1._splitChunk( chunk, charIndex );
|
1125 | chunk = chunk.next;
|
1126 | chunk.prependRight( indentStr );
|
1127 | }
|
1128 | }
|
1129 | }
|
1130 |
|
1131 | charIndex += 1;
|
1132 | }
|
1133 | }
|
1134 |
|
1135 | charIndex = chunk.end;
|
1136 | chunk = chunk.next;
|
1137 | }
|
1138 |
|
1139 | this.outro = this.outro.replace( pattern, replacer );
|
1140 |
|
1141 | return this;
|
1142 | },
|
1143 |
|
1144 | insert: function insert () {
|
1145 | throw new Error( 'magicString.insert(...) is deprecated. Use prependRight(...) or appendLeft(...)' );
|
1146 | },
|
1147 |
|
1148 | insertLeft: function insertLeft ( index, content ) {
|
1149 | if ( !warned.insertLeft ) {
|
1150 | console.warn( 'magicString.insertLeft(...) is deprecated. Use magicString.appendLeft(...) instead' );
|
1151 | warned.insertLeft = true;
|
1152 | }
|
1153 |
|
1154 | return this.appendLeft( index, content );
|
1155 | },
|
1156 |
|
1157 | insertRight: function insertRight ( index, content ) {
|
1158 | if ( !warned.insertRight ) {
|
1159 | console.warn( 'magicString.insertRight(...) is deprecated. Use magicString.prependRight(...) instead' );
|
1160 | warned.insertRight = true;
|
1161 | }
|
1162 |
|
1163 | return this.prependRight( index, content );
|
1164 | },
|
1165 |
|
1166 | move: function move ( start, end, index ) {
|
1167 | if ( index >= start && index <= end ) { throw new Error( 'Cannot move a selection inside itself' ); }
|
1168 |
|
1169 | this._split( start );
|
1170 | this._split( end );
|
1171 | this._split( index );
|
1172 |
|
1173 | var first = this.byStart[ start ];
|
1174 | var last = this.byEnd[ end ];
|
1175 |
|
1176 | var oldLeft = first.previous;
|
1177 | var oldRight = last.next;
|
1178 |
|
1179 | var newRight = this.byStart[ index ];
|
1180 | if ( !newRight && last === this.lastChunk ) { return this; }
|
1181 | var newLeft = newRight ? newRight.previous : this.lastChunk;
|
1182 |
|
1183 | if ( oldLeft ) { oldLeft.next = oldRight; }
|
1184 | if ( oldRight ) { oldRight.previous = oldLeft; }
|
1185 |
|
1186 | if ( newLeft ) { newLeft.next = first; }
|
1187 | if ( newRight ) { newRight.previous = last; }
|
1188 |
|
1189 | if ( !first.previous ) { this.firstChunk = last.next; }
|
1190 | if ( !last.next ) {
|
1191 | this.lastChunk = first.previous;
|
1192 | this.lastChunk.next = null;
|
1193 | }
|
1194 |
|
1195 | first.previous = newLeft;
|
1196 | last.next = newRight || null;
|
1197 |
|
1198 | if ( !newLeft ) { this.firstChunk = first; }
|
1199 | if ( !newRight ) { this.lastChunk = last; }
|
1200 |
|
1201 | return this;
|
1202 | },
|
1203 |
|
1204 | overwrite: function overwrite ( start, end, content, options ) {
|
1205 | var this$1 = this;
|
1206 |
|
1207 | if ( typeof content !== 'string' ) { throw new TypeError( 'replacement content must be a string' ); }
|
1208 |
|
1209 | while ( start < 0 ) { start += this$1.original.length; }
|
1210 | while ( end < 0 ) { end += this$1.original.length; }
|
1211 |
|
1212 | if ( end > this.original.length ) { throw new Error( 'end is out of bounds' ); }
|
1213 | if ( start === end ) { throw new Error( 'Cannot overwrite a zero-length range – use appendLeft or prependRight instead' ); }
|
1214 |
|
1215 | this._split( start );
|
1216 | this._split( end );
|
1217 |
|
1218 | if ( options === true ) {
|
1219 | if ( !warned.storeName ) {
|
1220 | console.warn( 'The final argument to magicString.overwrite(...) should be an options object. See https://github.com/rich-harris/magic-string' );
|
1221 | warned.storeName = true;
|
1222 | }
|
1223 |
|
1224 | options = { storeName: true };
|
1225 | }
|
1226 | var storeName = options !== undefined ? options.storeName : false;
|
1227 | var contentOnly = options !== undefined ? options.contentOnly : false;
|
1228 |
|
1229 | if ( storeName ) {
|
1230 | var original = this.original.slice( start, end );
|
1231 | this.storedNames[ original ] = true;
|
1232 | }
|
1233 |
|
1234 | var first = this.byStart[ start ];
|
1235 | var last = this.byEnd[ end ];
|
1236 |
|
1237 | if ( first ) {
|
1238 | if ( end > first.end && first.next !== this.byStart[ first.end ] ) {
|
1239 | throw new Error( 'Cannot overwrite across a split point' );
|
1240 | }
|
1241 |
|
1242 | first.edit( content, storeName, contentOnly );
|
1243 |
|
1244 | if ( first !== last ) {
|
1245 | var chunk = first.next;
|
1246 | while ( chunk !== last ) {
|
1247 | chunk.edit( '', false );
|
1248 | chunk = chunk.next;
|
1249 | }
|
1250 |
|
1251 | chunk.edit( '', false );
|
1252 | }
|
1253 | }
|
1254 |
|
1255 | else {
|
1256 |
|
1257 | var newChunk = new Chunk( start, end, '' ).edit( content, storeName );
|
1258 |
|
1259 |
|
1260 | last.next = newChunk;
|
1261 | newChunk.previous = last;
|
1262 | }
|
1263 |
|
1264 | return this;
|
1265 | },
|
1266 |
|
1267 | prepend: function prepend ( content ) {
|
1268 | if ( typeof content !== 'string' ) { throw new TypeError( 'outro content must be a string' ); }
|
1269 |
|
1270 | this.intro = content + this.intro;
|
1271 | return this;
|
1272 | },
|
1273 |
|
1274 | prependLeft: function prependLeft ( index, content ) {
|
1275 | if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
|
1276 |
|
1277 | this._split( index );
|
1278 |
|
1279 | var chunk = this.byEnd[ index ];
|
1280 |
|
1281 | if ( chunk ) {
|
1282 | chunk.prependLeft( content );
|
1283 | } else {
|
1284 | this.intro = content + this.intro;
|
1285 | }
|
1286 |
|
1287 | return this;
|
1288 | },
|
1289 |
|
1290 | prependRight: function prependRight ( index, content ) {
|
1291 | if ( typeof content !== 'string' ) { throw new TypeError( 'inserted content must be a string' ); }
|
1292 |
|
1293 | this._split( index );
|
1294 |
|
1295 | var chunk = this.byStart[ index ];
|
1296 |
|
1297 | if ( chunk ) {
|
1298 | chunk.prependRight( content );
|
1299 | } else {
|
1300 | this.outro = content + this.outro;
|
1301 | }
|
1302 |
|
1303 | return this;
|
1304 | },
|
1305 |
|
1306 | remove: function remove ( start, end ) {
|
1307 | var this$1 = this;
|
1308 |
|
1309 | while ( start < 0 ) { start += this$1.original.length; }
|
1310 | while ( end < 0 ) { end += this$1.original.length; }
|
1311 |
|
1312 | if ( start === end ) { return this; }
|
1313 |
|
1314 | if ( start < 0 || end > this.original.length ) { throw new Error( 'Character is out of bounds' ); }
|
1315 | if ( start > end ) { throw new Error( 'end must be greater than start' ); }
|
1316 |
|
1317 | this._split( start );
|
1318 | this._split( end );
|
1319 |
|
1320 | var chunk = this.byStart[ start ];
|
1321 |
|
1322 | while ( chunk ) {
|
1323 | chunk.intro = '';
|
1324 | chunk.outro = '';
|
1325 | chunk.edit( '' );
|
1326 |
|
1327 | chunk = end > chunk.end ? this$1.byStart[ chunk.end ] : null;
|
1328 | }
|
1329 |
|
1330 | return this;
|
1331 | },
|
1332 |
|
1333 | slice: function slice ( start, end ) {
|
1334 | var this$1 = this;
|
1335 | if ( start === void 0 ) start = 0;
|
1336 | if ( end === void 0 ) end = this.original.length;
|
1337 |
|
1338 | while ( start < 0 ) { start += this$1.original.length; }
|
1339 | while ( end < 0 ) { end += this$1.original.length; }
|
1340 |
|
1341 | var result = '';
|
1342 |
|
1343 |
|
1344 | var chunk = this.firstChunk;
|
1345 | while ( chunk && ( chunk.start > start || chunk.end <= start ) ) {
|
1346 |
|
1347 |
|
1348 | if ( chunk.start < end && chunk.end >= end ) {
|
1349 | return result;
|
1350 | }
|
1351 |
|
1352 | chunk = chunk.next;
|
1353 | }
|
1354 |
|
1355 | if ( chunk && chunk.edited && chunk.start !== start ) { throw new Error(("Cannot use replaced character " + start + " as slice start anchor.")); }
|
1356 |
|
1357 | var startChunk = chunk;
|
1358 | while ( chunk ) {
|
1359 | if ( chunk.intro && ( startChunk !== chunk || chunk.start === start ) ) {
|
1360 | result += chunk.intro;
|
1361 | }
|
1362 |
|
1363 | var containsEnd = chunk.start < end && chunk.end >= end;
|
1364 | if ( containsEnd && chunk.edited && chunk.end !== end ) { throw new Error(("Cannot use replaced character " + end + " as slice end anchor.")); }
|
1365 |
|
1366 | var sliceStart = startChunk === chunk ? start - chunk.start : 0;
|
1367 | var sliceEnd = containsEnd ? chunk.content.length + end - chunk.end : chunk.content.length;
|
1368 |
|
1369 | result += chunk.content.slice( sliceStart, sliceEnd );
|
1370 |
|
1371 | if ( chunk.outro && ( !containsEnd || chunk.end === end ) ) {
|
1372 | result += chunk.outro;
|
1373 | }
|
1374 |
|
1375 | if ( containsEnd ) {
|
1376 | break;
|
1377 | }
|
1378 |
|
1379 | chunk = chunk.next;
|
1380 | }
|
1381 |
|
1382 | return result;
|
1383 | },
|
1384 |
|
1385 |
|
1386 | snip: function snip ( start, end ) {
|
1387 | var clone = this.clone();
|
1388 | clone.remove( 0, start );
|
1389 | clone.remove( end, clone.original.length );
|
1390 |
|
1391 | return clone;
|
1392 | },
|
1393 |
|
1394 | _split: function _split ( index ) {
|
1395 | var this$1 = this;
|
1396 |
|
1397 | if ( this.byStart[ index ] || this.byEnd[ index ] ) { return; }
|
1398 |
|
1399 | var chunk = this.lastSearchedChunk;
|
1400 | var searchForward = index > chunk.end;
|
1401 |
|
1402 | while ( true ) {
|
1403 | if ( chunk.contains( index ) ) { return this$1._splitChunk( chunk, index ); }
|
1404 |
|
1405 | chunk = searchForward ?
|
1406 | this$1.byStart[ chunk.end ] :
|
1407 | this$1.byEnd[ chunk.start ];
|
1408 | }
|
1409 | },
|
1410 |
|
1411 | _splitChunk: function _splitChunk ( chunk, index ) {
|
1412 | if ( chunk.edited && chunk.content.length ) {
|
1413 | var loc = getLocator( this.original )( index );
|
1414 | throw new Error( ("Cannot split a chunk that has already been edited (" + (loc.line) + ":" + (loc.column) + " – \"" + (chunk.original) + "\")") );
|
1415 | }
|
1416 |
|
1417 | var newChunk = chunk.split( index );
|
1418 |
|
1419 | this.byEnd[ index ] = chunk;
|
1420 | this.byStart[ index ] = newChunk;
|
1421 | this.byEnd[ newChunk.end ] = newChunk;
|
1422 |
|
1423 | if ( chunk === this.lastChunk ) { this.lastChunk = newChunk; }
|
1424 |
|
1425 | this.lastSearchedChunk = chunk;
|
1426 | return true;
|
1427 | },
|
1428 |
|
1429 | toString: function toString () {
|
1430 | var str = this.intro;
|
1431 |
|
1432 | var chunk = this.firstChunk;
|
1433 | while ( chunk ) {
|
1434 | str += chunk.toString();
|
1435 | chunk = chunk.next;
|
1436 | }
|
1437 |
|
1438 | return str + this.outro;
|
1439 | },
|
1440 |
|
1441 | trimLines: function trimLines () {
|
1442 | return this.trim('[\\r\\n]');
|
1443 | },
|
1444 |
|
1445 | trim: function trim ( charType ) {
|
1446 | return this.trimStart( charType ).trimEnd( charType );
|
1447 | },
|
1448 |
|
1449 | trimEnd: function trimEnd ( charType ) {
|
1450 | var this$1 = this;
|
1451 |
|
1452 | var rx = new RegExp( ( charType || '\\s' ) + '+$' );
|
1453 |
|
1454 | this.outro = this.outro.replace( rx, '' );
|
1455 | if ( this.outro.length ) { return this; }
|
1456 |
|
1457 | var chunk = this.lastChunk;
|
1458 |
|
1459 | do {
|
1460 | var end = chunk.end;
|
1461 | var aborted = chunk.trimEnd( rx );
|
1462 |
|
1463 |
|
1464 | if ( chunk.end !== end ) {
|
1465 | if ( this$1.lastChunk === chunk ) {
|
1466 | this$1.lastChunk = chunk.next;
|
1467 | }
|
1468 |
|
1469 | this$1.byEnd[ chunk.end ] = chunk;
|
1470 | this$1.byStart[ chunk.next.start ] = chunk.next;
|
1471 | this$1.byEnd[ chunk.next.end ] = chunk.next;
|
1472 | }
|
1473 |
|
1474 | if ( aborted ) { return this$1; }
|
1475 | chunk = chunk.previous;
|
1476 | } while ( chunk );
|
1477 |
|
1478 | return this;
|
1479 | },
|
1480 |
|
1481 | trimStart: function trimStart ( charType ) {
|
1482 | var this$1 = this;
|
1483 |
|
1484 | var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
|
1485 |
|
1486 | this.intro = this.intro.replace( rx, '' );
|
1487 | if ( this.intro.length ) { return this; }
|
1488 |
|
1489 | var chunk = this.firstChunk;
|
1490 |
|
1491 | do {
|
1492 | var end = chunk.end;
|
1493 | var aborted = chunk.trimStart( rx );
|
1494 |
|
1495 | if ( chunk.end !== end ) {
|
1496 |
|
1497 | if ( chunk === this$1.lastChunk ) { this$1.lastChunk = chunk.next; }
|
1498 |
|
1499 | this$1.byEnd[ chunk.end ] = chunk;
|
1500 | this$1.byStart[ chunk.next.start ] = chunk.next;
|
1501 | this$1.byEnd[ chunk.next.end ] = chunk.next;
|
1502 | }
|
1503 |
|
1504 | if ( aborted ) { return this$1; }
|
1505 | chunk = chunk.next;
|
1506 | } while ( chunk );
|
1507 |
|
1508 | return this;
|
1509 | }
|
1510 | };
|
1511 |
|
1512 | var hasOwnProp = Object.prototype.hasOwnProperty;
|
1513 |
|
1514 | function Bundle$2 ( options ) {
|
1515 | if ( options === void 0 ) options = {};
|
1516 |
|
1517 | this.intro = options.intro || '';
|
1518 | this.separator = options.separator !== undefined ? options.separator : '\n';
|
1519 |
|
1520 | this.sources = [];
|
1521 |
|
1522 | this.uniqueSources = [];
|
1523 | this.uniqueSourceIndexByFilename = {};
|
1524 | }
|
1525 |
|
1526 | Bundle$2.prototype = {
|
1527 | addSource: function addSource ( source ) {
|
1528 | if ( source instanceof MagicString$1 ) {
|
1529 | return this.addSource({
|
1530 | content: source,
|
1531 | filename: source.filename,
|
1532 | separator: this.separator
|
1533 | });
|
1534 | }
|
1535 |
|
1536 | if ( !isObject( source ) || !source.content ) {
|
1537 | throw new Error( 'bundle.addSource() takes an object with a `content` property, which should be an instance of MagicString, and an optional `filename`' );
|
1538 | }
|
1539 |
|
1540 | [ 'filename', 'indentExclusionRanges', 'separator' ].forEach( function (option) {
|
1541 | if ( !hasOwnProp.call( source, option ) ) { source[ option ] = source.content[ option ]; }
|
1542 | });
|
1543 |
|
1544 | if ( source.separator === undefined ) {
|
1545 | source.separator = this.separator;
|
1546 | }
|
1547 |
|
1548 | if ( source.filename ) {
|
1549 | if ( !hasOwnProp.call( this.uniqueSourceIndexByFilename, source.filename ) ) {
|
1550 | this.uniqueSourceIndexByFilename[ source.filename ] = this.uniqueSources.length;
|
1551 | this.uniqueSources.push({ filename: source.filename, content: source.content.original });
|
1552 | } else {
|
1553 | var uniqueSource = this.uniqueSources[ this.uniqueSourceIndexByFilename[ source.filename ] ];
|
1554 | if ( source.content.original !== uniqueSource.content ) {
|
1555 | throw new Error( ("Illegal source: same filename (" + (source.filename) + "), different contents") );
|
1556 | }
|
1557 | }
|
1558 | }
|
1559 |
|
1560 | this.sources.push( source );
|
1561 | return this;
|
1562 | },
|
1563 |
|
1564 | append: function append ( str, options ) {
|
1565 | this.addSource({
|
1566 | content: new MagicString$1( str ),
|
1567 | separator: ( options && options.separator ) || ''
|
1568 | });
|
1569 |
|
1570 | return this;
|
1571 | },
|
1572 |
|
1573 | clone: function clone () {
|
1574 | var bundle = new Bundle$2({
|
1575 | intro: this.intro,
|
1576 | separator: this.separator
|
1577 | });
|
1578 |
|
1579 | this.sources.forEach( function (source) {
|
1580 | bundle.addSource({
|
1581 | filename: source.filename,
|
1582 | content: source.content.clone(),
|
1583 | separator: source.separator
|
1584 | });
|
1585 | });
|
1586 |
|
1587 | return bundle;
|
1588 | },
|
1589 |
|
1590 | generateMap: function generateMap ( options ) {
|
1591 | var this$1 = this;
|
1592 | if ( options === void 0 ) options = {};
|
1593 |
|
1594 | var names = [];
|
1595 | this.sources.forEach( function (source) {
|
1596 | Object.keys( source.content.storedNames ).forEach( function (name) {
|
1597 | if ( !~names.indexOf( name ) ) { names.push( name ); }
|
1598 | });
|
1599 | });
|
1600 |
|
1601 | var mappings = new Mappings( options.hires );
|
1602 |
|
1603 | if ( this.intro ) {
|
1604 | mappings.advance( this.intro );
|
1605 | }
|
1606 |
|
1607 | this.sources.forEach( function ( source, i ) {
|
1608 | if ( i > 0 ) {
|
1609 | mappings.advance( this$1.separator );
|
1610 | }
|
1611 |
|
1612 | var sourceIndex = source.filename ? this$1.uniqueSourceIndexByFilename[ source.filename ] : -1;
|
1613 | var magicString = source.content;
|
1614 | var locate = getLocator( magicString.original );
|
1615 |
|
1616 | if ( magicString.intro ) {
|
1617 | mappings.advance( magicString.intro );
|
1618 | }
|
1619 |
|
1620 | magicString.firstChunk.eachNext( function (chunk) {
|
1621 | var loc = locate( chunk.start );
|
1622 |
|
1623 | if ( chunk.intro.length ) { mappings.advance( chunk.intro ); }
|
1624 |
|
1625 | if ( source.filename ) {
|
1626 | if ( chunk.edited ) {
|
1627 | mappings.addEdit( sourceIndex, chunk.content, chunk.original, loc, chunk.storeName ? names.indexOf( chunk.original ) : -1 );
|
1628 | } else {
|
1629 | mappings.addUneditedChunk( sourceIndex, chunk, magicString.original, loc, magicString.sourcemapLocations );
|
1630 | }
|
1631 | }
|
1632 |
|
1633 | else {
|
1634 | mappings.advance( chunk.content );
|
1635 | }
|
1636 |
|
1637 | if ( chunk.outro.length ) { mappings.advance( chunk.outro ); }
|
1638 | });
|
1639 |
|
1640 | if ( magicString.outro ) {
|
1641 | mappings.advance( magicString.outro );
|
1642 | }
|
1643 | });
|
1644 |
|
1645 | return new SourceMap({
|
1646 | file: ( options.file ? options.file.split( /[\/\\]/ ).pop() : null ),
|
1647 | sources: this.uniqueSources.map( function (source) {
|
1648 | return options.file ? getRelativePath( options.file, source.filename ) : source.filename;
|
1649 | }),
|
1650 | sourcesContent: this.uniqueSources.map( function (source) {
|
1651 | return options.includeContent ? source.content : null;
|
1652 | }),
|
1653 | names: names,
|
1654 | mappings: mappings.encode()
|
1655 | });
|
1656 | },
|
1657 |
|
1658 | getIndentString: function getIndentString () {
|
1659 | var indentStringCounts = {};
|
1660 |
|
1661 | this.sources.forEach( function (source) {
|
1662 | var indentStr = source.content.indentStr;
|
1663 |
|
1664 | if ( indentStr === null ) { return; }
|
1665 |
|
1666 | if ( !indentStringCounts[ indentStr ] ) { indentStringCounts[ indentStr ] = 0; }
|
1667 | indentStringCounts[ indentStr ] += 1;
|
1668 | });
|
1669 |
|
1670 | return ( Object.keys( indentStringCounts ).sort( function ( a, b ) {
|
1671 | return indentStringCounts[a] - indentStringCounts[b];
|
1672 | })[0] ) || '\t';
|
1673 | },
|
1674 |
|
1675 | indent: function indent ( indentStr ) {
|
1676 | var this$1 = this;
|
1677 |
|
1678 | if ( !arguments.length ) {
|
1679 | indentStr = this.getIndentString();
|
1680 | }
|
1681 |
|
1682 | if ( indentStr === '' ) { return this; }
|
1683 |
|
1684 | var trailingNewline = !this.intro || this.intro.slice( -1 ) === '\n';
|
1685 |
|
1686 | this.sources.forEach( function ( source, i ) {
|
1687 | var separator = source.separator !== undefined ? source.separator : this$1.separator;
|
1688 | var indentStart = trailingNewline || ( i > 0 && /\r?\n$/.test( separator ) );
|
1689 |
|
1690 | source.content.indent( indentStr, {
|
1691 | exclude: source.indentExclusionRanges,
|
1692 | indentStart: indentStart
|
1693 | });
|
1694 |
|
1695 |
|
1696 | trailingNewline = source.content.toString().slice( 0, -1 ) === '\n';
|
1697 | });
|
1698 |
|
1699 | if ( this.intro ) {
|
1700 | this.intro = indentStr + this.intro.replace( /^[^\n]/gm, function ( match, index ) {
|
1701 | return index > 0 ? indentStr + match : match;
|
1702 | });
|
1703 | }
|
1704 |
|
1705 | return this;
|
1706 | },
|
1707 |
|
1708 | prepend: function prepend ( str ) {
|
1709 | this.intro = str + this.intro;
|
1710 | return this;
|
1711 | },
|
1712 |
|
1713 | toString: function toString () {
|
1714 | var this$1 = this;
|
1715 |
|
1716 | var body = this.sources.map( function ( source, i ) {
|
1717 | var separator = source.separator !== undefined ? source.separator : this$1.separator;
|
1718 | var str = ( i > 0 ? separator : '' ) + source.content.toString();
|
1719 |
|
1720 | return str;
|
1721 | }).join( '' );
|
1722 |
|
1723 | return this.intro + body;
|
1724 | },
|
1725 |
|
1726 | trimLines: function trimLines () {
|
1727 | return this.trim('[\\r\\n]');
|
1728 | },
|
1729 |
|
1730 | trim: function trim ( charType ) {
|
1731 | return this.trimStart( charType ).trimEnd( charType );
|
1732 | },
|
1733 |
|
1734 | trimStart: function trimStart ( charType ) {
|
1735 | var this$1 = this;
|
1736 |
|
1737 | var rx = new RegExp( '^' + ( charType || '\\s' ) + '+' );
|
1738 | this.intro = this.intro.replace( rx, '' );
|
1739 |
|
1740 | if ( !this.intro ) {
|
1741 | var source;
|
1742 | var i = 0;
|
1743 |
|
1744 | do {
|
1745 | source = this$1.sources[i];
|
1746 |
|
1747 | if ( !source ) {
|
1748 | break;
|
1749 | }
|
1750 |
|
1751 | source.content.trimStart( charType );
|
1752 | i += 1;
|
1753 | } while ( source.content.toString() === '' );
|
1754 | }
|
1755 |
|
1756 | return this;
|
1757 | },
|
1758 |
|
1759 | trimEnd: function trimEnd ( charType ) {
|
1760 | var this$1 = this;
|
1761 |
|
1762 | var rx = new RegExp( ( charType || '\\s' ) + '+$' );
|
1763 |
|
1764 | var source;
|
1765 | var i = this.sources.length - 1;
|
1766 |
|
1767 | do {
|
1768 | source = this$1.sources[i];
|
1769 |
|
1770 | if ( !source ) {
|
1771 | this$1.intro = this$1.intro.replace( rx, '' );
|
1772 | break;
|
1773 | }
|
1774 |
|
1775 | source.content.trimEnd( charType );
|
1776 | i -= 1;
|
1777 | } while ( source.content.toString() === '' );
|
1778 |
|
1779 | return this;
|
1780 | }
|
1781 | };
|
1782 |
|
1783 |
|
1784 |
|
1785 | function first ( candidates ) {
|
1786 | return function () {
|
1787 | var args = [], len = arguments.length;
|
1788 | while ( len-- ) args[ len ] = arguments[ len ];
|
1789 |
|
1790 | return candidates.reduce( function ( promise, candidate ) {
|
1791 | return promise.then( function (result) { return result != null ?
|
1792 | result :
|
1793 | Promise.resolve( candidate.apply( void 0, args ) ); } );
|
1794 | }, Promise.resolve() );
|
1795 | };
|
1796 | }
|
1797 |
|
1798 | function find ( array, fn ) {
|
1799 | for ( var i = 0; i < array.length; i += 1 ) {
|
1800 | if ( fn( array[i], i ) ) { return array[i]; }
|
1801 | }
|
1802 |
|
1803 | return null;
|
1804 | }
|
1805 |
|
1806 |
|
1807 |
|
1808 | var reservedWords = {
|
1809 | 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",
|
1810 | 5: "class enum extends super const export import",
|
1811 | 6: "enum",
|
1812 | strict: "implements interface let package private protected public static yield",
|
1813 | strictBind: "eval arguments"
|
1814 | };
|
1815 |
|
1816 |
|
1817 |
|
1818 | var ecma5AndLessKeywords = "break case catch continue debugger default do else finally for function if return switch throw try var while with null true false instanceof typeof void delete new in this";
|
1819 |
|
1820 | var keywords = {
|
1821 | 5: ecma5AndLessKeywords,
|
1822 | 6: ecma5AndLessKeywords + " const class extends export import super"
|
1823 | };
|
1824 |
|
1825 |
|
1826 |
|
1827 |
|
1828 |
|
1829 |
|
1830 |
|
1831 |
|
1832 |
|
1833 | var nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0561-\u0587\u05d0-\u05ea\u05f0-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u08a0-\u08b4\u08b6-\u08bd\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\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d05-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\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\u1c80-\u1c88\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-\ua7ae\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";
|
1834 | var nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d4-\u08e1\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\u1dfb-\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-\ua8c5\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";
|
1835 |
|
1836 | var nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
|
1837 | var nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
|
1838 |
|
1839 | nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
|
1840 |
|
1841 |
|
1842 |
|
1843 |
|
1844 |
|
1845 |
|
1846 |
|
1847 |
|
1848 | var astralIdentifierStartCodes = [0,11,2,25,2,18,2,1,2,14,3,13,35,122,70,52,268,28,4,48,48,31,17,26,6,37,11,29,3,35,5,7,2,4,43,157,19,35,5,35,5,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,159,52,19,3,54,47,21,1,2,0,185,46,42,3,37,47,21,0,60,42,86,25,391,63,32,0,449,56,264,8,2,36,18,0,50,29,881,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,65,0,32,6124,20,754,9486,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,60,67,1213,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];
|
1849 |
|
1850 |
|
1851 | var astralIdentifierCodes = [509,0,227,0,150,4,294,9,1368,2,2,1,6,3,41,2,5,0,166,1,1306,2,54,14,32,9,16,3,46,10,54,9,7,2,37,13,2,9,52,0,13,2,49,13,10,2,4,9,83,11,7,0,161,11,6,9,7,3,57,0,2,6,3,1,3,2,10,0,11,1,3,6,4,4,193,17,10,9,87,19,13,9,214,6,3,8,28,1,83,16,16,9,82,12,9,9,84,14,5,9,423,9,838,7,2,7,17,9,57,21,2,13,19882,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,1361,6,2,16,3,6,2,1,2,4,2214,6,110,6,6,9,792487,239];
|
1852 |
|
1853 |
|
1854 |
|
1855 |
|
1856 | function isInAstralSet(code, set) {
|
1857 | var pos = 0x10000;
|
1858 | for (var i = 0; i < set.length; i += 2) {
|
1859 | pos += set[i];
|
1860 | if (pos > code) { return false }
|
1861 | pos += set[i + 1];
|
1862 | if (pos >= code) { return true }
|
1863 | }
|
1864 | }
|
1865 |
|
1866 |
|
1867 |
|
1868 | function isIdentifierStart(code, astral) {
|
1869 | if (code < 65) { return code === 36 }
|
1870 | if (code < 91) { return true }
|
1871 | if (code < 97) { return code === 95 }
|
1872 | if (code < 123) { return true }
|
1873 | if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code)) }
|
1874 | if (astral === false) { return false }
|
1875 | return isInAstralSet(code, astralIdentifierStartCodes)
|
1876 | }
|
1877 |
|
1878 |
|
1879 |
|
1880 | function isIdentifierChar(code, astral) {
|
1881 | if (code < 48) { return code === 36 }
|
1882 | if (code < 58) { return true }
|
1883 | if (code < 65) { return false }
|
1884 | if (code < 91) { return true }
|
1885 | if (code < 97) { return code === 95 }
|
1886 | if (code < 123) { return true }
|
1887 | if (code <= 0xffff) { return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code)) }
|
1888 | if (astral === false) { return false }
|
1889 | return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes)
|
1890 | }
|
1891 |
|
1892 |
|
1893 |
|
1894 |
|
1895 |
|
1896 |
|
1897 |
|
1898 |
|
1899 |
|
1900 |
|
1901 |
|
1902 |
|
1903 |
|
1904 |
|
1905 |
|
1906 |
|
1907 |
|
1908 |
|
1909 |
|
1910 |
|
1911 |
|
1912 |
|
1913 |
|
1914 |
|
1915 | var TokenType = function TokenType(label, conf) {
|
1916 | if ( conf === void 0 ) { conf = {}; }
|
1917 |
|
1918 | this.label = label;
|
1919 | this.keyword = conf.keyword;
|
1920 | this.beforeExpr = !!conf.beforeExpr;
|
1921 | this.startsExpr = !!conf.startsExpr;
|
1922 | this.isLoop = !!conf.isLoop;
|
1923 | this.isAssign = !!conf.isAssign;
|
1924 | this.prefix = !!conf.prefix;
|
1925 | this.postfix = !!conf.postfix;
|
1926 | this.binop = conf.binop || null;
|
1927 | this.updateContext = null;
|
1928 | };
|
1929 |
|
1930 | function binop(name, prec) {
|
1931 | return new TokenType(name, {beforeExpr: true, binop: prec})
|
1932 | }
|
1933 | var beforeExpr = {beforeExpr: true};
|
1934 | var startsExpr = {startsExpr: true};
|
1935 |
|
1936 |
|
1937 |
|
1938 | var keywords$1 = {};
|
1939 |
|
1940 |
|
1941 | function kw(name, options) {
|
1942 | if ( options === void 0 ) { options = {}; }
|
1943 |
|
1944 | options.keyword = name;
|
1945 | return keywords$1[name] = new TokenType(name, options)
|
1946 | }
|
1947 |
|
1948 | var types = {
|
1949 | num: new TokenType("num", startsExpr),
|
1950 | regexp: new TokenType("regexp", startsExpr),
|
1951 | string: new TokenType("string", startsExpr),
|
1952 | name: new TokenType("name", startsExpr),
|
1953 | eof: new TokenType("eof"),
|
1954 |
|
1955 |
|
1956 | bracketL: new TokenType("[", {beforeExpr: true, startsExpr: true}),
|
1957 | bracketR: new TokenType("]"),
|
1958 | braceL: new TokenType("{", {beforeExpr: true, startsExpr: true}),
|
1959 | braceR: new TokenType("}"),
|
1960 | parenL: new TokenType("(", {beforeExpr: true, startsExpr: true}),
|
1961 | parenR: new TokenType(")"),
|
1962 | comma: new TokenType(",", beforeExpr),
|
1963 | semi: new TokenType(";", beforeExpr),
|
1964 | colon: new TokenType(":", beforeExpr),
|
1965 | dot: new TokenType("."),
|
1966 | question: new TokenType("?", beforeExpr),
|
1967 | arrow: new TokenType("=>", beforeExpr),
|
1968 | template: new TokenType("template"),
|
1969 | invalidTemplate: new TokenType("invalidTemplate"),
|
1970 | ellipsis: new TokenType("...", beforeExpr),
|
1971 | backQuote: new TokenType("`", startsExpr),
|
1972 | dollarBraceL: new TokenType("${", {beforeExpr: true, startsExpr: true}),
|
1973 |
|
1974 |
|
1975 |
|
1976 |
|
1977 |
|
1978 |
|
1979 |
|
1980 |
|
1981 |
|
1982 |
|
1983 |
|
1984 |
|
1985 |
|
1986 |
|
1987 |
|
1988 | eq: new TokenType("=", {beforeExpr: true, isAssign: true}),
|
1989 | assign: new TokenType("_=", {beforeExpr: true, isAssign: true}),
|
1990 | incDec: new TokenType("++/--", {prefix: true, postfix: true, startsExpr: true}),
|
1991 | prefix: new TokenType("prefix", {beforeExpr: true, prefix: true, startsExpr: true}),
|
1992 | logicalOR: binop("||", 1),
|
1993 | logicalAND: binop("&&", 2),
|
1994 | bitwiseOR: binop("|", 3),
|
1995 | bitwiseXOR: binop("^", 4),
|
1996 | bitwiseAND: binop("&", 5),
|
1997 | equality: binop("==/!=", 6),
|
1998 | relational: binop("</>", 7),
|
1999 | bitShift: binop("<</>>", 8),
|
2000 | plusMin: new TokenType("+/-", {beforeExpr: true, binop: 9, prefix: true, startsExpr: true}),
|
2001 | modulo: binop("%", 10),
|
2002 | star: binop("*", 10),
|
2003 | slash: binop("/", 10),
|
2004 | starstar: new TokenType("**", {beforeExpr: true}),
|
2005 |
|
2006 |
|
2007 | _break: kw("break"),
|
2008 | _case: kw("case", beforeExpr),
|
2009 | _catch: kw("catch"),
|
2010 | _continue: kw("continue"),
|
2011 | _debugger: kw("debugger"),
|
2012 | _default: kw("default", beforeExpr),
|
2013 | _do: kw("do", {isLoop: true, beforeExpr: true}),
|
2014 | _else: kw("else", beforeExpr),
|
2015 | _finally: kw("finally"),
|
2016 | _for: kw("for", {isLoop: true}),
|
2017 | _function: kw("function", startsExpr),
|
2018 | _if: kw("if"),
|
2019 | _return: kw("return", beforeExpr),
|
2020 | _switch: kw("switch"),
|
2021 | _throw: kw("throw", beforeExpr),
|
2022 | _try: kw("try"),
|
2023 | _var: kw("var"),
|
2024 | _const: kw("const"),
|
2025 | _while: kw("while", {isLoop: true}),
|
2026 | _with: kw("with"),
|
2027 | _new: kw("new", {beforeExpr: true, startsExpr: true}),
|
2028 | _this: kw("this", startsExpr),
|
2029 | _super: kw("super", startsExpr),
|
2030 | _class: kw("class", startsExpr),
|
2031 | _extends: kw("extends", beforeExpr),
|
2032 | _export: kw("export"),
|
2033 | _import: kw("import"),
|
2034 | _null: kw("null", startsExpr),
|
2035 | _true: kw("true", startsExpr),
|
2036 | _false: kw("false", startsExpr),
|
2037 | _in: kw("in", {beforeExpr: true, binop: 7}),
|
2038 | _instanceof: kw("instanceof", {beforeExpr: true, binop: 7}),
|
2039 | _typeof: kw("typeof", {beforeExpr: true, prefix: true, startsExpr: true}),
|
2040 | _void: kw("void", {beforeExpr: true, prefix: true, startsExpr: true}),
|
2041 | _delete: kw("delete", {beforeExpr: true, prefix: true, startsExpr: true})
|
2042 | };
|
2043 |
|
2044 |
|
2045 |
|
2046 |
|
2047 | var lineBreak = /\r\n?|\n|\u2028|\u2029/;
|
2048 | var lineBreakG = new RegExp(lineBreak.source, "g");
|
2049 |
|
2050 | function isNewLine(code) {
|
2051 | return code === 10 || code === 13 || code === 0x2028 || code === 0x2029
|
2052 | }
|
2053 |
|
2054 | var nonASCIIwhitespace = /[\u1680\u180e\u2000-\u200a\u202f\u205f\u3000\ufeff]/;
|
2055 |
|
2056 | var skipWhiteSpace = /(?:\s|\/\/.*|\/\*[^]*?\*\/)*/g;
|
2057 |
|
2058 | var ref = Object.prototype;
|
2059 | var hasOwnProperty = ref.hasOwnProperty;
|
2060 | var toString = ref.toString;
|
2061 |
|
2062 |
|
2063 |
|
2064 | function has(obj, propName) {
|
2065 | return hasOwnProperty.call(obj, propName)
|
2066 | }
|
2067 |
|
2068 | var isArray = Array.isArray || (function (obj) { return (
|
2069 | toString.call(obj) === "[object Array]"
|
2070 | ); });
|
2071 |
|
2072 |
|
2073 |
|
2074 |
|
2075 | var Position = function Position(line, col) {
|
2076 | this.line = line;
|
2077 | this.column = col;
|
2078 | };
|
2079 |
|
2080 | Position.prototype.offset = function offset (n) {
|
2081 | return new Position(this.line, this.column + n)
|
2082 | };
|
2083 |
|
2084 | var SourceLocation = function SourceLocation(p, start, end) {
|
2085 | this.start = start;
|
2086 | this.end = end;
|
2087 | if (p.sourceFile !== null) { this.source = p.sourceFile; }
|
2088 | };
|
2089 |
|
2090 |
|
2091 |
|
2092 |
|
2093 |
|
2094 |
|
2095 |
|
2096 | function getLineInfo(input, offset) {
|
2097 | for (var line = 1, cur = 0;;) {
|
2098 | lineBreakG.lastIndex = cur;
|
2099 | var match = lineBreakG.exec(input);
|
2100 | if (match && match.index < offset) {
|
2101 | ++line;
|
2102 | cur = match.index + match[0].length;
|
2103 | } else {
|
2104 | return new Position(line, offset - cur)
|
2105 | }
|
2106 | }
|
2107 | }
|
2108 |
|
2109 |
|
2110 |
|
2111 |
|
2112 | var defaultOptions = {
|
2113 |
|
2114 |
|
2115 |
|
2116 |
|
2117 | ecmaVersion: 7,
|
2118 |
|
2119 |
|
2120 |
|
2121 | sourceType: "script",
|
2122 |
|
2123 |
|
2124 |
|
2125 |
|
2126 |
|
2127 | onInsertedSemicolon: null,
|
2128 |
|
2129 |
|
2130 | onTrailingComma: null,
|
2131 |
|
2132 |
|
2133 |
|
2134 |
|
2135 | allowReserved: null,
|
2136 |
|
2137 |
|
2138 | allowReturnOutsideFunction: false,
|
2139 |
|
2140 |
|
2141 | allowImportExportEverywhere: false,
|
2142 |
|
2143 |
|
2144 | allowHashBang: false,
|
2145 |
|
2146 |
|
2147 |
|
2148 |
|
2149 | locations: false,
|
2150 |
|
2151 |
|
2152 |
|
2153 |
|
2154 |
|
2155 | onToken: null,
|
2156 |
|
2157 |
|
2158 |
|
2159 |
|
2160 |
|
2161 |
|
2162 |
|
2163 |
|
2164 |
|
2165 |
|
2166 | onComment: null,
|
2167 |
|
2168 |
|
2169 |
|
2170 |
|
2171 |
|
2172 |
|
2173 |
|
2174 |
|
2175 | ranges: false,
|
2176 |
|
2177 |
|
2178 |
|
2179 |
|
2180 |
|
2181 | program: null,
|
2182 |
|
2183 |
|
2184 | sourceFile: null,
|
2185 |
|
2186 |
|
2187 | directSourceFile: null,
|
2188 |
|
2189 |
|
2190 | preserveParens: false,
|
2191 | plugins: {}
|
2192 | };
|
2193 |
|
2194 |
|
2195 |
|
2196 | function getOptions(opts) {
|
2197 | var options = {};
|
2198 |
|
2199 | for (var opt in defaultOptions)
|
2200 | { options[opt] = opts && has(opts, opt) ? opts[opt] : defaultOptions[opt]; }
|
2201 |
|
2202 | if (options.ecmaVersion >= 2015)
|
2203 | { options.ecmaVersion -= 2009; }
|
2204 |
|
2205 | if (options.allowReserved == null)
|
2206 | { options.allowReserved = options.ecmaVersion < 5; }
|
2207 |
|
2208 | if (isArray(options.onToken)) {
|
2209 | var tokens = options.onToken;
|
2210 | options.onToken = function (token) { return tokens.push(token); };
|
2211 | }
|
2212 | if (isArray(options.onComment))
|
2213 | { options.onComment = pushComment(options, options.onComment); }
|
2214 |
|
2215 | return options
|
2216 | }
|
2217 |
|
2218 | function pushComment(options, array) {
|
2219 | return function(block, text, start, end, startLoc, endLoc) {
|
2220 | var comment = {
|
2221 | type: block ? "Block" : "Line",
|
2222 | value: text,
|
2223 | start: start,
|
2224 | end: end
|
2225 | };
|
2226 | if (options.locations)
|
2227 | { comment.loc = new SourceLocation(this, startLoc, endLoc); }
|
2228 | if (options.ranges)
|
2229 | { comment.range = [start, end]; }
|
2230 | array.push(comment);
|
2231 | }
|
2232 | }
|
2233 |
|
2234 |
|
2235 | var plugins = {};
|
2236 |
|
2237 | function keywordRegexp(words) {
|
2238 | return new RegExp("^(?:" + words.replace(/ /g, "|") + ")$")
|
2239 | }
|
2240 |
|
2241 | var Parser = function Parser(options, input, startPos) {
|
2242 | this.options = options = getOptions(options);
|
2243 | this.sourceFile = options.sourceFile;
|
2244 | this.keywords = keywordRegexp(keywords[options.ecmaVersion >= 6 ? 6 : 5]);
|
2245 | var reserved = "";
|
2246 | if (!options.allowReserved) {
|
2247 | for (var v = options.ecmaVersion;; v--)
|
2248 | { if (reserved = reservedWords[v]) { break } }
|
2249 | if (options.sourceType == "module") { reserved += " await"; }
|
2250 | }
|
2251 | this.reservedWords = keywordRegexp(reserved);
|
2252 | var reservedStrict = (reserved ? reserved + " " : "") + reservedWords.strict;
|
2253 | this.reservedWordsStrict = keywordRegexp(reservedStrict);
|
2254 | this.reservedWordsStrictBind = keywordRegexp(reservedStrict + " " + reservedWords.strictBind);
|
2255 | this.input = String(input);
|
2256 |
|
2257 |
|
2258 |
|
2259 |
|
2260 | this.containsEsc = false;
|
2261 |
|
2262 |
|
2263 | this.loadPlugins(options.plugins);
|
2264 |
|
2265 |
|
2266 |
|
2267 |
|
2268 | if (startPos) {
|
2269 | this.pos = startPos;
|
2270 | this.lineStart = this.input.lastIndexOf("\n", startPos - 1) + 1;
|
2271 | this.curLine = this.input.slice(0, this.lineStart).split(lineBreak).length;
|
2272 | } else {
|
2273 | this.pos = this.lineStart = 0;
|
2274 | this.curLine = 1;
|
2275 | }
|
2276 |
|
2277 |
|
2278 |
|
2279 | this.type = types.eof;
|
2280 |
|
2281 | this.value = null;
|
2282 |
|
2283 | this.start = this.end = this.pos;
|
2284 |
|
2285 |
|
2286 | this.startLoc = this.endLoc = this.curPosition();
|
2287 |
|
2288 |
|
2289 | this.lastTokEndLoc = this.lastTokStartLoc = null;
|
2290 | this.lastTokStart = this.lastTokEnd = this.pos;
|
2291 |
|
2292 |
|
2293 |
|
2294 |
|
2295 | this.context = this.initialContext();
|
2296 | this.exprAllowed = true;
|
2297 |
|
2298 |
|
2299 | this.inModule = options.sourceType === "module";
|
2300 | this.strict = this.inModule || this.strictDirective(this.pos);
|
2301 |
|
2302 |
|
2303 | this.potentialArrowAt = -1;
|
2304 |
|
2305 |
|
2306 | this.inFunction = this.inGenerator = this.inAsync = false;
|
2307 |
|
2308 | this.yieldPos = this.awaitPos = 0;
|
2309 |
|
2310 | this.labels = [];
|
2311 |
|
2312 |
|
2313 | if (this.pos === 0 && options.allowHashBang && this.input.slice(0, 2) === "#!")
|
2314 | { this.skipLineComment(2); }
|
2315 |
|
2316 |
|
2317 | this.scopeStack = [];
|
2318 | this.enterFunctionScope();
|
2319 | };
|
2320 |
|
2321 |
|
2322 | Parser.prototype.isKeyword = function isKeyword (word) { return this.keywords.test(word) };
|
2323 | Parser.prototype.isReservedWord = function isReservedWord (word) { return this.reservedWords.test(word) };
|
2324 |
|
2325 | Parser.prototype.extend = function extend (name, f) {
|
2326 | this[name] = f(this[name]);
|
2327 | };
|
2328 |
|
2329 | Parser.prototype.loadPlugins = function loadPlugins (pluginConfigs) {
|
2330 | var this$1 = this;
|
2331 |
|
2332 | for (var name in pluginConfigs) {
|
2333 | var plugin = plugins[name];
|
2334 | if (!plugin) { throw new Error("Plugin '" + name + "' not found") }
|
2335 | plugin(this$1, pluginConfigs[name]);
|
2336 | }
|
2337 | };
|
2338 |
|
2339 | Parser.prototype.parse = function parse () {
|
2340 | var node = this.options.program || this.startNode();
|
2341 | this.nextToken();
|
2342 | return this.parseTopLevel(node)
|
2343 | };
|
2344 |
|
2345 | var pp = Parser.prototype;
|
2346 |
|
2347 |
|
2348 |
|
2349 | var literal = /^(?:'((?:[^']|\.)*)'|"((?:[^"]|\.)*)"|;)/;
|
2350 | pp.strictDirective = function(start) {
|
2351 | var this$1 = this;
|
2352 |
|
2353 | for (;;) {
|
2354 | skipWhiteSpace.lastIndex = start;
|
2355 | start += skipWhiteSpace.exec(this$1.input)[0].length;
|
2356 | var match = literal.exec(this$1.input.slice(start));
|
2357 | if (!match) { return false }
|
2358 | if ((match[1] || match[2]) == "use strict") { return true }
|
2359 | start += match[0].length;
|
2360 | }
|
2361 | };
|
2362 |
|
2363 |
|
2364 |
|
2365 |
|
2366 | pp.eat = function(type) {
|
2367 | if (this.type === type) {
|
2368 | this.next();
|
2369 | return true
|
2370 | } else {
|
2371 | return false
|
2372 | }
|
2373 | };
|
2374 |
|
2375 |
|
2376 |
|
2377 | pp.isContextual = function(name) {
|
2378 | return this.type === types.name && this.value === name
|
2379 | };
|
2380 |
|
2381 |
|
2382 |
|
2383 | pp.eatContextual = function(name) {
|
2384 | return this.value === name && this.eat(types.name)
|
2385 | };
|
2386 |
|
2387 |
|
2388 |
|
2389 | pp.expectContextual = function(name) {
|
2390 | if (!this.eatContextual(name)) { this.unexpected(); }
|
2391 | };
|
2392 |
|
2393 |
|
2394 |
|
2395 | pp.canInsertSemicolon = function() {
|
2396 | return this.type === types.eof ||
|
2397 | this.type === types.braceR ||
|
2398 | lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
|
2399 | };
|
2400 |
|
2401 | pp.insertSemicolon = function() {
|
2402 | if (this.canInsertSemicolon()) {
|
2403 | if (this.options.onInsertedSemicolon)
|
2404 | { this.options.onInsertedSemicolon(this.lastTokEnd, this.lastTokEndLoc); }
|
2405 | return true
|
2406 | }
|
2407 | };
|
2408 |
|
2409 |
|
2410 |
|
2411 |
|
2412 | pp.semicolon = function() {
|
2413 | if (!this.eat(types.semi) && !this.insertSemicolon()) { this.unexpected(); }
|
2414 | };
|
2415 |
|
2416 | pp.afterTrailingComma = function(tokType, notNext) {
|
2417 | if (this.type == tokType) {
|
2418 | if (this.options.onTrailingComma)
|
2419 | { this.options.onTrailingComma(this.lastTokStart, this.lastTokStartLoc); }
|
2420 | if (!notNext)
|
2421 | { this.next(); }
|
2422 | return true
|
2423 | }
|
2424 | };
|
2425 |
|
2426 |
|
2427 |
|
2428 |
|
2429 | pp.expect = function(type) {
|
2430 | this.eat(type) || this.unexpected();
|
2431 | };
|
2432 |
|
2433 |
|
2434 |
|
2435 | pp.unexpected = function(pos) {
|
2436 | this.raise(pos != null ? pos : this.start, "Unexpected token");
|
2437 | };
|
2438 |
|
2439 | function DestructuringErrors() {
|
2440 | this.shorthandAssign =
|
2441 | this.trailingComma =
|
2442 | this.parenthesizedAssign =
|
2443 | this.parenthesizedBind =
|
2444 | -1;
|
2445 | }
|
2446 |
|
2447 | pp.checkPatternErrors = function(refDestructuringErrors, isAssign) {
|
2448 | if (!refDestructuringErrors) { return }
|
2449 | if (refDestructuringErrors.trailingComma > -1)
|
2450 | { this.raiseRecoverable(refDestructuringErrors.trailingComma, "Comma is not permitted after the rest element"); }
|
2451 | var parens = isAssign ? refDestructuringErrors.parenthesizedAssign : refDestructuringErrors.parenthesizedBind;
|
2452 | if (parens > -1) { this.raiseRecoverable(parens, "Parenthesized pattern"); }
|
2453 | };
|
2454 |
|
2455 | pp.checkExpressionErrors = function(refDestructuringErrors, andThrow) {
|
2456 | var pos = refDestructuringErrors ? refDestructuringErrors.shorthandAssign : -1;
|
2457 | if (!andThrow) { return pos >= 0 }
|
2458 | if (pos > -1) { this.raise(pos, "Shorthand property assignments are valid only in destructuring patterns"); }
|
2459 | };
|
2460 |
|
2461 | pp.checkYieldAwaitInDefaultParams = function() {
|
2462 | if (this.yieldPos && (!this.awaitPos || this.yieldPos < this.awaitPos))
|
2463 | { this.raise(this.yieldPos, "Yield expression cannot be a default value"); }
|
2464 | if (this.awaitPos)
|
2465 | { this.raise(this.awaitPos, "Await expression cannot be a default value"); }
|
2466 | };
|
2467 |
|
2468 | pp.isSimpleAssignTarget = function(expr) {
|
2469 | if (expr.type === "ParenthesizedExpression")
|
2470 | { return this.isSimpleAssignTarget(expr.expression) }
|
2471 | return expr.type === "Identifier" || expr.type === "MemberExpression"
|
2472 | };
|
2473 |
|
2474 | var pp$1 = Parser.prototype;
|
2475 |
|
2476 |
|
2477 |
|
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 |
|
2483 | pp$1.parseTopLevel = function(node) {
|
2484 | var this$1 = this;
|
2485 |
|
2486 | var exports = {};
|
2487 | if (!node.body) { node.body = []; }
|
2488 | while (this.type !== types.eof) {
|
2489 | var stmt = this$1.parseStatement(true, true, exports);
|
2490 | node.body.push(stmt);
|
2491 | }
|
2492 | this.next();
|
2493 | if (this.options.ecmaVersion >= 6) {
|
2494 | node.sourceType = this.options.sourceType;
|
2495 | }
|
2496 | return this.finishNode(node, "Program")
|
2497 | };
|
2498 |
|
2499 | var loopLabel = {kind: "loop"};
|
2500 | var switchLabel = {kind: "switch"};
|
2501 |
|
2502 | pp$1.isLet = function() {
|
2503 | if (this.type !== types.name || this.options.ecmaVersion < 6 || this.value != "let") { return false }
|
2504 | skipWhiteSpace.lastIndex = this.pos;
|
2505 | var skip = skipWhiteSpace.exec(this.input);
|
2506 | var next = this.pos + skip[0].length, nextCh = this.input.charCodeAt(next);
|
2507 | if (nextCh === 91 || nextCh == 123) { return true }
|
2508 | if (isIdentifierStart(nextCh, true)) {
|
2509 | var pos = next + 1;
|
2510 | while (isIdentifierChar(this.input.charCodeAt(pos), true)) { ++pos; }
|
2511 | var ident = this.input.slice(next, pos);
|
2512 | if (!this.isKeyword(ident)) { return true }
|
2513 | }
|
2514 | return false
|
2515 | };
|
2516 |
|
2517 |
|
2518 |
|
2519 |
|
2520 | pp$1.isAsyncFunction = function() {
|
2521 | if (this.type !== types.name || this.options.ecmaVersion < 8 || this.value != "async")
|
2522 | { return false }
|
2523 |
|
2524 | skipWhiteSpace.lastIndex = this.pos;
|
2525 | var skip = skipWhiteSpace.exec(this.input);
|
2526 | var next = this.pos + skip[0].length;
|
2527 | return !lineBreak.test(this.input.slice(this.pos, next)) &&
|
2528 | this.input.slice(next, next + 8) === "function" &&
|
2529 | (next + 8 == this.input.length || !isIdentifierChar(this.input.charAt(next + 8)))
|
2530 | };
|
2531 |
|
2532 |
|
2533 |
|
2534 |
|
2535 |
|
2536 |
|
2537 |
|
2538 |
|
2539 | pp$1.parseStatement = function(declaration, topLevel, exports) {
|
2540 | var starttype = this.type, node = this.startNode(), kind;
|
2541 |
|
2542 | if (this.isLet()) {
|
2543 | starttype = types._var;
|
2544 | kind = "let";
|
2545 | }
|
2546 |
|
2547 |
|
2548 |
|
2549 |
|
2550 |
|
2551 | switch (starttype) {
|
2552 | case types._break: case types._continue: return this.parseBreakContinueStatement(node, starttype.keyword)
|
2553 | case types._debugger: return this.parseDebuggerStatement(node)
|
2554 | case types._do: return this.parseDoStatement(node)
|
2555 | case types._for: return this.parseForStatement(node)
|
2556 | case types._function:
|
2557 | if (!declaration && this.options.ecmaVersion >= 6) { this.unexpected(); }
|
2558 | return this.parseFunctionStatement(node, false)
|
2559 | case types._class:
|
2560 | if (!declaration) { this.unexpected(); }
|
2561 | return this.parseClass(node, true)
|
2562 | case types._if: return this.parseIfStatement(node)
|
2563 | case types._return: return this.parseReturnStatement(node)
|
2564 | case types._switch: return this.parseSwitchStatement(node)
|
2565 | case types._throw: return this.parseThrowStatement(node)
|
2566 | case types._try: return this.parseTryStatement(node)
|
2567 | case types._const: case types._var:
|
2568 | kind = kind || this.value;
|
2569 | if (!declaration && kind != "var") { this.unexpected(); }
|
2570 | return this.parseVarStatement(node, kind)
|
2571 | case types._while: return this.parseWhileStatement(node)
|
2572 | case types._with: return this.parseWithStatement(node)
|
2573 | case types.braceL: return this.parseBlock()
|
2574 | case types.semi: return this.parseEmptyStatement(node)
|
2575 | case types._export:
|
2576 | case types._import:
|
2577 | if (!this.options.allowImportExportEverywhere) {
|
2578 | if (!topLevel)
|
2579 | { this.raise(this.start, "'import' and 'export' may only appear at the top level"); }
|
2580 | if (!this.inModule)
|
2581 | { this.raise(this.start, "'import' and 'export' may appear only with 'sourceType: module'"); }
|
2582 | }
|
2583 | return starttype === types._import ? this.parseImport(node) : this.parseExport(node, exports)
|
2584 |
|
2585 |
|
2586 |
|
2587 |
|
2588 |
|
2589 |
|
2590 | default:
|
2591 | if (this.isAsyncFunction() && declaration) {
|
2592 | this.next();
|
2593 | return this.parseFunctionStatement(node, true)
|
2594 | }
|
2595 |
|
2596 | var maybeName = this.value, expr = this.parseExpression();
|
2597 | if (starttype === types.name && expr.type === "Identifier" && this.eat(types.colon))
|
2598 | { return this.parseLabeledStatement(node, maybeName, expr) }
|
2599 | else { return this.parseExpressionStatement(node, expr) }
|
2600 | }
|
2601 | };
|
2602 |
|
2603 | pp$1.parseBreakContinueStatement = function(node, keyword) {
|
2604 | var this$1 = this;
|
2605 |
|
2606 | var isBreak = keyword == "break";
|
2607 | this.next();
|
2608 | if (this.eat(types.semi) || this.insertSemicolon()) { node.label = null; }
|
2609 | else if (this.type !== types.name) { this.unexpected(); }
|
2610 | else {
|
2611 | node.label = this.parseIdent();
|
2612 | this.semicolon();
|
2613 | }
|
2614 |
|
2615 |
|
2616 |
|
2617 | var i = 0;
|
2618 | for (; i < this.labels.length; ++i) {
|
2619 | var lab = this$1.labels[i];
|
2620 | if (node.label == null || lab.name === node.label.name) {
|
2621 | if (lab.kind != null && (isBreak || lab.kind === "loop")) { break }
|
2622 | if (node.label && isBreak) { break }
|
2623 | }
|
2624 | }
|
2625 | if (i === this.labels.length) { this.raise(node.start, "Unsyntactic " + keyword); }
|
2626 | return this.finishNode(node, isBreak ? "BreakStatement" : "ContinueStatement")
|
2627 | };
|
2628 |
|
2629 | pp$1.parseDebuggerStatement = function(node) {
|
2630 | this.next();
|
2631 | this.semicolon();
|
2632 | return this.finishNode(node, "DebuggerStatement")
|
2633 | };
|
2634 |
|
2635 | pp$1.parseDoStatement = function(node) {
|
2636 | this.next();
|
2637 | this.labels.push(loopLabel);
|
2638 | node.body = this.parseStatement(false);
|
2639 | this.labels.pop();
|
2640 | this.expect(types._while);
|
2641 | node.test = this.parseParenExpression();
|
2642 | if (this.options.ecmaVersion >= 6)
|
2643 | { this.eat(types.semi); }
|
2644 | else
|
2645 | { this.semicolon(); }
|
2646 | return this.finishNode(node, "DoWhileStatement")
|
2647 | };
|
2648 |
|
2649 |
|
2650 |
|
2651 |
|
2652 |
|
2653 |
|
2654 |
|
2655 |
|
2656 |
|
2657 | pp$1.parseForStatement = function(node) {
|
2658 | this.next();
|
2659 | this.labels.push(loopLabel);
|
2660 | this.enterLexicalScope();
|
2661 | this.expect(types.parenL);
|
2662 | if (this.type === types.semi) { return this.parseFor(node, null) }
|
2663 | var isLet = this.isLet();
|
2664 | if (this.type === types._var || this.type === types._const || isLet) {
|
2665 | var init$1 = this.startNode(), kind = isLet ? "let" : this.value;
|
2666 | this.next();
|
2667 | this.parseVar(init$1, true, kind);
|
2668 | this.finishNode(init$1, "VariableDeclaration");
|
2669 | if ((this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) && init$1.declarations.length === 1 &&
|
2670 | !(kind !== "var" && init$1.declarations[0].init))
|
2671 | { return this.parseForIn(node, init$1) }
|
2672 | return this.parseFor(node, init$1)
|
2673 | }
|
2674 | var refDestructuringErrors = new DestructuringErrors;
|
2675 | var init = this.parseExpression(true, refDestructuringErrors);
|
2676 | if (this.type === types._in || (this.options.ecmaVersion >= 6 && this.isContextual("of"))) {
|
2677 | this.toAssignable(init);
|
2678 | this.checkLVal(init);
|
2679 | this.checkPatternErrors(refDestructuringErrors, true);
|
2680 | return this.parseForIn(node, init)
|
2681 | } else {
|
2682 | this.checkExpressionErrors(refDestructuringErrors, true);
|
2683 | }
|
2684 | return this.parseFor(node, init)
|
2685 | };
|
2686 |
|
2687 | pp$1.parseFunctionStatement = function(node, isAsync) {
|
2688 | this.next();
|
2689 | return this.parseFunction(node, true, false, isAsync)
|
2690 | };
|
2691 |
|
2692 | pp$1.isFunction = function() {
|
2693 | return this.type === types._function || this.isAsyncFunction()
|
2694 | };
|
2695 |
|
2696 | pp$1.parseIfStatement = function(node) {
|
2697 | this.next();
|
2698 | node.test = this.parseParenExpression();
|
2699 |
|
2700 | node.consequent = this.parseStatement(!this.strict && this.isFunction());
|
2701 | node.alternate = this.eat(types._else) ? this.parseStatement(!this.strict && this.isFunction()) : null;
|
2702 | return this.finishNode(node, "IfStatement")
|
2703 | };
|
2704 |
|
2705 | pp$1.parseReturnStatement = function(node) {
|
2706 | if (!this.inFunction && !this.options.allowReturnOutsideFunction)
|
2707 | { this.raise(this.start, "'return' outside of function"); }
|
2708 | this.next();
|
2709 |
|
2710 |
|
2711 |
|
2712 |
|
2713 |
|
2714 | if (this.eat(types.semi) || this.insertSemicolon()) { node.argument = null; }
|
2715 | else { node.argument = this.parseExpression(); this.semicolon(); }
|
2716 | return this.finishNode(node, "ReturnStatement")
|
2717 | };
|
2718 |
|
2719 | pp$1.parseSwitchStatement = function(node) {
|
2720 | var this$1 = this;
|
2721 |
|
2722 | this.next();
|
2723 | node.discriminant = this.parseParenExpression();
|
2724 | node.cases = [];
|
2725 | this.expect(types.braceL);
|
2726 | this.labels.push(switchLabel);
|
2727 | this.enterLexicalScope();
|
2728 |
|
2729 |
|
2730 |
|
2731 |
|
2732 |
|
2733 | var cur;
|
2734 | for (var sawDefault = false; this.type != types.braceR;) {
|
2735 | if (this$1.type === types._case || this$1.type === types._default) {
|
2736 | var isCase = this$1.type === types._case;
|
2737 | if (cur) { this$1.finishNode(cur, "SwitchCase"); }
|
2738 | node.cases.push(cur = this$1.startNode());
|
2739 | cur.consequent = [];
|
2740 | this$1.next();
|
2741 | if (isCase) {
|
2742 | cur.test = this$1.parseExpression();
|
2743 | } else {
|
2744 | if (sawDefault) { this$1.raiseRecoverable(this$1.lastTokStart, "Multiple default clauses"); }
|
2745 | sawDefault = true;
|
2746 | cur.test = null;
|
2747 | }
|
2748 | this$1.expect(types.colon);
|
2749 | } else {
|
2750 | if (!cur) { this$1.unexpected(); }
|
2751 | cur.consequent.push(this$1.parseStatement(true));
|
2752 | }
|
2753 | }
|
2754 | this.exitLexicalScope();
|
2755 | if (cur) { this.finishNode(cur, "SwitchCase"); }
|
2756 | this.next();
|
2757 | this.labels.pop();
|
2758 | return this.finishNode(node, "SwitchStatement")
|
2759 | };
|
2760 |
|
2761 | pp$1.parseThrowStatement = function(node) {
|
2762 | this.next();
|
2763 | if (lineBreak.test(this.input.slice(this.lastTokEnd, this.start)))
|
2764 | { this.raise(this.lastTokEnd, "Illegal newline after throw"); }
|
2765 | node.argument = this.parseExpression();
|
2766 | this.semicolon();
|
2767 | return this.finishNode(node, "ThrowStatement")
|
2768 | };
|
2769 |
|
2770 |
|
2771 |
|
2772 | var empty = [];
|
2773 |
|
2774 | pp$1.parseTryStatement = function(node) {
|
2775 | this.next();
|
2776 | node.block = this.parseBlock();
|
2777 | node.handler = null;
|
2778 | if (this.type === types._catch) {
|
2779 | var clause = this.startNode();
|
2780 | this.next();
|
2781 | this.expect(types.parenL);
|
2782 | clause.param = this.parseBindingAtom();
|
2783 | this.enterLexicalScope();
|
2784 | this.checkLVal(clause.param, "let");
|
2785 | this.expect(types.parenR);
|
2786 | clause.body = this.parseBlock(false);
|
2787 | this.exitLexicalScope();
|
2788 | node.handler = this.finishNode(clause, "CatchClause");
|
2789 | }
|
2790 | node.finalizer = this.eat(types._finally) ? this.parseBlock() : null;
|
2791 | if (!node.handler && !node.finalizer)
|
2792 | { this.raise(node.start, "Missing catch or finally clause"); }
|
2793 | return this.finishNode(node, "TryStatement")
|
2794 | };
|
2795 |
|
2796 | pp$1.parseVarStatement = function(node, kind) {
|
2797 | this.next();
|
2798 | this.parseVar(node, false, kind);
|
2799 | this.semicolon();
|
2800 | return this.finishNode(node, "VariableDeclaration")
|
2801 | };
|
2802 |
|
2803 | pp$1.parseWhileStatement = function(node) {
|
2804 | this.next();
|
2805 | node.test = this.parseParenExpression();
|
2806 | this.labels.push(loopLabel);
|
2807 | node.body = this.parseStatement(false);
|
2808 | this.labels.pop();
|
2809 | return this.finishNode(node, "WhileStatement")
|
2810 | };
|
2811 |
|
2812 | pp$1.parseWithStatement = function(node) {
|
2813 | if (this.strict) { this.raise(this.start, "'with' in strict mode"); }
|
2814 | this.next();
|
2815 | node.object = this.parseParenExpression();
|
2816 | node.body = this.parseStatement(false);
|
2817 | return this.finishNode(node, "WithStatement")
|
2818 | };
|
2819 |
|
2820 | pp$1.parseEmptyStatement = function(node) {
|
2821 | this.next();
|
2822 | return this.finishNode(node, "EmptyStatement")
|
2823 | };
|
2824 |
|
2825 | pp$1.parseLabeledStatement = function(node, maybeName, expr) {
|
2826 | var this$1 = this;
|
2827 |
|
2828 | for (var i$1 = 0, list = this$1.labels; i$1 < list.length; i$1 += 1)
|
2829 | {
|
2830 | var label = list[i$1];
|
2831 |
|
2832 | if (label.name === maybeName)
|
2833 | { this$1.raise(expr.start, "Label '" + maybeName + "' is already declared");
|
2834 | } }
|
2835 | var kind = this.type.isLoop ? "loop" : this.type === types._switch ? "switch" : null;
|
2836 | for (var i = this.labels.length - 1; i >= 0; i--) {
|
2837 | var label$1 = this$1.labels[i];
|
2838 | if (label$1.statementStart == node.start) {
|
2839 | label$1.statementStart = this$1.start;
|
2840 | label$1.kind = kind;
|
2841 | } else { break }
|
2842 | }
|
2843 | this.labels.push({name: maybeName, kind: kind, statementStart: this.start});
|
2844 | node.body = this.parseStatement(true);
|
2845 | if (node.body.type == "ClassDeclaration" ||
|
2846 | node.body.type == "VariableDeclaration" && node.body.kind != "var" ||
|
2847 | node.body.type == "FunctionDeclaration" && (this.strict || node.body.generator))
|
2848 | { this.raiseRecoverable(node.body.start, "Invalid labeled declaration"); }
|
2849 | this.labels.pop();
|
2850 | node.label = expr;
|
2851 | return this.finishNode(node, "LabeledStatement")
|
2852 | };
|
2853 |
|
2854 | pp$1.parseExpressionStatement = function(node, expr) {
|
2855 | node.expression = expr;
|
2856 | this.semicolon();
|
2857 | return this.finishNode(node, "ExpressionStatement")
|
2858 | };
|
2859 |
|
2860 |
|
2861 |
|
2862 |
|
2863 |
|
2864 | pp$1.parseBlock = function(createNewLexicalScope) {
|
2865 | var this$1 = this;
|
2866 | if ( createNewLexicalScope === void 0 ) { createNewLexicalScope = true; }
|
2867 |
|
2868 | var node = this.startNode();
|
2869 | node.body = [];
|
2870 | this.expect(types.braceL);
|
2871 | if (createNewLexicalScope) {
|
2872 | this.enterLexicalScope();
|
2873 | }
|
2874 | while (!this.eat(types.braceR)) {
|
2875 | var stmt = this$1.parseStatement(true);
|
2876 | node.body.push(stmt);
|
2877 | }
|
2878 | if (createNewLexicalScope) {
|
2879 | this.exitLexicalScope();
|
2880 | }
|
2881 | return this.finishNode(node, "BlockStatement")
|
2882 | };
|
2883 |
|
2884 |
|
2885 |
|
2886 |
|
2887 |
|
2888 | pp$1.parseFor = function(node, init) {
|
2889 | node.init = init;
|
2890 | this.expect(types.semi);
|
2891 | node.test = this.type === types.semi ? null : this.parseExpression();
|
2892 | this.expect(types.semi);
|
2893 | node.update = this.type === types.parenR ? null : this.parseExpression();
|
2894 | this.expect(types.parenR);
|
2895 | this.exitLexicalScope();
|
2896 | node.body = this.parseStatement(false);
|
2897 | this.labels.pop();
|
2898 | return this.finishNode(node, "ForStatement")
|
2899 | };
|
2900 |
|
2901 |
|
2902 |
|
2903 |
|
2904 | pp$1.parseForIn = function(node, init) {
|
2905 | var type = this.type === types._in ? "ForInStatement" : "ForOfStatement";
|
2906 | this.next();
|
2907 | node.left = init;
|
2908 | node.right = this.parseExpression();
|
2909 | this.expect(types.parenR);
|
2910 | this.exitLexicalScope();
|
2911 | node.body = this.parseStatement(false);
|
2912 | this.labels.pop();
|
2913 | return this.finishNode(node, type)
|
2914 | };
|
2915 |
|
2916 |
|
2917 |
|
2918 | pp$1.parseVar = function(node, isFor, kind) {
|
2919 | var this$1 = this;
|
2920 |
|
2921 | node.declarations = [];
|
2922 | node.kind = kind;
|
2923 | for (;;) {
|
2924 | var decl = this$1.startNode();
|
2925 | this$1.parseVarId(decl, kind);
|
2926 | if (this$1.eat(types.eq)) {
|
2927 | decl.init = this$1.parseMaybeAssign(isFor);
|
2928 | } else if (kind === "const" && !(this$1.type === types._in || (this$1.options.ecmaVersion >= 6 && this$1.isContextual("of")))) {
|
2929 | this$1.unexpected();
|
2930 | } else if (decl.id.type != "Identifier" && !(isFor && (this$1.type === types._in || this$1.isContextual("of")))) {
|
2931 | this$1.raise(this$1.lastTokEnd, "Complex binding patterns require an initialization value");
|
2932 | } else {
|
2933 | decl.init = null;
|
2934 | }
|
2935 | node.declarations.push(this$1.finishNode(decl, "VariableDeclarator"));
|
2936 | if (!this$1.eat(types.comma)) { break }
|
2937 | }
|
2938 | return node
|
2939 | };
|
2940 |
|
2941 | pp$1.parseVarId = function(decl, kind) {
|
2942 | decl.id = this.parseBindingAtom(kind);
|
2943 | this.checkLVal(decl.id, kind, false);
|
2944 | };
|
2945 |
|
2946 |
|
2947 |
|
2948 |
|
2949 | pp$1.parseFunction = function(node, isStatement, allowExpressionBody, isAsync) {
|
2950 | this.initFunction(node);
|
2951 | if (this.options.ecmaVersion >= 6 && !isAsync)
|
2952 | { node.generator = this.eat(types.star); }
|
2953 | if (this.options.ecmaVersion >= 8)
|
2954 | { node.async = !!isAsync; }
|
2955 |
|
2956 | if (isStatement) {
|
2957 | node.id = isStatement === "nullableID" && this.type != types.name ? null : this.parseIdent();
|
2958 | if (node.id) {
|
2959 | this.checkLVal(node.id, "var");
|
2960 | }
|
2961 | }
|
2962 |
|
2963 | var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
|
2964 | oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
|
2965 | this.inGenerator = node.generator;
|
2966 | this.inAsync = node.async;
|
2967 | this.yieldPos = 0;
|
2968 | this.awaitPos = 0;
|
2969 | this.inFunction = true;
|
2970 | this.enterFunctionScope();
|
2971 |
|
2972 | if (!isStatement)
|
2973 | { node.id = this.type == types.name ? this.parseIdent() : null; }
|
2974 |
|
2975 | this.parseFunctionParams(node);
|
2976 | this.parseFunctionBody(node, allowExpressionBody);
|
2977 |
|
2978 | this.inGenerator = oldInGen;
|
2979 | this.inAsync = oldInAsync;
|
2980 | this.yieldPos = oldYieldPos;
|
2981 | this.awaitPos = oldAwaitPos;
|
2982 | this.inFunction = oldInFunc;
|
2983 | return this.finishNode(node, isStatement ? "FunctionDeclaration" : "FunctionExpression")
|
2984 | };
|
2985 |
|
2986 | pp$1.parseFunctionParams = function(node) {
|
2987 | this.expect(types.parenL);
|
2988 | node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
|
2989 | this.checkYieldAwaitInDefaultParams();
|
2990 | };
|
2991 |
|
2992 |
|
2993 |
|
2994 |
|
2995 | pp$1.parseClass = function(node, isStatement) {
|
2996 | var this$1 = this;
|
2997 |
|
2998 | this.next();
|
2999 |
|
3000 | this.parseClassId(node, isStatement);
|
3001 | this.parseClassSuper(node);
|
3002 | var classBody = this.startNode();
|
3003 | var hadConstructor = false;
|
3004 | classBody.body = [];
|
3005 | this.expect(types.braceL);
|
3006 | while (!this.eat(types.braceR)) {
|
3007 | if (this$1.eat(types.semi)) { continue }
|
3008 | var method = this$1.startNode();
|
3009 | var isGenerator = this$1.eat(types.star);
|
3010 | var isAsync = false;
|
3011 | var isMaybeStatic = this$1.type === types.name && this$1.value === "static";
|
3012 | this$1.parsePropertyName(method);
|
3013 | method.static = isMaybeStatic && this$1.type !== types.parenL;
|
3014 | if (method.static) {
|
3015 | if (isGenerator) { this$1.unexpected(); }
|
3016 | isGenerator = this$1.eat(types.star);
|
3017 | this$1.parsePropertyName(method);
|
3018 | }
|
3019 | if (this$1.options.ecmaVersion >= 8 && !isGenerator && !method.computed &&
|
3020 | method.key.type === "Identifier" && method.key.name === "async" && this$1.type !== types.parenL &&
|
3021 | !this$1.canInsertSemicolon()) {
|
3022 | isAsync = true;
|
3023 | this$1.parsePropertyName(method);
|
3024 | }
|
3025 | method.kind = "method";
|
3026 | var isGetSet = false;
|
3027 | if (!method.computed) {
|
3028 | var key = method.key;
|
3029 | if (!isGenerator && !isAsync && key.type === "Identifier" && this$1.type !== types.parenL && (key.name === "get" || key.name === "set")) {
|
3030 | isGetSet = true;
|
3031 | method.kind = key.name;
|
3032 | key = this$1.parsePropertyName(method);
|
3033 | }
|
3034 | if (!method.static && (key.type === "Identifier" && key.name === "constructor" ||
|
3035 | key.type === "Literal" && key.value === "constructor")) {
|
3036 | if (hadConstructor) { this$1.raise(key.start, "Duplicate constructor in the same class"); }
|
3037 | if (isGetSet) { this$1.raise(key.start, "Constructor can't have get/set modifier"); }
|
3038 | if (isGenerator) { this$1.raise(key.start, "Constructor can't be a generator"); }
|
3039 | if (isAsync) { this$1.raise(key.start, "Constructor can't be an async method"); }
|
3040 | method.kind = "constructor";
|
3041 | hadConstructor = true;
|
3042 | }
|
3043 | }
|
3044 | this$1.parseClassMethod(classBody, method, isGenerator, isAsync);
|
3045 | if (isGetSet) {
|
3046 | var paramCount = method.kind === "get" ? 0 : 1;
|
3047 | if (method.value.params.length !== paramCount) {
|
3048 | var start = method.value.start;
|
3049 | if (method.kind === "get")
|
3050 | { this$1.raiseRecoverable(start, "getter should have no params"); }
|
3051 | else
|
3052 | { this$1.raiseRecoverable(start, "setter should have exactly one param"); }
|
3053 | } else {
|
3054 | if (method.kind === "set" && method.value.params[0].type === "RestElement")
|
3055 | { this$1.raiseRecoverable(method.value.params[0].start, "Setter cannot use rest params"); }
|
3056 | }
|
3057 | }
|
3058 | }
|
3059 | node.body = this.finishNode(classBody, "ClassBody");
|
3060 | return this.finishNode(node, isStatement ? "ClassDeclaration" : "ClassExpression")
|
3061 | };
|
3062 |
|
3063 | pp$1.parseClassMethod = function(classBody, method, isGenerator, isAsync) {
|
3064 | method.value = this.parseMethod(isGenerator, isAsync);
|
3065 | classBody.body.push(this.finishNode(method, "MethodDefinition"));
|
3066 | };
|
3067 |
|
3068 | pp$1.parseClassId = function(node, isStatement) {
|
3069 | node.id = this.type === types.name ? this.parseIdent() : isStatement === true ? this.unexpected() : null;
|
3070 | };
|
3071 |
|
3072 | pp$1.parseClassSuper = function(node) {
|
3073 | node.superClass = this.eat(types._extends) ? this.parseExprSubscripts() : null;
|
3074 | };
|
3075 |
|
3076 |
|
3077 |
|
3078 | pp$1.parseExport = function(node, exports) {
|
3079 | var this$1 = this;
|
3080 |
|
3081 | this.next();
|
3082 |
|
3083 | if (this.eat(types.star)) {
|
3084 | this.expectContextual("from");
|
3085 | node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
|
3086 | this.semicolon();
|
3087 | return this.finishNode(node, "ExportAllDeclaration")
|
3088 | }
|
3089 | if (this.eat(types._default)) {
|
3090 | this.checkExport(exports, "default", this.lastTokStart);
|
3091 | var isAsync;
|
3092 | if (this.type === types._function || (isAsync = this.isAsyncFunction())) {
|
3093 | var fNode = this.startNode();
|
3094 | this.next();
|
3095 | if (isAsync) { this.next(); }
|
3096 | node.declaration = this.parseFunction(fNode, "nullableID", false, isAsync);
|
3097 | } else if (this.type === types._class) {
|
3098 | var cNode = this.startNode();
|
3099 | node.declaration = this.parseClass(cNode, "nullableID");
|
3100 | } else {
|
3101 | node.declaration = this.parseMaybeAssign();
|
3102 | this.semicolon();
|
3103 | }
|
3104 | return this.finishNode(node, "ExportDefaultDeclaration")
|
3105 | }
|
3106 |
|
3107 | if (this.shouldParseExportStatement()) {
|
3108 | node.declaration = this.parseStatement(true);
|
3109 | if (node.declaration.type === "VariableDeclaration")
|
3110 | { this.checkVariableExport(exports, node.declaration.declarations); }
|
3111 | else
|
3112 | { this.checkExport(exports, node.declaration.id.name, node.declaration.id.start); }
|
3113 | node.specifiers = [];
|
3114 | node.source = null;
|
3115 | } else {
|
3116 | node.declaration = null;
|
3117 | node.specifiers = this.parseExportSpecifiers(exports);
|
3118 | if (this.eatContextual("from")) {
|
3119 | node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
|
3120 | } else {
|
3121 |
|
3122 | for (var i = 0, list = node.specifiers; i < list.length; i += 1) {
|
3123 | var spec = list[i];
|
3124 |
|
3125 | this$1.checkUnreserved(spec.local);
|
3126 | }
|
3127 |
|
3128 | node.source = null;
|
3129 | }
|
3130 | this.semicolon();
|
3131 | }
|
3132 | return this.finishNode(node, "ExportNamedDeclaration")
|
3133 | };
|
3134 |
|
3135 | pp$1.checkExport = function(exports, name, pos) {
|
3136 | if (!exports) { return }
|
3137 | if (has(exports, name))
|
3138 | { this.raiseRecoverable(pos, "Duplicate export '" + name + "'"); }
|
3139 | exports[name] = true;
|
3140 | };
|
3141 |
|
3142 | pp$1.checkPatternExport = function(exports, pat) {
|
3143 | var this$1 = this;
|
3144 |
|
3145 | var type = pat.type;
|
3146 | if (type == "Identifier")
|
3147 | { this.checkExport(exports, pat.name, pat.start); }
|
3148 | else if (type == "ObjectPattern")
|
3149 | { for (var i = 0, list = pat.properties; i < list.length; i += 1)
|
3150 | {
|
3151 | var prop = list[i];
|
3152 |
|
3153 | this$1.checkPatternExport(exports, prop.value);
|
3154 | } }
|
3155 | else if (type == "ArrayPattern")
|
3156 | { for (var i$1 = 0, list$1 = pat.elements; i$1 < list$1.length; i$1 += 1) {
|
3157 | var elt = list$1[i$1];
|
3158 |
|
3159 | if (elt) { this$1.checkPatternExport(exports, elt); }
|
3160 | } }
|
3161 | else if (type == "AssignmentPattern")
|
3162 | { this.checkPatternExport(exports, pat.left); }
|
3163 | else if (type == "ParenthesizedExpression")
|
3164 | { this.checkPatternExport(exports, pat.expression); }
|
3165 | };
|
3166 |
|
3167 | pp$1.checkVariableExport = function(exports, decls) {
|
3168 | var this$1 = this;
|
3169 |
|
3170 | if (!exports) { return }
|
3171 | for (var i = 0, list = decls; i < list.length; i += 1)
|
3172 | {
|
3173 | var decl = list[i];
|
3174 |
|
3175 | this$1.checkPatternExport(exports, decl.id);
|
3176 | }
|
3177 | };
|
3178 |
|
3179 | pp$1.shouldParseExportStatement = function() {
|
3180 | return this.type.keyword === "var" ||
|
3181 | this.type.keyword === "const" ||
|
3182 | this.type.keyword === "class" ||
|
3183 | this.type.keyword === "function" ||
|
3184 | this.isLet() ||
|
3185 | this.isAsyncFunction()
|
3186 | };
|
3187 |
|
3188 |
|
3189 |
|
3190 | pp$1.parseExportSpecifiers = function(exports) {
|
3191 | var this$1 = this;
|
3192 |
|
3193 | var nodes = [], first = true;
|
3194 |
|
3195 | this.expect(types.braceL);
|
3196 | while (!this.eat(types.braceR)) {
|
3197 | if (!first) {
|
3198 | this$1.expect(types.comma);
|
3199 | if (this$1.afterTrailingComma(types.braceR)) { break }
|
3200 | } else { first = false; }
|
3201 |
|
3202 | var node = this$1.startNode();
|
3203 | node.local = this$1.parseIdent(true);
|
3204 | node.exported = this$1.eatContextual("as") ? this$1.parseIdent(true) : node.local;
|
3205 | this$1.checkExport(exports, node.exported.name, node.exported.start);
|
3206 | nodes.push(this$1.finishNode(node, "ExportSpecifier"));
|
3207 | }
|
3208 | return nodes
|
3209 | };
|
3210 |
|
3211 |
|
3212 |
|
3213 | pp$1.parseImport = function(node) {
|
3214 | this.next();
|
3215 |
|
3216 | if (this.type === types.string) {
|
3217 | node.specifiers = empty;
|
3218 | node.source = this.parseExprAtom();
|
3219 | } else {
|
3220 | node.specifiers = this.parseImportSpecifiers();
|
3221 | this.expectContextual("from");
|
3222 | node.source = this.type === types.string ? this.parseExprAtom() : this.unexpected();
|
3223 | }
|
3224 | this.semicolon();
|
3225 | return this.finishNode(node, "ImportDeclaration")
|
3226 | };
|
3227 |
|
3228 |
|
3229 |
|
3230 | pp$1.parseImportSpecifiers = function() {
|
3231 | var this$1 = this;
|
3232 |
|
3233 | var nodes = [], first = true;
|
3234 | if (this.type === types.name) {
|
3235 |
|
3236 | var node = this.startNode();
|
3237 | node.local = this.parseIdent();
|
3238 | this.checkLVal(node.local, "let");
|
3239 | nodes.push(this.finishNode(node, "ImportDefaultSpecifier"));
|
3240 | if (!this.eat(types.comma)) { return nodes }
|
3241 | }
|
3242 | if (this.type === types.star) {
|
3243 | var node$1 = this.startNode();
|
3244 | this.next();
|
3245 | this.expectContextual("as");
|
3246 | node$1.local = this.parseIdent();
|
3247 | this.checkLVal(node$1.local, "let");
|
3248 | nodes.push(this.finishNode(node$1, "ImportNamespaceSpecifier"));
|
3249 | return nodes
|
3250 | }
|
3251 | this.expect(types.braceL);
|
3252 | while (!this.eat(types.braceR)) {
|
3253 | if (!first) {
|
3254 | this$1.expect(types.comma);
|
3255 | if (this$1.afterTrailingComma(types.braceR)) { break }
|
3256 | } else { first = false; }
|
3257 |
|
3258 | var node$2 = this$1.startNode();
|
3259 | node$2.imported = this$1.parseIdent(true);
|
3260 | if (this$1.eatContextual("as")) {
|
3261 | node$2.local = this$1.parseIdent();
|
3262 | } else {
|
3263 | this$1.checkUnreserved(node$2.imported);
|
3264 | node$2.local = node$2.imported;
|
3265 | }
|
3266 | this$1.checkLVal(node$2.local, "let");
|
3267 | nodes.push(this$1.finishNode(node$2, "ImportSpecifier"));
|
3268 | }
|
3269 | return nodes
|
3270 | };
|
3271 |
|
3272 | var pp$2 = Parser.prototype;
|
3273 |
|
3274 |
|
3275 |
|
3276 |
|
3277 | pp$2.toAssignable = function(node, isBinding) {
|
3278 | var this$1 = this;
|
3279 |
|
3280 | if (this.options.ecmaVersion >= 6 && node) {
|
3281 | switch (node.type) {
|
3282 | case "Identifier":
|
3283 | if (this.inAsync && node.name === "await")
|
3284 | { this.raise(node.start, "Can not use 'await' as identifier inside an async function"); }
|
3285 | break
|
3286 |
|
3287 | case "ObjectPattern":
|
3288 | case "ArrayPattern":
|
3289 | break
|
3290 |
|
3291 | case "ObjectExpression":
|
3292 | node.type = "ObjectPattern";
|
3293 | for (var i = 0, list = node.properties; i < list.length; i += 1) {
|
3294 | var prop = list[i];
|
3295 |
|
3296 | if (prop.kind !== "init") { this$1.raise(prop.key.start, "Object pattern can't contain getter or setter"); }
|
3297 | this$1.toAssignable(prop.value, isBinding);
|
3298 | }
|
3299 | break
|
3300 |
|
3301 | case "ArrayExpression":
|
3302 | node.type = "ArrayPattern";
|
3303 | this.toAssignableList(node.elements, isBinding);
|
3304 | break
|
3305 |
|
3306 | case "AssignmentExpression":
|
3307 | if (node.operator === "=") {
|
3308 | node.type = "AssignmentPattern";
|
3309 | delete node.operator;
|
3310 | this.toAssignable(node.left, isBinding);
|
3311 |
|
3312 | } else {
|
3313 | this.raise(node.left.end, "Only '=' operator can be used for specifying default value.");
|
3314 | break
|
3315 | }
|
3316 |
|
3317 | case "AssignmentPattern":
|
3318 | break
|
3319 |
|
3320 | case "ParenthesizedExpression":
|
3321 | this.toAssignable(node.expression, isBinding);
|
3322 | break
|
3323 |
|
3324 | case "MemberExpression":
|
3325 | if (!isBinding) { break }
|
3326 |
|
3327 | default:
|
3328 | this.raise(node.start, "Assigning to rvalue");
|
3329 | }
|
3330 | }
|
3331 | return node
|
3332 | };
|
3333 |
|
3334 |
|
3335 |
|
3336 | pp$2.toAssignableList = function(exprList, isBinding) {
|
3337 | var this$1 = this;
|
3338 |
|
3339 | var end = exprList.length;
|
3340 | if (end) {
|
3341 | var last = exprList[end - 1];
|
3342 | if (last && last.type == "RestElement") {
|
3343 | --end;
|
3344 | } else if (last && last.type == "SpreadElement") {
|
3345 | last.type = "RestElement";
|
3346 | var arg = last.argument;
|
3347 | this.toAssignable(arg, isBinding);
|
3348 | --end;
|
3349 | }
|
3350 |
|
3351 | if (this.options.ecmaVersion === 6 && isBinding && last && last.type === "RestElement" && last.argument.type !== "Identifier")
|
3352 | { this.unexpected(last.argument.start); }
|
3353 | }
|
3354 | for (var i = 0; i < end; i++) {
|
3355 | var elt = exprList[i];
|
3356 | if (elt) { this$1.toAssignable(elt, isBinding); }
|
3357 | }
|
3358 | return exprList
|
3359 | };
|
3360 |
|
3361 |
|
3362 |
|
3363 | pp$2.parseSpread = function(refDestructuringErrors) {
|
3364 | var node = this.startNode();
|
3365 | this.next();
|
3366 | node.argument = this.parseMaybeAssign(false, refDestructuringErrors);
|
3367 | return this.finishNode(node, "SpreadElement")
|
3368 | };
|
3369 |
|
3370 | pp$2.parseRestBinding = function() {
|
3371 | var node = this.startNode();
|
3372 | this.next();
|
3373 |
|
3374 |
|
3375 | if (this.options.ecmaVersion === 6 && this.type !== types.name)
|
3376 | { this.unexpected(); }
|
3377 |
|
3378 | node.argument = this.parseBindingAtom();
|
3379 |
|
3380 | return this.finishNode(node, "RestElement")
|
3381 | };
|
3382 |
|
3383 |
|
3384 |
|
3385 | pp$2.parseBindingAtom = function() {
|
3386 | if (this.options.ecmaVersion < 6) { return this.parseIdent() }
|
3387 | switch (this.type) {
|
3388 | case types.name:
|
3389 | return this.parseIdent()
|
3390 |
|
3391 | case types.bracketL:
|
3392 | var node = this.startNode();
|
3393 | this.next();
|
3394 | node.elements = this.parseBindingList(types.bracketR, true, true);
|
3395 | return this.finishNode(node, "ArrayPattern")
|
3396 |
|
3397 | case types.braceL:
|
3398 | return this.parseObj(true)
|
3399 |
|
3400 | default:
|
3401 | this.unexpected();
|
3402 | }
|
3403 | };
|
3404 |
|
3405 | pp$2.parseBindingList = function(close, allowEmpty, allowTrailingComma) {
|
3406 | var this$1 = this;
|
3407 |
|
3408 | var elts = [], first = true;
|
3409 | while (!this.eat(close)) {
|
3410 | if (first) { first = false; }
|
3411 | else { this$1.expect(types.comma); }
|
3412 | if (allowEmpty && this$1.type === types.comma) {
|
3413 | elts.push(null);
|
3414 | } else if (allowTrailingComma && this$1.afterTrailingComma(close)) {
|
3415 | break
|
3416 | } else if (this$1.type === types.ellipsis) {
|
3417 | var rest = this$1.parseRestBinding();
|
3418 | this$1.parseBindingListItem(rest);
|
3419 | elts.push(rest);
|
3420 | if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
|
3421 | this$1.expect(close);
|
3422 | break
|
3423 | } else {
|
3424 | var elem = this$1.parseMaybeDefault(this$1.start, this$1.startLoc);
|
3425 | this$1.parseBindingListItem(elem);
|
3426 | elts.push(elem);
|
3427 | }
|
3428 | }
|
3429 | return elts
|
3430 | };
|
3431 |
|
3432 | pp$2.parseBindingListItem = function(param) {
|
3433 | return param
|
3434 | };
|
3435 |
|
3436 |
|
3437 |
|
3438 | pp$2.parseMaybeDefault = function(startPos, startLoc, left) {
|
3439 | left = left || this.parseBindingAtom();
|
3440 | if (this.options.ecmaVersion < 6 || !this.eat(types.eq)) { return left }
|
3441 | var node = this.startNodeAt(startPos, startLoc);
|
3442 | node.left = left;
|
3443 | node.right = this.parseMaybeAssign();
|
3444 | return this.finishNode(node, "AssignmentPattern")
|
3445 | };
|
3446 |
|
3447 |
|
3448 |
|
3449 |
|
3450 |
|
3451 |
|
3452 |
|
3453 |
|
3454 | pp$2.checkLVal = function(expr, bindingType, checkClashes) {
|
3455 | var this$1 = this;
|
3456 |
|
3457 | switch (expr.type) {
|
3458 | case "Identifier":
|
3459 | if (this.strict && this.reservedWordsStrictBind.test(expr.name))
|
3460 | { this.raiseRecoverable(expr.start, (bindingType ? "Binding " : "Assigning to ") + expr.name + " in strict mode"); }
|
3461 | if (checkClashes) {
|
3462 | if (has(checkClashes, expr.name))
|
3463 | { this.raiseRecoverable(expr.start, "Argument name clash"); }
|
3464 | checkClashes[expr.name] = true;
|
3465 | }
|
3466 | if (bindingType && bindingType !== "none") {
|
3467 | if (
|
3468 | bindingType === "var" && !this.canDeclareVarName(expr.name) ||
|
3469 | bindingType !== "var" && !this.canDeclareLexicalName(expr.name)
|
3470 | ) {
|
3471 | this.raiseRecoverable(expr.start, ("Identifier '" + (expr.name) + "' has already been declared"));
|
3472 | }
|
3473 | if (bindingType === "var") {
|
3474 | this.declareVarName(expr.name);
|
3475 | } else {
|
3476 | this.declareLexicalName(expr.name);
|
3477 | }
|
3478 | }
|
3479 | break
|
3480 |
|
3481 | case "MemberExpression":
|
3482 | if (bindingType) { this.raiseRecoverable(expr.start, (bindingType ? "Binding" : "Assigning to") + " member expression"); }
|
3483 | break
|
3484 |
|
3485 | case "ObjectPattern":
|
3486 | for (var i = 0, list = expr.properties; i < list.length; i += 1)
|
3487 | {
|
3488 | var prop = list[i];
|
3489 |
|
3490 | this$1.checkLVal(prop.value, bindingType, checkClashes);
|
3491 | }
|
3492 | break
|
3493 |
|
3494 | case "ArrayPattern":
|
3495 | for (var i$1 = 0, list$1 = expr.elements; i$1 < list$1.length; i$1 += 1) {
|
3496 | var elem = list$1[i$1];
|
3497 |
|
3498 | if (elem) { this$1.checkLVal(elem, bindingType, checkClashes); }
|
3499 | }
|
3500 | break
|
3501 |
|
3502 | case "AssignmentPattern":
|
3503 | this.checkLVal(expr.left, bindingType, checkClashes);
|
3504 | break
|
3505 |
|
3506 | case "RestElement":
|
3507 | this.checkLVal(expr.argument, bindingType, checkClashes);
|
3508 | break
|
3509 |
|
3510 | case "ParenthesizedExpression":
|
3511 | this.checkLVal(expr.expression, bindingType, checkClashes);
|
3512 | break
|
3513 |
|
3514 | default:
|
3515 | this.raise(expr.start, (bindingType ? "Binding" : "Assigning to") + " rvalue");
|
3516 | }
|
3517 | };
|
3518 |
|
3519 |
|
3520 |
|
3521 |
|
3522 |
|
3523 |
|
3524 |
|
3525 |
|
3526 |
|
3527 |
|
3528 |
|
3529 |
|
3530 |
|
3531 |
|
3532 |
|
3533 |
|
3534 |
|
3535 |
|
3536 |
|
3537 | var pp$3 = Parser.prototype;
|
3538 |
|
3539 |
|
3540 |
|
3541 |
|
3542 |
|
3543 |
|
3544 | pp$3.checkPropClash = function(prop, propHash) {
|
3545 | if (this.options.ecmaVersion >= 6 && (prop.computed || prop.method || prop.shorthand))
|
3546 | { return }
|
3547 | var key = prop.key;
|
3548 | var name;
|
3549 | switch (key.type) {
|
3550 | case "Identifier": name = key.name; break
|
3551 | case "Literal": name = String(key.value); break
|
3552 | default: return
|
3553 | }
|
3554 | var kind = prop.kind;
|
3555 | if (this.options.ecmaVersion >= 6) {
|
3556 | if (name === "__proto__" && kind === "init") {
|
3557 | if (propHash.proto) { this.raiseRecoverable(key.start, "Redefinition of __proto__ property"); }
|
3558 | propHash.proto = true;
|
3559 | }
|
3560 | return
|
3561 | }
|
3562 | name = "$" + name;
|
3563 | var other = propHash[name];
|
3564 | if (other) {
|
3565 | var redefinition;
|
3566 | if (kind === "init") {
|
3567 | redefinition = this.strict && other.init || other.get || other.set;
|
3568 | } else {
|
3569 | redefinition = other.init || other[kind];
|
3570 | }
|
3571 | if (redefinition)
|
3572 | { this.raiseRecoverable(key.start, "Redefinition of property"); }
|
3573 | } else {
|
3574 | other = propHash[name] = {
|
3575 | init: false,
|
3576 | get: false,
|
3577 | set: false
|
3578 | };
|
3579 | }
|
3580 | other[kind] = true;
|
3581 | };
|
3582 |
|
3583 | // ### Expression parsing
|
3584 |
|
3585 | // These nest, from the most general expression type at the top to
|
3586 | // 'atomic', nondivisible expression types at the bottom. Most of
|
3587 | // the functions will simply let the function(s) below them parse,
|
3588 | // and, *if* the syntactic construct they handle is present, wrap
|
3589 | // the AST node that the inner parser gave them in another node.
|
3590 |
|
3591 | // Parse a full expression. The optional arguments are used to
|
3592 | // forbid the `in` operator (in for loops initalization expressions)
|
3593 | // and provide reference for storing '=' operator inside shorthand
|
3594 | // property assignment in contexts where both object expression
|
3595 | // and object pattern might appear (so it's possible to raise
|
3596 | // delayed syntax error at correct position).
|
3597 |
|
3598 | pp$3.parseExpression = function(noIn, refDestructuringErrors) {
|
3599 | var this$1 = this;
|
3600 |
|
3601 | var startPos = this.start, startLoc = this.startLoc;
|
3602 | var expr = this.parseMaybeAssign(noIn, refDestructuringErrors);
|
3603 | if (this.type === types.comma) {
|
3604 | var node = this.startNodeAt(startPos, startLoc);
|
3605 | node.expressions = [expr];
|
3606 | while (this.eat(types.comma)) { node.expressions.push(this$1.parseMaybeAssign(noIn, refDestructuringErrors)); }
|
3607 | return this.finishNode(node, "SequenceExpression")
|
3608 | }
|
3609 | return expr
|
3610 | };
|
3611 |
|
3612 |
|
3613 |
|
3614 |
|
3615 | pp$3.parseMaybeAssign = function(noIn, refDestructuringErrors, afterLeftParse) {
|
3616 | if (this.inGenerator && this.isContextual("yield")) { return this.parseYield() }
|
3617 |
|
3618 | var ownDestructuringErrors = false, oldParenAssign = -1, oldTrailingComma = -1;
|
3619 | if (refDestructuringErrors) {
|
3620 | oldParenAssign = refDestructuringErrors.parenthesizedAssign;
|
3621 | oldTrailingComma = refDestructuringErrors.trailingComma;
|
3622 | refDestructuringErrors.parenthesizedAssign = refDestructuringErrors.trailingComma = -1;
|
3623 | } else {
|
3624 | refDestructuringErrors = new DestructuringErrors;
|
3625 | ownDestructuringErrors = true;
|
3626 | }
|
3627 |
|
3628 | var startPos = this.start, startLoc = this.startLoc;
|
3629 | if (this.type == types.parenL || this.type == types.name)
|
3630 | { this.potentialArrowAt = this.start; }
|
3631 | var left = this.parseMaybeConditional(noIn, refDestructuringErrors);
|
3632 | if (afterLeftParse) { left = afterLeftParse.call(this, left, startPos, startLoc); }
|
3633 | if (this.type.isAssign) {
|
3634 | this.checkPatternErrors(refDestructuringErrors, true);
|
3635 | if (!ownDestructuringErrors) { DestructuringErrors.call(refDestructuringErrors); }
|
3636 | var node = this.startNodeAt(startPos, startLoc);
|
3637 | node.operator = this.value;
|
3638 | node.left = this.type === types.eq ? this.toAssignable(left) : left;
|
3639 | refDestructuringErrors.shorthandAssign = -1;
|
3640 | this.checkLVal(left);
|
3641 | this.next();
|
3642 | node.right = this.parseMaybeAssign(noIn);
|
3643 | return this.finishNode(node, "AssignmentExpression")
|
3644 | } else {
|
3645 | if (ownDestructuringErrors) { this.checkExpressionErrors(refDestructuringErrors, true); }
|
3646 | }
|
3647 | if (oldParenAssign > -1) { refDestructuringErrors.parenthesizedAssign = oldParenAssign; }
|
3648 | if (oldTrailingComma > -1) { refDestructuringErrors.trailingComma = oldTrailingComma; }
|
3649 | return left
|
3650 | };
|
3651 |
|
3652 |
|
3653 |
|
3654 | pp$3.parseMaybeConditional = function(noIn, refDestructuringErrors) {
|
3655 | var startPos = this.start, startLoc = this.startLoc;
|
3656 | var expr = this.parseExprOps(noIn, refDestructuringErrors);
|
3657 | if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
|
3658 | if (this.eat(types.question)) {
|
3659 | var node = this.startNodeAt(startPos, startLoc);
|
3660 | node.test = expr;
|
3661 | node.consequent = this.parseMaybeAssign();
|
3662 | this.expect(types.colon);
|
3663 | node.alternate = this.parseMaybeAssign(noIn);
|
3664 | return this.finishNode(node, "ConditionalExpression")
|
3665 | }
|
3666 | return expr
|
3667 | };
|
3668 |
|
3669 |
|
3670 |
|
3671 | pp$3.parseExprOps = function(noIn, refDestructuringErrors) {
|
3672 | var startPos = this.start, startLoc = this.startLoc;
|
3673 | var expr = this.parseMaybeUnary(refDestructuringErrors, false);
|
3674 | if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
|
3675 | return expr.start == startPos && expr.type === "ArrowFunctionExpression" ? expr : this.parseExprOp(expr, startPos, startLoc, -1, noIn)
|
3676 | };
|
3677 |
|
3678 |
|
3679 |
|
3680 |
|
3681 |
|
3682 |
|
3683 |
|
3684 | pp$3.parseExprOp = function(left, leftStartPos, leftStartLoc, minPrec, noIn) {
|
3685 | var prec = this.type.binop;
|
3686 | if (prec != null && (!noIn || this.type !== types._in)) {
|
3687 | if (prec > minPrec) {
|
3688 | var logical = this.type === types.logicalOR || this.type === types.logicalAND;
|
3689 | var op = this.value;
|
3690 | this.next();
|
3691 | var startPos = this.start, startLoc = this.startLoc;
|
3692 | var right = this.parseExprOp(this.parseMaybeUnary(null, false), startPos, startLoc, prec, noIn);
|
3693 | var node = this.buildBinary(leftStartPos, leftStartLoc, left, right, op, logical);
|
3694 | return this.parseExprOp(node, leftStartPos, leftStartLoc, minPrec, noIn)
|
3695 | }
|
3696 | }
|
3697 | return left
|
3698 | };
|
3699 |
|
3700 | pp$3.buildBinary = function(startPos, startLoc, left, right, op, logical) {
|
3701 | var node = this.startNodeAt(startPos, startLoc);
|
3702 | node.left = left;
|
3703 | node.operator = op;
|
3704 | node.right = right;
|
3705 | return this.finishNode(node, logical ? "LogicalExpression" : "BinaryExpression")
|
3706 | };
|
3707 |
|
3708 |
|
3709 |
|
3710 | pp$3.parseMaybeUnary = function(refDestructuringErrors, sawUnary) {
|
3711 | var this$1 = this;
|
3712 |
|
3713 | var startPos = this.start, startLoc = this.startLoc, expr;
|
3714 | if (this.inAsync && this.isContextual("await")) {
|
3715 | expr = this.parseAwait(refDestructuringErrors);
|
3716 | sawUnary = true;
|
3717 | } else if (this.type.prefix) {
|
3718 | var node = this.startNode(), update = this.type === types.incDec;
|
3719 | node.operator = this.value;
|
3720 | node.prefix = true;
|
3721 | this.next();
|
3722 | node.argument = this.parseMaybeUnary(null, true);
|
3723 | this.checkExpressionErrors(refDestructuringErrors, true);
|
3724 | if (update) { this.checkLVal(node.argument); }
|
3725 | else if (this.strict && node.operator === "delete" &&
|
3726 | node.argument.type === "Identifier")
|
3727 | { this.raiseRecoverable(node.start, "Deleting local variable in strict mode"); }
|
3728 | else { sawUnary = true; }
|
3729 | expr = this.finishNode(node, update ? "UpdateExpression" : "UnaryExpression");
|
3730 | } else {
|
3731 | expr = this.parseExprSubscripts(refDestructuringErrors);
|
3732 | if (this.checkExpressionErrors(refDestructuringErrors)) { return expr }
|
3733 | while (this.type.postfix && !this.canInsertSemicolon()) {
|
3734 | var node$1 = this$1.startNodeAt(startPos, startLoc);
|
3735 | node$1.operator = this$1.value;
|
3736 | node$1.prefix = false;
|
3737 | node$1.argument = expr;
|
3738 | this$1.checkLVal(expr);
|
3739 | this$1.next();
|
3740 | expr = this$1.finishNode(node$1, "UpdateExpression");
|
3741 | }
|
3742 | }
|
3743 |
|
3744 | if (!sawUnary && this.eat(types.starstar))
|
3745 | { return this.buildBinary(startPos, startLoc, expr, this.parseMaybeUnary(null, false), "**", false) }
|
3746 | else
|
3747 | { return expr }
|
3748 | };
|
3749 |
|
3750 |
|
3751 |
|
3752 | pp$3.parseExprSubscripts = function(refDestructuringErrors) {
|
3753 | var startPos = this.start, startLoc = this.startLoc;
|
3754 | var expr = this.parseExprAtom(refDestructuringErrors);
|
3755 | var skipArrowSubscripts = expr.type === "ArrowFunctionExpression" && this.input.slice(this.lastTokStart, this.lastTokEnd) !== ")";
|
3756 | if (this.checkExpressionErrors(refDestructuringErrors) || skipArrowSubscripts) { return expr }
|
3757 | var result = this.parseSubscripts(expr, startPos, startLoc);
|
3758 | if (refDestructuringErrors && result.type === "MemberExpression") {
|
3759 | if (refDestructuringErrors.parenthesizedAssign >= result.start) { refDestructuringErrors.parenthesizedAssign = -1; }
|
3760 | if (refDestructuringErrors.parenthesizedBind >= result.start) { refDestructuringErrors.parenthesizedBind = -1; }
|
3761 | }
|
3762 | return result
|
3763 | };
|
3764 |
|
3765 | pp$3.parseSubscripts = function(base, startPos, startLoc, noCalls) {
|
3766 | var this$1 = this;
|
3767 |
|
3768 | var maybeAsyncArrow = this.options.ecmaVersion >= 8 && base.type === "Identifier" && base.name === "async" &&
|
3769 | this.lastTokEnd == base.end && !this.canInsertSemicolon();
|
3770 | for (var computed = (void 0);;) {
|
3771 | if ((computed = this$1.eat(types.bracketL)) || this$1.eat(types.dot)) {
|
3772 | var node = this$1.startNodeAt(startPos, startLoc);
|
3773 | node.object = base;
|
3774 | node.property = computed ? this$1.parseExpression() : this$1.parseIdent(true);
|
3775 | node.computed = !!computed;
|
3776 | if (computed) { this$1.expect(types.bracketR); }
|
3777 | base = this$1.finishNode(node, "MemberExpression");
|
3778 | } else if (!noCalls && this$1.eat(types.parenL)) {
|
3779 | var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this$1.yieldPos, oldAwaitPos = this$1.awaitPos;
|
3780 | this$1.yieldPos = 0;
|
3781 | this$1.awaitPos = 0;
|
3782 | var exprList = this$1.parseExprList(types.parenR, this$1.options.ecmaVersion >= 8, false, refDestructuringErrors);
|
3783 | if (maybeAsyncArrow && !this$1.canInsertSemicolon() && this$1.eat(types.arrow)) {
|
3784 | this$1.checkPatternErrors(refDestructuringErrors, false);
|
3785 | this$1.checkYieldAwaitInDefaultParams();
|
3786 | this$1.yieldPos = oldYieldPos;
|
3787 | this$1.awaitPos = oldAwaitPos;
|
3788 | return this$1.parseArrowExpression(this$1.startNodeAt(startPos, startLoc), exprList, true)
|
3789 | }
|
3790 | this$1.checkExpressionErrors(refDestructuringErrors, true);
|
3791 | this$1.yieldPos = oldYieldPos || this$1.yieldPos;
|
3792 | this$1.awaitPos = oldAwaitPos || this$1.awaitPos;
|
3793 | var node$1 = this$1.startNodeAt(startPos, startLoc);
|
3794 | node$1.callee = base;
|
3795 | node$1.arguments = exprList;
|
3796 | base = this$1.finishNode(node$1, "CallExpression");
|
3797 | } else if (this$1.type === types.backQuote) {
|
3798 | var node$2 = this$1.startNodeAt(startPos, startLoc);
|
3799 | node$2.tag = base;
|
3800 | node$2.quasi = this$1.parseTemplate({isTagged: true});
|
3801 | base = this$1.finishNode(node$2, "TaggedTemplateExpression");
|
3802 | } else {
|
3803 | return base
|
3804 | }
|
3805 | }
|
3806 | };
|
3807 |
|
3808 |
|
3809 |
|
3810 |
|
3811 |
|
3812 |
|
3813 | pp$3.parseExprAtom = function(refDestructuringErrors) {
|
3814 | var node, canBeArrow = this.potentialArrowAt == this.start;
|
3815 | switch (this.type) {
|
3816 | case types._super:
|
3817 | if (!this.inFunction)
|
3818 | { this.raise(this.start, "'super' outside of function or class"); }
|
3819 |
|
3820 | case types._this:
|
3821 | var type = this.type === types._this ? "ThisExpression" : "Super";
|
3822 | node = this.startNode();
|
3823 | this.next();
|
3824 | return this.finishNode(node, type)
|
3825 |
|
3826 | case types.name:
|
3827 | var startPos = this.start, startLoc = this.startLoc;
|
3828 | var id = this.parseIdent(this.type !== types.name);
|
3829 | if (this.options.ecmaVersion >= 8 && id.name === "async" && !this.canInsertSemicolon() && this.eat(types._function))
|
3830 | { return this.parseFunction(this.startNodeAt(startPos, startLoc), false, false, true) }
|
3831 | if (canBeArrow && !this.canInsertSemicolon()) {
|
3832 | if (this.eat(types.arrow))
|
3833 | { return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], false) }
|
3834 | if (this.options.ecmaVersion >= 8 && id.name === "async" && this.type === types.name) {
|
3835 | id = this.parseIdent();
|
3836 | if (this.canInsertSemicolon() || !this.eat(types.arrow))
|
3837 | { this.unexpected(); }
|
3838 | return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), [id], true)
|
3839 | }
|
3840 | }
|
3841 | return id
|
3842 |
|
3843 | case types.regexp:
|
3844 | var value = this.value;
|
3845 | node = this.parseLiteral(value.value);
|
3846 | node.regex = {pattern: value.pattern, flags: value.flags};
|
3847 | return node
|
3848 |
|
3849 | case types.num: case types.string:
|
3850 | return this.parseLiteral(this.value)
|
3851 |
|
3852 | case types._null: case types._true: case types._false:
|
3853 | node = this.startNode();
|
3854 | node.value = this.type === types._null ? null : this.type === types._true;
|
3855 | node.raw = this.type.keyword;
|
3856 | this.next();
|
3857 | return this.finishNode(node, "Literal")
|
3858 |
|
3859 | case types.parenL:
|
3860 | var start = this.start, expr = this.parseParenAndDistinguishExpression(canBeArrow);
|
3861 | if (refDestructuringErrors) {
|
3862 | if (refDestructuringErrors.parenthesizedAssign < 0 && !this.isSimpleAssignTarget(expr))
|
3863 | { refDestructuringErrors.parenthesizedAssign = start; }
|
3864 | if (refDestructuringErrors.parenthesizedBind < 0)
|
3865 | { refDestructuringErrors.parenthesizedBind = start; }
|
3866 | }
|
3867 | return expr
|
3868 |
|
3869 | case types.bracketL:
|
3870 | node = this.startNode();
|
3871 | this.next();
|
3872 | node.elements = this.parseExprList(types.bracketR, true, true, refDestructuringErrors);
|
3873 | return this.finishNode(node, "ArrayExpression")
|
3874 |
|
3875 | case types.braceL:
|
3876 | return this.parseObj(false, refDestructuringErrors)
|
3877 |
|
3878 | case types._function:
|
3879 | node = this.startNode();
|
3880 | this.next();
|
3881 | return this.parseFunction(node, false)
|
3882 |
|
3883 | case types._class:
|
3884 | return this.parseClass(this.startNode(), false)
|
3885 |
|
3886 | case types._new:
|
3887 | return this.parseNew()
|
3888 |
|
3889 | case types.backQuote:
|
3890 | return this.parseTemplate()
|
3891 |
|
3892 | default:
|
3893 | this.unexpected();
|
3894 | }
|
3895 | };
|
3896 |
|
3897 | pp$3.parseLiteral = function(value) {
|
3898 | var node = this.startNode();
|
3899 | node.value = value;
|
3900 | node.raw = this.input.slice(this.start, this.end);
|
3901 | this.next();
|
3902 | return this.finishNode(node, "Literal")
|
3903 | };
|
3904 |
|
3905 | pp$3.parseParenExpression = function() {
|
3906 | this.expect(types.parenL);
|
3907 | var val = this.parseExpression();
|
3908 | this.expect(types.parenR);
|
3909 | return val
|
3910 | };
|
3911 |
|
3912 | pp$3.parseParenAndDistinguishExpression = function(canBeArrow) {
|
3913 | var this$1 = this;
|
3914 |
|
3915 | var startPos = this.start, startLoc = this.startLoc, val, allowTrailingComma = this.options.ecmaVersion >= 8;
|
3916 | if (this.options.ecmaVersion >= 6) {
|
3917 | this.next();
|
3918 |
|
3919 | var innerStartPos = this.start, innerStartLoc = this.startLoc;
|
3920 | var exprList = [], first = true, lastIsComma = false;
|
3921 | var refDestructuringErrors = new DestructuringErrors, oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, spreadStart, innerParenStart;
|
3922 | this.yieldPos = 0;
|
3923 | this.awaitPos = 0;
|
3924 | while (this.type !== types.parenR) {
|
3925 | first ? first = false : this$1.expect(types.comma);
|
3926 | if (allowTrailingComma && this$1.afterTrailingComma(types.parenR, true)) {
|
3927 | lastIsComma = true;
|
3928 | break
|
3929 | } else if (this$1.type === types.ellipsis) {
|
3930 | spreadStart = this$1.start;
|
3931 | exprList.push(this$1.parseParenItem(this$1.parseRestBinding()));
|
3932 | if (this$1.type === types.comma) { this$1.raise(this$1.start, "Comma is not permitted after the rest element"); }
|
3933 | break
|
3934 | } else {
|
3935 | if (this$1.type === types.parenL && !innerParenStart) {
|
3936 | innerParenStart = this$1.start;
|
3937 | }
|
3938 | exprList.push(this$1.parseMaybeAssign(false, refDestructuringErrors, this$1.parseParenItem));
|
3939 | }
|
3940 | }
|
3941 | var innerEndPos = this.start, innerEndLoc = this.startLoc;
|
3942 | this.expect(types.parenR);
|
3943 |
|
3944 | if (canBeArrow && !this.canInsertSemicolon() && this.eat(types.arrow)) {
|
3945 | this.checkPatternErrors(refDestructuringErrors, false);
|
3946 | this.checkYieldAwaitInDefaultParams();
|
3947 | if (innerParenStart) { this.unexpected(innerParenStart); }
|
3948 | this.yieldPos = oldYieldPos;
|
3949 | this.awaitPos = oldAwaitPos;
|
3950 | return this.parseParenArrowList(startPos, startLoc, exprList)
|
3951 | }
|
3952 |
|
3953 | if (!exprList.length || lastIsComma) { this.unexpected(this.lastTokStart); }
|
3954 | if (spreadStart) { this.unexpected(spreadStart); }
|
3955 | this.checkExpressionErrors(refDestructuringErrors, true);
|
3956 | this.yieldPos = oldYieldPos || this.yieldPos;
|
3957 | this.awaitPos = oldAwaitPos || this.awaitPos;
|
3958 |
|
3959 | if (exprList.length > 1) {
|
3960 | val = this.startNodeAt(innerStartPos, innerStartLoc);
|
3961 | val.expressions = exprList;
|
3962 | this.finishNodeAt(val, "SequenceExpression", innerEndPos, innerEndLoc);
|
3963 | } else {
|
3964 | val = exprList[0];
|
3965 | }
|
3966 | } else {
|
3967 | val = this.parseParenExpression();
|
3968 | }
|
3969 |
|
3970 | if (this.options.preserveParens) {
|
3971 | var par = this.startNodeAt(startPos, startLoc);
|
3972 | par.expression = val;
|
3973 | return this.finishNode(par, "ParenthesizedExpression")
|
3974 | } else {
|
3975 | return val
|
3976 | }
|
3977 | };
|
3978 |
|
3979 | pp$3.parseParenItem = function(item) {
|
3980 | return item
|
3981 | };
|
3982 |
|
3983 | pp$3.parseParenArrowList = function(startPos, startLoc, exprList) {
|
3984 | return this.parseArrowExpression(this.startNodeAt(startPos, startLoc), exprList)
|
3985 | };
|
3986 |
|
3987 |
|
3988 |
|
3989 |
|
3990 |
|
3991 |
|
3992 |
|
3993 | var empty$1 = [];
|
3994 |
|
3995 | pp$3.parseNew = function() {
|
3996 | var node = this.startNode();
|
3997 | var meta = this.parseIdent(true);
|
3998 | if (this.options.ecmaVersion >= 6 && this.eat(types.dot)) {
|
3999 | node.meta = meta;
|
4000 | node.property = this.parseIdent(true);
|
4001 | if (node.property.name !== "target")
|
4002 | { this.raiseRecoverable(node.property.start, "The only valid meta property for new is new.target"); }
|
4003 | if (!this.inFunction)
|
4004 | { this.raiseRecoverable(node.start, "new.target can only be used in functions"); }
|
4005 | return this.finishNode(node, "MetaProperty")
|
4006 | }
|
4007 | var startPos = this.start, startLoc = this.startLoc;
|
4008 | node.callee = this.parseSubscripts(this.parseExprAtom(), startPos, startLoc, true);
|
4009 | if (this.eat(types.parenL)) { node.arguments = this.parseExprList(types.parenR, this.options.ecmaVersion >= 8, false); }
|
4010 | else { node.arguments = empty$1; }
|
4011 | return this.finishNode(node, "NewExpression")
|
4012 | };
|
4013 |
|
4014 |
|
4015 |
|
4016 | pp$3.parseTemplateElement = function(ref) {
|
4017 | var isTagged = ref.isTagged;
|
4018 |
|
4019 | var elem = this.startNode();
|
4020 | if (this.type === types.invalidTemplate) {
|
4021 | if (!isTagged) {
|
4022 | this.raiseRecoverable(this.start, "Bad escape sequence in untagged template literal");
|
4023 | }
|
4024 | elem.value = {
|
4025 | raw: this.value,
|
4026 | cooked: null
|
4027 | };
|
4028 | } else {
|
4029 | elem.value = {
|
4030 | raw: this.input.slice(this.start, this.end).replace(/\r\n?/g, "\n"),
|
4031 | cooked: this.value
|
4032 | };
|
4033 | }
|
4034 | this.next();
|
4035 | elem.tail = this.type === types.backQuote;
|
4036 | return this.finishNode(elem, "TemplateElement")
|
4037 | };
|
4038 |
|
4039 | pp$3.parseTemplate = function(ref) {
|
4040 | var this$1 = this;
|
4041 | if ( ref === void 0 ) { ref = {}; }
|
4042 | var isTagged = ref.isTagged; if ( isTagged === void 0 ) { isTagged = false; }
|
4043 |
|
4044 | var node = this.startNode();
|
4045 | this.next();
|
4046 | node.expressions = [];
|
4047 | var curElt = this.parseTemplateElement({isTagged: isTagged});
|
4048 | node.quasis = [curElt];
|
4049 | while (!curElt.tail) {
|
4050 | this$1.expect(types.dollarBraceL);
|
4051 | node.expressions.push(this$1.parseExpression());
|
4052 | this$1.expect(types.braceR);
|
4053 | node.quasis.push(curElt = this$1.parseTemplateElement({isTagged: isTagged}));
|
4054 | }
|
4055 | this.next();
|
4056 | return this.finishNode(node, "TemplateLiteral")
|
4057 | };
|
4058 |
|
4059 |
|
4060 |
|
4061 | pp$3.isAsyncProp = function(prop) {
|
4062 | return !prop.computed && prop.key.type === "Identifier" && prop.key.name === "async" &&
|
4063 | (this.type === types.name || this.type === types.num || this.type === types.string || this.type === types.bracketL) &&
|
4064 | !lineBreak.test(this.input.slice(this.lastTokEnd, this.start))
|
4065 | };
|
4066 |
|
4067 | pp$3.parseObj = function(isPattern, refDestructuringErrors) {
|
4068 | var this$1 = this;
|
4069 |
|
4070 | var node = this.startNode(), first = true, propHash = {};
|
4071 | node.properties = [];
|
4072 | this.next();
|
4073 | while (!this.eat(types.braceR)) {
|
4074 | if (!first) {
|
4075 | this$1.expect(types.comma);
|
4076 | if (this$1.afterTrailingComma(types.braceR)) { break }
|
4077 | } else { first = false; }
|
4078 |
|
4079 | var prop = this$1.startNode(), isGenerator = (void 0), isAsync = (void 0), startPos = (void 0), startLoc = (void 0);
|
4080 | if (this$1.options.ecmaVersion >= 6) {
|
4081 | prop.method = false;
|
4082 | prop.shorthand = false;
|
4083 | if (isPattern || refDestructuringErrors) {
|
4084 | startPos = this$1.start;
|
4085 | startLoc = this$1.startLoc;
|
4086 | }
|
4087 | if (!isPattern)
|
4088 | { isGenerator = this$1.eat(types.star); }
|
4089 | }
|
4090 | this$1.parsePropertyName(prop);
|
4091 | if (!isPattern && this$1.options.ecmaVersion >= 8 && !isGenerator && this$1.isAsyncProp(prop)) {
|
4092 | isAsync = true;
|
4093 | this$1.parsePropertyName(prop, refDestructuringErrors);
|
4094 | } else {
|
4095 | isAsync = false;
|
4096 | }
|
4097 | this$1.parsePropertyValue(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors);
|
4098 | this$1.checkPropClash(prop, propHash);
|
4099 | node.properties.push(this$1.finishNode(prop, "Property"));
|
4100 | }
|
4101 | return this.finishNode(node, isPattern ? "ObjectPattern" : "ObjectExpression")
|
4102 | };
|
4103 |
|
4104 | pp$3.parsePropertyValue = function(prop, isPattern, isGenerator, isAsync, startPos, startLoc, refDestructuringErrors) {
|
4105 | if ((isGenerator || isAsync) && this.type === types.colon)
|
4106 | { this.unexpected(); }
|
4107 |
|
4108 | if (this.eat(types.colon)) {
|
4109 | prop.value = isPattern ? this.parseMaybeDefault(this.start, this.startLoc) : this.parseMaybeAssign(false, refDestructuringErrors);
|
4110 | prop.kind = "init";
|
4111 | } else if (this.options.ecmaVersion >= 6 && this.type === types.parenL) {
|
4112 | if (isPattern) { this.unexpected(); }
|
4113 | prop.kind = "init";
|
4114 | prop.method = true;
|
4115 | prop.value = this.parseMethod(isGenerator, isAsync);
|
4116 | } else if (this.options.ecmaVersion >= 5 && !prop.computed && prop.key.type === "Identifier" &&
|
4117 | (prop.key.name === "get" || prop.key.name === "set") &&
|
4118 | (this.type != types.comma && this.type != types.braceR)) {
|
4119 | if (isGenerator || isAsync || isPattern) { this.unexpected(); }
|
4120 | prop.kind = prop.key.name;
|
4121 | this.parsePropertyName(prop);
|
4122 | prop.value = this.parseMethod(false);
|
4123 | var paramCount = prop.kind === "get" ? 0 : 1;
|
4124 | if (prop.value.params.length !== paramCount) {
|
4125 | var start = prop.value.start;
|
4126 | if (prop.kind === "get")
|
4127 | { this.raiseRecoverable(start, "getter should have no params"); }
|
4128 | else
|
4129 | { this.raiseRecoverable(start, "setter should have exactly one param"); }
|
4130 | } else {
|
4131 | if (prop.kind === "set" && prop.value.params[0].type === "RestElement")
|
4132 | { this.raiseRecoverable(prop.value.params[0].start, "Setter cannot use rest params"); }
|
4133 | }
|
4134 | } else if (this.options.ecmaVersion >= 6 && !prop.computed && prop.key.type === "Identifier") {
|
4135 | this.checkUnreserved(prop.key);
|
4136 | prop.kind = "init";
|
4137 | if (isPattern) {
|
4138 | prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
|
4139 | } else if (this.type === types.eq && refDestructuringErrors) {
|
4140 | if (refDestructuringErrors.shorthandAssign < 0)
|
4141 | { refDestructuringErrors.shorthandAssign = this.start; }
|
4142 | prop.value = this.parseMaybeDefault(startPos, startLoc, prop.key);
|
4143 | } else {
|
4144 | prop.value = prop.key;
|
4145 | }
|
4146 | prop.shorthand = true;
|
4147 | } else { this.unexpected(); }
|
4148 | };
|
4149 |
|
4150 | pp$3.parsePropertyName = function(prop) {
|
4151 | if (this.options.ecmaVersion >= 6) {
|
4152 | if (this.eat(types.bracketL)) {
|
4153 | prop.computed = true;
|
4154 | prop.key = this.parseMaybeAssign();
|
4155 | this.expect(types.bracketR);
|
4156 | return prop.key
|
4157 | } else {
|
4158 | prop.computed = false;
|
4159 | }
|
4160 | }
|
4161 | return prop.key = this.type === types.num || this.type === types.string ? this.parseExprAtom() : this.parseIdent(true)
|
4162 | };
|
4163 |
|
4164 |
|
4165 |
|
4166 | pp$3.initFunction = function(node) {
|
4167 | node.id = null;
|
4168 | if (this.options.ecmaVersion >= 6) {
|
4169 | node.generator = false;
|
4170 | node.expression = false;
|
4171 | }
|
4172 | if (this.options.ecmaVersion >= 8)
|
4173 | { node.async = false; }
|
4174 | };
|
4175 |
|
4176 |
|
4177 |
|
4178 | pp$3.parseMethod = function(isGenerator, isAsync) {
|
4179 | var node = this.startNode(), oldInGen = this.inGenerator, oldInAsync = this.inAsync,
|
4180 | oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
|
4181 |
|
4182 | this.initFunction(node);
|
4183 | if (this.options.ecmaVersion >= 6)
|
4184 | { node.generator = isGenerator; }
|
4185 | if (this.options.ecmaVersion >= 8)
|
4186 | { node.async = !!isAsync; }
|
4187 |
|
4188 | this.inGenerator = node.generator;
|
4189 | this.inAsync = node.async;
|
4190 | this.yieldPos = 0;
|
4191 | this.awaitPos = 0;
|
4192 | this.inFunction = true;
|
4193 | this.enterFunctionScope();
|
4194 |
|
4195 | this.expect(types.parenL);
|
4196 | node.params = this.parseBindingList(types.parenR, false, this.options.ecmaVersion >= 8);
|
4197 | this.checkYieldAwaitInDefaultParams();
|
4198 | this.parseFunctionBody(node, false);
|
4199 |
|
4200 | this.inGenerator = oldInGen;
|
4201 | this.inAsync = oldInAsync;
|
4202 | this.yieldPos = oldYieldPos;
|
4203 | this.awaitPos = oldAwaitPos;
|
4204 | this.inFunction = oldInFunc;
|
4205 | return this.finishNode(node, "FunctionExpression")
|
4206 | };
|
4207 |
|
4208 |
|
4209 |
|
4210 | pp$3.parseArrowExpression = function(node, params, isAsync) {
|
4211 | var oldInGen = this.inGenerator, oldInAsync = this.inAsync,
|
4212 | oldYieldPos = this.yieldPos, oldAwaitPos = this.awaitPos, oldInFunc = this.inFunction;
|
4213 |
|
4214 | this.enterFunctionScope();
|
4215 | this.initFunction(node);
|
4216 | if (this.options.ecmaVersion >= 8)
|
4217 | { node.async = !!isAsync; }
|
4218 |
|
4219 | this.inGenerator = false;
|
4220 | this.inAsync = node.async;
|
4221 | this.yieldPos = 0;
|
4222 | this.awaitPos = 0;
|
4223 | this.inFunction = true;
|
4224 |
|
4225 | node.params = this.toAssignableList(params, true);
|
4226 | this.parseFunctionBody(node, true);
|
4227 |
|
4228 | this.inGenerator = oldInGen;
|
4229 | this.inAsync = oldInAsync;
|
4230 | this.yieldPos = oldYieldPos;
|
4231 | this.awaitPos = oldAwaitPos;
|
4232 | this.inFunction = oldInFunc;
|
4233 | return this.finishNode(node, "ArrowFunctionExpression")
|
4234 | };
|
4235 |
|
4236 |
|
4237 |
|
4238 | pp$3.parseFunctionBody = function(node, isArrowFunction) {
|
4239 | var isExpression = isArrowFunction && this.type !== types.braceL;
|
4240 | var oldStrict = this.strict, useStrict = false;
|
4241 |
|
4242 | if (isExpression) {
|
4243 | node.body = this.parseMaybeAssign();
|
4244 | node.expression = true;
|
4245 | this.checkParams(node, false);
|
4246 | } else {
|
4247 | var nonSimple = this.options.ecmaVersion >= 7 && !this.isSimpleParamList(node.params);
|
4248 | if (!oldStrict || nonSimple) {
|
4249 | useStrict = this.strictDirective(this.end);
|
4250 |
|
4251 |
|
4252 |
|
4253 | if (useStrict && nonSimple)
|
4254 | { this.raiseRecoverable(node.start, "Illegal 'use strict' directive in function with non-simple parameter list"); }
|
4255 | }
|
4256 |
|
4257 |
|
4258 | var oldLabels = this.labels;
|
4259 | this.labels = [];
|
4260 | if (useStrict) { this.strict = true; }
|
4261 |
|
4262 |
|
4263 |
|
4264 | this.checkParams(node, !oldStrict && !useStrict && !isArrowFunction && this.isSimpleParamList(node.params));
|
4265 | node.body = this.parseBlock(false);
|
4266 | node.expression = false;
|
4267 | this.labels = oldLabels;
|
4268 | }
|
4269 | this.exitFunctionScope();
|
4270 |
|
4271 | if (this.strict && node.id) {
|
4272 |
|
4273 | this.checkLVal(node.id, "none");
|
4274 | }
|
4275 | this.strict = oldStrict;
|
4276 | };
|
4277 |
|
4278 | pp$3.isSimpleParamList = function(params) {
|
4279 | for (var i = 0, list = params; i < list.length; i += 1)
|
4280 | {
|
4281 | var param = list[i];
|
4282 |
|
4283 | if (param.type !== "Identifier") { return false
|
4284 | } }
|
4285 | return true
|
4286 | };
|
4287 |
|
4288 |
|
4289 |
|
4290 |
|
4291 | pp$3.checkParams = function(node, allowDuplicates) {
|
4292 | var this$1 = this;
|
4293 |
|
4294 | var nameHash = {};
|
4295 | for (var i = 0, list = node.params; i < list.length; i += 1)
|
4296 | {
|
4297 | var param = list[i];
|
4298 |
|
4299 | this$1.checkLVal(param, "var", allowDuplicates ? null : nameHash);
|
4300 | }
|
4301 | };
|
4302 |
|
4303 |
|
4304 |
|
4305 |
|
4306 |
|
4307 |
|
4308 |
|
4309 | pp$3.parseExprList = function(close, allowTrailingComma, allowEmpty, refDestructuringErrors) {
|
4310 | var this$1 = this;
|
4311 |
|
4312 | var elts = [], first = true;
|
4313 | while (!this.eat(close)) {
|
4314 | if (!first) {
|
4315 | this$1.expect(types.comma);
|
4316 | if (allowTrailingComma && this$1.afterTrailingComma(close)) { break }
|
4317 | } else { first = false; }
|
4318 |
|
4319 | var elt = (void 0);
|
4320 | if (allowEmpty && this$1.type === types.comma)
|
4321 | { elt = null; }
|
4322 | else if (this$1.type === types.ellipsis) {
|
4323 | elt = this$1.parseSpread(refDestructuringErrors);
|
4324 | if (refDestructuringErrors && this$1.type === types.comma && refDestructuringErrors.trailingComma < 0)
|
4325 | { refDestructuringErrors.trailingComma = this$1.start; }
|
4326 | } else {
|
4327 | elt = this$1.parseMaybeAssign(false, refDestructuringErrors);
|
4328 | }
|
4329 | elts.push(elt);
|
4330 | }
|
4331 | return elts
|
4332 | };
|
4333 |
|
4334 |
|
4335 |
|
4336 |
|
4337 |
|
4338 | pp$3.checkUnreserved = function(ref) {
|
4339 | var start = ref.start;
|
4340 | var end = ref.end;
|
4341 | var name = ref.name;
|
4342 |
|
4343 | if (this.inGenerator && name === "yield")
|
4344 | { this.raiseRecoverable(start, "Can not use 'yield' as identifier inside a generator"); }
|
4345 | if (this.inAsync && name === "await")
|
4346 | { this.raiseRecoverable(start, "Can not use 'await' as identifier inside an async function"); }
|
4347 | if (this.isKeyword(name))
|
4348 | { this.raise(start, ("Unexpected keyword '" + name + "'")); }
|
4349 | if (this.options.ecmaVersion < 6 &&
|
4350 | this.input.slice(start, end).indexOf("\\") != -1) { return }
|
4351 | var re = this.strict ? this.reservedWordsStrict : this.reservedWords;
|
4352 | if (re.test(name))
|
4353 | { this.raiseRecoverable(start, ("The keyword '" + name + "' is reserved")); }
|
4354 | };
|
4355 |
|
4356 | pp$3.parseIdent = function(liberal, isBinding) {
|
4357 | var node = this.startNode();
|
4358 | if (liberal && this.options.allowReserved == "never") { liberal = false; }
|
4359 | if (this.type === types.name) {
|
4360 | node.name = this.value;
|
4361 | } else if (this.type.keyword) {
|
4362 | node.name = this.type.keyword;
|
4363 | } else {
|
4364 | this.unexpected();
|
4365 | }
|
4366 | this.next();
|
4367 | this.finishNode(node, "Identifier");
|
4368 | if (!liberal) { this.checkUnreserved(node); }
|
4369 | return node
|
4370 | };
|
4371 |
|
4372 |
|
4373 |
|
4374 | pp$3.parseYield = function() {
|
4375 | if (!this.yieldPos) { this.yieldPos = this.start; }
|
4376 |
|
4377 | var node = this.startNode();
|
4378 | this.next();
|
4379 | if (this.type == types.semi || this.canInsertSemicolon() || (this.type != types.star && !this.type.startsExpr)) {
|
4380 | node.delegate = false;
|
4381 | node.argument = null;
|
4382 | } else {
|
4383 | node.delegate = this.eat(types.star);
|
4384 | node.argument = this.parseMaybeAssign();
|
4385 | }
|
4386 | return this.finishNode(node, "YieldExpression")
|
4387 | };
|
4388 |
|
4389 | pp$3.parseAwait = function() {
|
4390 | if (!this.awaitPos) { this.awaitPos = this.start; }
|
4391 |
|
4392 | var node = this.startNode();
|
4393 | this.next();
|
4394 | node.argument = this.parseMaybeUnary(null, true);
|
4395 | return this.finishNode(node, "AwaitExpression")
|
4396 | };
|
4397 |
|
4398 | var pp$4 = Parser.prototype;
|
4399 |
|
4400 |
|
4401 |
|
4402 |
|
4403 |
|
4404 |
|
4405 |
|
4406 | pp$4.raise = function(pos, message) {
|
4407 | var loc = getLineInfo(this.input, pos);
|
4408 | message += " (" + loc.line + ":" + loc.column + ")";
|
4409 | var err = new SyntaxError(message);
|
4410 | err.pos = pos; err.loc = loc; err.raisedAt = this.pos;
|
4411 | throw err
|
4412 | };
|
4413 |
|
4414 | pp$4.raiseRecoverable = pp$4.raise;
|
4415 |
|
4416 | pp$4.curPosition = function() {
|
4417 | if (this.options.locations) {
|
4418 | return new Position(this.curLine, this.pos - this.lineStart)
|
4419 | }
|
4420 | };
|
4421 |
|
4422 | var pp$5 = Parser.prototype;
|
4423 |
|
4424 |
|
4425 | var assign$1 = Object.assign || function(target) {
|
4426 | var arguments$1 = arguments;
|
4427 |
|
4428 | var sources = [], len = arguments.length - 1;
|
4429 | while ( len-- > 0 ) { sources[ len ] = arguments$1[ len + 1 ]; }
|
4430 |
|
4431 | for (var i = 0, list = sources; i < list.length; i += 1) {
|
4432 | var source = list[i];
|
4433 |
|
4434 | for (var key in source) {
|
4435 | if (has(source, key)) {
|
4436 | target[key] = source[key];
|
4437 | }
|
4438 | }
|
4439 | }
|
4440 | return target
|
4441 | };
|
4442 |
|
4443 |
|
4444 |
|
4445 | pp$5.enterFunctionScope = function() {
|
4446 |
|
4447 |
|
4448 |
|
4449 |
|
4450 | this.scopeStack.push({var: {}, lexical: {}, childVar: {}, parentLexical: {}});
|
4451 | };
|
4452 |
|
4453 | pp$5.exitFunctionScope = function() {
|
4454 | this.scopeStack.pop();
|
4455 | };
|
4456 |
|
4457 | pp$5.enterLexicalScope = function() {
|
4458 | var parentScope = this.scopeStack[this.scopeStack.length - 1];
|
4459 | var childScope = {var: {}, lexical: {}, childVar: {}, parentLexical: {}};
|
4460 |
|
4461 | this.scopeStack.push(childScope);
|
4462 | assign$1(childScope.parentLexical, parentScope.lexical, parentScope.parentLexical);
|
4463 | };
|
4464 |
|
4465 | pp$5.exitLexicalScope = function() {
|
4466 | var childScope = this.scopeStack.pop();
|
4467 | var parentScope = this.scopeStack[this.scopeStack.length - 1];
|
4468 |
|
4469 | assign$1(parentScope.childVar, childScope.var, childScope.childVar);
|
4470 | };
|
4471 |
|
4472 |
|
4473 |
|
4474 |
|
4475 |
|
4476 | pp$5.canDeclareVarName = function(name) {
|
4477 | var currentScope = this.scopeStack[this.scopeStack.length - 1];
|
4478 |
|
4479 | return !has(currentScope.lexical, name) && !has(currentScope.parentLexical, name)
|
4480 | };
|
4481 |
|
4482 |
|
4483 |
|
4484 |
|
4485 |
|
4486 |
|
4487 | pp$5.canDeclareLexicalName = function(name) {
|
4488 | var currentScope = this.scopeStack[this.scopeStack.length - 1];
|
4489 |
|
4490 | return !has(currentScope.lexical, name) && !has(currentScope.var, name) && !has(currentScope.childVar, name)
|
4491 | };
|
4492 |
|
4493 | pp$5.declareVarName = function(name) {
|
4494 | this.scopeStack[this.scopeStack.length - 1].var[name] = true;
|
4495 | };
|
4496 |
|
4497 | pp$5.declareLexicalName = function(name) {
|
4498 | this.scopeStack[this.scopeStack.length - 1].lexical[name] = true;
|
4499 | };
|
4500 |
|
4501 | var Node = function Node(parser, pos, loc) {
|
4502 | this.type = "";
|
4503 | this.start = pos;
|
4504 | this.end = 0;
|
4505 | if (parser.options.locations)
|
4506 | { this.loc = new SourceLocation(parser, loc); }
|
4507 | if (parser.options.directSourceFile)
|
4508 | { this.sourceFile = parser.options.directSourceFile; }
|
4509 | if (parser.options.ranges)
|
4510 | { this.range = [pos, 0]; }
|
4511 | };
|
4512 |
|
4513 |
|
4514 |
|
4515 | var pp$6 = Parser.prototype;
|
4516 |
|
4517 | pp$6.startNode = function() {
|
4518 | return new Node(this, this.start, this.startLoc)
|
4519 | };
|
4520 |
|
4521 | pp$6.startNodeAt = function(pos, loc) {
|
4522 | return new Node(this, pos, loc)
|
4523 | };
|
4524 |
|
4525 |
|
4526 |
|
4527 | function finishNodeAt(node, type, pos, loc) {
|
4528 | node.type = type;
|
4529 | node.end = pos;
|
4530 | if (this.options.locations)
|
4531 | { node.loc.end = loc; }
|
4532 | if (this.options.ranges)
|
4533 | { node.range[1] = pos; }
|
4534 | return node
|
4535 | }
|
4536 |
|
4537 | pp$6.finishNode = function(node, type) {
|
4538 | return finishNodeAt.call(this, node, type, this.lastTokEnd, this.lastTokEndLoc)
|
4539 | };
|
4540 |
|
4541 |
|
4542 |
|
4543 | pp$6.finishNodeAt = function(node, type, pos, loc) {
|
4544 | return finishNodeAt.call(this, node, type, pos, loc)
|
4545 | };
|
4546 |
|
4547 |
|
4548 |
|
4549 |
|
4550 |
|
4551 | var TokContext = function TokContext(token, isExpr, preserveSpace, override, generator) {
|
4552 | this.token = token;
|
4553 | this.isExpr = !!isExpr;
|
4554 | this.preserveSpace = !!preserveSpace;
|
4555 | this.override = override;
|
4556 | this.generator = !!generator;
|
4557 | };
|
4558 |
|
4559 | var types$1 = {
|
4560 | b_stat: new TokContext("{", false),
|
4561 | b_expr: new TokContext("{", true),
|
4562 | b_tmpl: new TokContext("${", false),
|
4563 | p_stat: new TokContext("(", false),
|
4564 | p_expr: new TokContext("(", true),
|
4565 | q_tmpl: new TokContext("`", true, true, function (p) { return p.tryReadTemplateToken(); }),
|
4566 | f_stat: new TokContext("function", false),
|
4567 | f_expr: new TokContext("function", true),
|
4568 | f_expr_gen: new TokContext("function", true, false, null, true),
|
4569 | f_gen: new TokContext("function", false, false, null, true)
|
4570 | };
|
4571 |
|
4572 | var pp$7 = Parser.prototype;
|
4573 |
|
4574 | pp$7.initialContext = function() {
|
4575 | return [types$1.b_stat]
|
4576 | };
|
4577 |
|
4578 | pp$7.braceIsBlock = function(prevType) {
|
4579 | var parent = this.curContext();
|
4580 | if (parent === types$1.f_expr || parent === types$1.f_stat)
|
4581 | { return true }
|
4582 | if (prevType === types.colon && (parent === types$1.b_stat || parent === types$1.b_expr))
|
4583 | { return !parent.isExpr }
|
4584 |
|
4585 |
|
4586 |
|
4587 |
|
4588 | if (prevType === types._return || prevType == types.name && this.exprAllowed)
|
4589 | { return lineBreak.test(this.input.slice(this.lastTokEnd, this.start)) }
|
4590 | if (prevType === types._else || prevType === types.semi || prevType === types.eof || prevType === types.parenR || prevType == types.arrow)
|
4591 | { return true }
|
4592 | if (prevType == types.braceL)
|
4593 | { return parent === types$1.b_stat }
|
4594 | if (prevType == types._var || prevType == types.name)
|
4595 | { return false }
|
4596 | return !this.exprAllowed
|
4597 | };
|
4598 |
|
4599 | pp$7.inGeneratorContext = function() {
|
4600 | var this$1 = this;
|
4601 |
|
4602 | for (var i = this.context.length - 1; i >= 1; i--) {
|
4603 | var context = this$1.context[i];
|
4604 | if (context.token === "function")
|
4605 | { return context.generator }
|
4606 | }
|
4607 | return false
|
4608 | };
|
4609 |
|
4610 | pp$7.updateContext = function(prevType) {
|
4611 | var update, type = this.type;
|
4612 | if (type.keyword && prevType == types.dot)
|
4613 | { this.exprAllowed = false; }
|
4614 | else if (update = type.updateContext)
|
4615 | { update.call(this, prevType); }
|
4616 | else
|
4617 | { this.exprAllowed = type.beforeExpr; }
|
4618 | };
|
4619 |
|
4620 |
|
4621 |
|
4622 | types.parenR.updateContext = types.braceR.updateContext = function() {
|
4623 | if (this.context.length == 1) {
|
4624 | this.exprAllowed = true;
|
4625 | return
|
4626 | }
|
4627 | var out = this.context.pop();
|
4628 | if (out === types$1.b_stat && this.curContext().token === "function") {
|
4629 | out = this.context.pop();
|
4630 | }
|
4631 | this.exprAllowed = !out.isExpr;
|
4632 | };
|
4633 |
|
4634 | types.braceL.updateContext = function(prevType) {
|
4635 | this.context.push(this.braceIsBlock(prevType) ? types$1.b_stat : types$1.b_expr);
|
4636 | this.exprAllowed = true;
|
4637 | };
|
4638 |
|
4639 | types.dollarBraceL.updateContext = function() {
|
4640 | this.context.push(types$1.b_tmpl);
|
4641 | this.exprAllowed = true;
|
4642 | };
|
4643 |
|
4644 | types.parenL.updateContext = function(prevType) {
|
4645 | var statementParens = prevType === types._if || prevType === types._for || prevType === types._with || prevType === types._while;
|
4646 | this.context.push(statementParens ? types$1.p_stat : types$1.p_expr);
|
4647 | this.exprAllowed = true;
|
4648 | };
|
4649 |
|
4650 | types.incDec.updateContext = function() {
|
4651 |
|
4652 | };
|
4653 |
|
4654 | types._function.updateContext = types._class.updateContext = function(prevType) {
|
4655 | if (prevType.beforeExpr && prevType !== types.semi && prevType !== types._else &&
|
4656 | !((prevType === types.colon || prevType === types.braceL) && this.curContext() === types$1.b_stat))
|
4657 | { this.context.push(types$1.f_expr); }
|
4658 | else
|
4659 | { this.context.push(types$1.f_stat); }
|
4660 | this.exprAllowed = false;
|
4661 | };
|
4662 |
|
4663 | types.backQuote.updateContext = function() {
|
4664 | if (this.curContext() === types$1.q_tmpl)
|
4665 | { this.context.pop(); }
|
4666 | else
|
4667 | { this.context.push(types$1.q_tmpl); }
|
4668 | this.exprAllowed = false;
|
4669 | };
|
4670 |
|
4671 | types.star.updateContext = function(prevType) {
|
4672 | if (prevType == types._function) {
|
4673 | var index = this.context.length - 1;
|
4674 | if (this.context[index] === types$1.f_expr)
|
4675 | { this.context[index] = types$1.f_expr_gen; }
|
4676 | else
|
4677 | { this.context[index] = types$1.f_gen; }
|
4678 | }
|
4679 | this.exprAllowed = true;
|
4680 | };
|
4681 |
|
4682 | types.name.updateContext = function(prevType) {
|
4683 | var allowed = false;
|
4684 | if (this.options.ecmaVersion >= 6) {
|
4685 | if (this.value == "of" && !this.exprAllowed ||
|
4686 | this.value == "yield" && this.inGeneratorContext())
|
4687 | { allowed = true; }
|
4688 | }
|
4689 | this.exprAllowed = allowed;
|
4690 | };
|
4691 |
|
4692 |
|
4693 |
|
4694 |
|
4695 |
|
4696 | var Token = function Token(p) {
|
4697 | this.type = p.type;
|
4698 | this.value = p.value;
|
4699 | this.start = p.start;
|
4700 | this.end = p.end;
|
4701 | if (p.options.locations)
|
4702 | { this.loc = new SourceLocation(p, p.startLoc, p.endLoc); }
|
4703 | if (p.options.ranges)
|
4704 | { this.range = [p.start, p.end]; }
|
4705 | };
|
4706 |
|
4707 |
|
4708 |
|
4709 | var pp$8 = Parser.prototype;
|
4710 |
|
4711 |
|
4712 | var isRhino = typeof Packages == "object" && Object.prototype.toString.call(Packages) == "[object JavaPackage]";
|
4713 |
|
4714 |
|
4715 |
|
4716 | pp$8.next = function() {
|
4717 | if (this.options.onToken)
|
4718 | { this.options.onToken(new Token(this)); }
|
4719 |
|
4720 | this.lastTokEnd = this.end;
|
4721 | this.lastTokStart = this.start;
|
4722 | this.lastTokEndLoc = this.endLoc;
|
4723 | this.lastTokStartLoc = this.startLoc;
|
4724 | this.nextToken();
|
4725 | };
|
4726 |
|
4727 | pp$8.getToken = function() {
|
4728 | this.next();
|
4729 | return new Token(this)
|
4730 | };
|
4731 |
|
4732 |
|
4733 | if (typeof Symbol !== "undefined")
|
4734 | { pp$8[Symbol.iterator] = function() {
|
4735 | var this$1 = this;
|
4736 |
|
4737 | return {
|
4738 | next: function () {
|
4739 | var token = this$1.getToken();
|
4740 | return {
|
4741 | done: token.type === types.eof,
|
4742 | value: token
|
4743 | }
|
4744 | }
|
4745 | }
|
4746 | }; }
|
4747 |
|
4748 |
|
4749 |
|
4750 |
|
4751 | pp$8.curContext = function() {
|
4752 | return this.context[this.context.length - 1]
|
4753 | };
|
4754 |
|
4755 |
|
4756 |
|
4757 |
|
4758 | pp$8.nextToken = function() {
|
4759 | var curContext = this.curContext();
|
4760 | if (!curContext || !curContext.preserveSpace) { this.skipSpace(); }
|
4761 |
|
4762 | this.start = this.pos;
|
4763 | if (this.options.locations) { this.startLoc = this.curPosition(); }
|
4764 | if (this.pos >= this.input.length) { return this.finishToken(types.eof) }
|
4765 |
|
4766 | if (curContext.override) { return curContext.override(this) }
|
4767 | else { this.readToken(this.fullCharCodeAtPos()); }
|
4768 | };
|
4769 |
|
4770 | pp$8.readToken = function(code) {
|
4771 |
|
4772 |
|
4773 | if (isIdentifierStart(code, this.options.ecmaVersion >= 6) || code === 92 )
|
4774 | { return this.readWord() }
|
4775 |
|
4776 | return this.getTokenFromCode(code)
|
4777 | };
|
4778 |
|
4779 | pp$8.fullCharCodeAtPos = function() {
|
4780 | var code = this.input.charCodeAt(this.pos);
|
4781 | if (code <= 0xd7ff || code >= 0xe000) { return code }
|
4782 | var next = this.input.charCodeAt(this.pos + 1);
|
4783 | return (code << 10) + next - 0x35fdc00
|
4784 | };
|
4785 |
|
4786 | pp$8.skipBlockComment = function() {
|
4787 | var this$1 = this;
|
4788 |
|
4789 | var startLoc = this.options.onComment && this.curPosition();
|
4790 | var start = this.pos, end = this.input.indexOf("*/", this.pos += 2);
|
4791 | if (end === -1) { this.raise(this.pos - 2, "Unterminated comment"); }
|
4792 | this.pos = end + 2;
|
4793 | if (this.options.locations) {
|
4794 | lineBreakG.lastIndex = start;
|
4795 | var match;
|
4796 | while ((match = lineBreakG.exec(this.input)) && match.index < this.pos) {
|
4797 | ++this$1.curLine;
|
4798 | this$1.lineStart = match.index + match[0].length;
|
4799 | }
|
4800 | }
|
4801 | if (this.options.onComment)
|
4802 | { this.options.onComment(true, this.input.slice(start + 2, end), start, this.pos,
|
4803 | startLoc, this.curPosition()); }
|
4804 | };
|
4805 |
|
4806 | pp$8.skipLineComment = function(startSkip) {
|
4807 | var this$1 = this;
|
4808 |
|
4809 | var start = this.pos;
|
4810 | var startLoc = this.options.onComment && this.curPosition();
|
4811 | var ch = this.input.charCodeAt(this.pos += startSkip);
|
4812 | while (this.pos < this.input.length && !isNewLine(ch)) {
|
4813 | ch = this$1.input.charCodeAt(++this$1.pos);
|
4814 | }
|
4815 | if (this.options.onComment)
|
4816 | { this.options.onComment(false, this.input.slice(start + startSkip, this.pos), start, this.pos,
|
4817 | startLoc, this.curPosition()); }
|
4818 | };
|
4819 |
|
4820 |
|
4821 |
|
4822 |
|
4823 | pp$8.skipSpace = function() {
|
4824 | var this$1 = this;
|
4825 |
|
4826 | loop: while (this.pos < this.input.length) {
|
4827 | var ch = this$1.input.charCodeAt(this$1.pos);
|
4828 | switch (ch) {
|
4829 | case 32: case 160:
|
4830 | ++this$1.pos;
|
4831 | break
|
4832 | case 13:
|
4833 | if (this$1.input.charCodeAt(this$1.pos + 1) === 10) {
|
4834 | ++this$1.pos;
|
4835 | }
|
4836 | case 10: case 8232: case 8233:
|
4837 | ++this$1.pos;
|
4838 | if (this$1.options.locations) {
|
4839 | ++this$1.curLine;
|
4840 | this$1.lineStart = this$1.pos;
|
4841 | }
|
4842 | break
|
4843 | case 47:
|
4844 | switch (this$1.input.charCodeAt(this$1.pos + 1)) {
|
4845 | case 42:
|
4846 | this$1.skipBlockComment();
|
4847 | break
|
4848 | case 47:
|
4849 | this$1.skipLineComment(2);
|
4850 | break
|
4851 | default:
|
4852 | break loop
|
4853 | }
|
4854 | break
|
4855 | default:
|
4856 | if (ch > 8 && ch < 14 || ch >= 5760 && nonASCIIwhitespace.test(String.fromCharCode(ch))) {
|
4857 | ++this$1.pos;
|
4858 | } else {
|
4859 | break loop
|
4860 | }
|
4861 | }
|
4862 | }
|
4863 | };
|
4864 |
|
4865 |
|
4866 |
|
4867 |
|
4868 |
|
4869 |
|
4870 | pp$8.finishToken = function(type, val) {
|
4871 | this.end = this.pos;
|
4872 | if (this.options.locations) { this.endLoc = this.curPosition(); }
|
4873 | var prevType = this.type;
|
4874 | this.type = type;
|
4875 | this.value = val;
|
4876 |
|
4877 | this.updateContext(prevType);
|
4878 | };
|
4879 |
|
4880 |
|
4881 |
|
4882 |
|
4883 |
|
4884 |
|
4885 |
|
4886 |
|
4887 |
|
4888 |
|
4889 | pp$8.readToken_dot = function() {
|
4890 | var next = this.input.charCodeAt(this.pos + 1);
|
4891 | if (next >= 48 && next <= 57) { return this.readNumber(true) }
|
4892 | var next2 = this.input.charCodeAt(this.pos + 2);
|
4893 | if (this.options.ecmaVersion >= 6 && next === 46 && next2 === 46) {
|
4894 | this.pos += 3;
|
4895 | return this.finishToken(types.ellipsis)
|
4896 | } else {
|
4897 | ++this.pos;
|
4898 | return this.finishToken(types.dot)
|
4899 | }
|
4900 | };
|
4901 |
|
4902 | pp$8.readToken_slash = function() {
|
4903 | var next = this.input.charCodeAt(this.pos + 1);
|
4904 | if (this.exprAllowed) { ++this.pos; return this.readRegexp() }
|
4905 | if (next === 61) { return this.finishOp(types.assign, 2) }
|
4906 | return this.finishOp(types.slash, 1)
|
4907 | };
|
4908 |
|
4909 | pp$8.readToken_mult_modulo_exp = function(code) {
|
4910 | var next = this.input.charCodeAt(this.pos + 1);
|
4911 | var size = 1;
|
4912 | var tokentype = code === 42 ? types.star : types.modulo;
|
4913 |
|
4914 |
|
4915 | if (this.options.ecmaVersion >= 7 && next === 42) {
|
4916 | ++size;
|
4917 | tokentype = types.starstar;
|
4918 | next = this.input.charCodeAt(this.pos + 2);
|
4919 | }
|
4920 |
|
4921 | if (next === 61) { return this.finishOp(types.assign, size + 1) }
|
4922 | return this.finishOp(tokentype, size)
|
4923 | };
|
4924 |
|
4925 | pp$8.readToken_pipe_amp = function(code) {
|
4926 | var next = this.input.charCodeAt(this.pos + 1);
|
4927 | if (next === code) { return this.finishOp(code === 124 ? types.logicalOR : types.logicalAND, 2) }
|
4928 | if (next === 61) { return this.finishOp(types.assign, 2) }
|
4929 | return this.finishOp(code === 124 ? types.bitwiseOR : types.bitwiseAND, 1)
|
4930 | };
|
4931 |
|
4932 | pp$8.readToken_caret = function() {
|
4933 | var next = this.input.charCodeAt(this.pos + 1);
|
4934 | if (next === 61) { return this.finishOp(types.assign, 2) }
|
4935 | return this.finishOp(types.bitwiseXOR, 1)
|
4936 | };
|
4937 |
|
4938 | pp$8.readToken_plus_min = function(code) {
|
4939 | var next = this.input.charCodeAt(this.pos + 1);
|
4940 | if (next === code) {
|
4941 | if (next == 45 && this.input.charCodeAt(this.pos + 2) == 62 &&
|
4942 | (this.lastTokEnd === 0 || lineBreak.test(this.input.slice(this.lastTokEnd, this.pos)))) {
|
4943 |
|
4944 | this.skipLineComment(3);
|
4945 | this.skipSpace();
|
4946 | return this.nextToken()
|
4947 | }
|
4948 | return this.finishOp(types.incDec, 2)
|
4949 | }
|
4950 | if (next === 61) { return this.finishOp(types.assign, 2) }
|
4951 | return this.finishOp(types.plusMin, 1)
|
4952 | };
|
4953 |
|
4954 | pp$8.readToken_lt_gt = function(code) {
|
4955 | var next = this.input.charCodeAt(this.pos + 1);
|
4956 | var size = 1;
|
4957 | if (next === code) {
|
4958 | size = code === 62 && this.input.charCodeAt(this.pos + 2) === 62 ? 3 : 2;
|
4959 | if (this.input.charCodeAt(this.pos + size) === 61) { return this.finishOp(types.assign, size + 1) }
|
4960 | return this.finishOp(types.bitShift, size)
|
4961 | }
|
4962 | if (next == 33 && code == 60 && this.input.charCodeAt(this.pos + 2) == 45 &&
|
4963 | this.input.charCodeAt(this.pos + 3) == 45) {
|
4964 | if (this.inModule) { this.unexpected(); }
|
4965 |
|
4966 | this.skipLineComment(4);
|
4967 | this.skipSpace();
|
4968 | return this.nextToken()
|
4969 | }
|
4970 | if (next === 61) { size = 2; }
|
4971 | return this.finishOp(types.relational, size)
|
4972 | };
|
4973 |
|
4974 | pp$8.readToken_eq_excl = function(code) {
|
4975 | var next = this.input.charCodeAt(this.pos + 1);
|
4976 | if (next === 61) { return this.finishOp(types.equality, this.input.charCodeAt(this.pos + 2) === 61 ? 3 : 2) }
|
4977 | if (code === 61 && next === 62 && this.options.ecmaVersion >= 6) {
|
4978 | this.pos += 2;
|
4979 | return this.finishToken(types.arrow)
|
4980 | }
|
4981 | return this.finishOp(code === 61 ? types.eq : types.prefix, 1)
|
4982 | };
|
4983 |
|
4984 | pp$8.getTokenFromCode = function(code) {
|
4985 | switch (code) {
|
4986 |
|
4987 |
|
4988 | case 46:
|
4989 | return this.readToken_dot()
|
4990 |
|
4991 |
|
4992 | case 40: ++this.pos; return this.finishToken(types.parenL)
|
4993 | case 41: ++this.pos; return this.finishToken(types.parenR)
|
4994 | case 59: ++this.pos; return this.finishToken(types.semi)
|
4995 | case 44: ++this.pos; return this.finishToken(types.comma)
|
4996 | case 91: ++this.pos; return this.finishToken(types.bracketL)
|
4997 | case 93: ++this.pos; return this.finishToken(types.bracketR)
|
4998 | case 123: ++this.pos; return this.finishToken(types.braceL)
|
4999 | case 125: ++this.pos; return this.finishToken(types.braceR)
|
5000 | case 58: ++this.pos; return this.finishToken(types.colon)
|
5001 | case 63: ++this.pos; return this.finishToken(types.question)
|
5002 |
|
5003 | case 96:
|
5004 | if (this.options.ecmaVersion < 6) { break }
|
5005 | ++this.pos;
|
5006 | return this.finishToken(types.backQuote)
|
5007 |
|
5008 | case 48:
|
5009 | var next = this.input.charCodeAt(this.pos + 1);
|
5010 | if (next === 120 || next === 88) { return this.readRadixNumber(16) }
|
5011 | if (this.options.ecmaVersion >= 6) {
|
5012 | if (next === 111 || next === 79) { return this.readRadixNumber(8) }
|
5013 | if (next === 98 || next === 66) { return this.readRadixNumber(2) }
|
5014 | }
|
5015 |
|
5016 |
|
5017 | case 49: case 50: case 51: case 52: case 53: case 54: case 55: case 56: case 57:
|
5018 | return this.readNumber(false)
|
5019 |
|
5020 |
|
5021 | case 34: case 39:
|
5022 | return this.readString(code)
|
5023 |
|
5024 |
|
5025 |
|
5026 |
|
5027 |
|
5028 |
|
5029 | case 47:
|
5030 | return this.readToken_slash()
|
5031 |
|
5032 | case 37: case 42:
|
5033 | return this.readToken_mult_modulo_exp(code)
|
5034 |
|
5035 | case 124: case 38:
|
5036 | return this.readToken_pipe_amp(code)
|
5037 |
|
5038 | case 94:
|
5039 | return this.readToken_caret()
|
5040 |
|
5041 | case 43: case 45:
|
5042 | return this.readToken_plus_min(code)
|
5043 |
|
5044 | case 60: case 62:
|
5045 | return this.readToken_lt_gt(code)
|
5046 |
|
5047 | case 61: case 33:
|
5048 | return this.readToken_eq_excl(code)
|
5049 |
|
5050 | case 126:
|
5051 | return this.finishOp(types.prefix, 1)
|
5052 | }
|
5053 |
|
5054 | this.raise(this.pos, "Unexpected character '" + codePointToString(code) + "'");
|
5055 | };
|
5056 |
|
5057 | pp$8.finishOp = function(type, size) {
|
5058 | var str = this.input.slice(this.pos, this.pos + size);
|
5059 | this.pos += size;
|
5060 | return this.finishToken(type, str)
|
5061 | };
|
5062 |
|
5063 |
|
5064 |
|
5065 |
|
5066 | function tryCreateRegexp(src, flags, throwErrorAt, parser) {
|
5067 | try {
|
5068 | return new RegExp(src, flags)
|
5069 | } catch (e) {
|
5070 | if (throwErrorAt !== undefined) {
|
5071 | if (e instanceof SyntaxError) { parser.raise(throwErrorAt, "Error parsing regular expression: " + e.message); }
|
5072 | throw e
|
5073 | }
|
5074 | }
|
5075 | }
|
5076 |
|
5077 | var regexpUnicodeSupport = !!tryCreateRegexp("\uffff", "u");
|
5078 |
|
5079 | pp$8.readRegexp = function() {
|
5080 | var this$1 = this;
|
5081 |
|
5082 | var escaped, inClass, start = this.pos;
|
5083 | for (;;) {
|
5084 | if (this$1.pos >= this$1.input.length) { this$1.raise(start, "Unterminated regular expression"); }
|
5085 | var ch = this$1.input.charAt(this$1.pos);
|
5086 | if (lineBreak.test(ch)) { this$1.raise(start, "Unterminated regular expression"); }
|
5087 | if (!escaped) {
|
5088 | if (ch === "[") { inClass = true; }
|
5089 | else if (ch === "]" && inClass) { inClass = false; }
|
5090 | else if (ch === "/" && !inClass) { break }
|
5091 | escaped = ch === "\\";
|
5092 | } else { escaped = false; }
|
5093 | ++this$1.pos;
|
5094 | }
|
5095 | var content = this.input.slice(start, this.pos);
|
5096 | ++this.pos;
|
5097 |
|
5098 |
|
5099 | var mods = this.readWord1();
|
5100 | var tmp = content, tmpFlags = "";
|
5101 | if (mods) {
|
5102 | var validFlags = /^[gim]*$/;
|
5103 | if (this.options.ecmaVersion >= 6) { validFlags = /^[gimuy]*$/; }
|
5104 | if (!validFlags.test(mods)) { this.raise(start, "Invalid regular expression flag"); }
|
5105 | if (mods.indexOf("u") >= 0) {
|
5106 | if (regexpUnicodeSupport) {
|
5107 | tmpFlags = "u";
|
5108 | } else {
|
5109 |
|
5110 |
|
5111 |
|
5112 |
|
5113 |
|
5114 |
|
5115 |
|
5116 |
|
5117 | tmp = tmp.replace(/\\u\{([0-9a-fA-F]+)\}/g, function (_match, code, offset) {
|
5118 | code = Number("0x" + code);
|
5119 | if (code > 0x10FFFF) { this$1.raise(start + offset + 3, "Code point out of bounds"); }
|
5120 | return "x"
|
5121 | });
|
5122 | tmp = tmp.replace(/\\u([a-fA-F0-9]{4})|[\uD800-\uDBFF][\uDC00-\uDFFF]/g, "x");
|
5123 | tmpFlags = tmpFlags.replace("u", "");
|
5124 | }
|
5125 | }
|
5126 | }
|
5127 |
|
5128 | var value = null;
|
5129 |
|
5130 |
|
5131 | if (!isRhino) {
|
5132 | tryCreateRegexp(tmp, tmpFlags, start, this);
|
5133 |
|
5134 |
|
5135 | value = tryCreateRegexp(content, mods);
|
5136 | }
|
5137 | return this.finishToken(types.regexp, {pattern: content, flags: mods, value: value})
|
5138 | };
|
5139 |
|
5140 |
|
5141 |
|
5142 |
|
5143 |
|
5144 | pp$8.readInt = function(radix, len) {
|
5145 | var this$1 = this;
|
5146 |
|
5147 | var start = this.pos, total = 0;
|
5148 | for (var i = 0, e = len == null ? Infinity : len; i < e; ++i) {
|
5149 | var code = this$1.input.charCodeAt(this$1.pos), val = (void 0);
|
5150 | if (code >= 97) { val = code - 97 + 10; }
|
5151 | else if (code >= 65) { val = code - 65 + 10; }
|
5152 | else if (code >= 48 && code <= 57) { val = code - 48; }
|
5153 | else { val = Infinity; }
|
5154 | if (val >= radix) { break }
|
5155 | ++this$1.pos;
|
5156 | total = total * radix + val;
|
5157 | }
|
5158 | if (this.pos === start || len != null && this.pos - start !== len) { return null }
|
5159 |
|
5160 | return total
|
5161 | };
|
5162 |
|
5163 | pp$8.readRadixNumber = function(radix) {
|
5164 | this.pos += 2;
|
5165 | var val = this.readInt(radix);
|
5166 | if (val == null) { this.raise(this.start + 2, "Expected number in radix " + radix); }
|
5167 | if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
|
5168 | return this.finishToken(types.num, val)
|
5169 | };
|
5170 |
|
5171 |
|
5172 |
|
5173 | pp$8.readNumber = function(startsWithDot) {
|
5174 | var start = this.pos, isFloat = false, octal = this.input.charCodeAt(this.pos) === 48;
|
5175 | if (!startsWithDot && this.readInt(10) === null) { this.raise(start, "Invalid number"); }
|
5176 | if (octal && this.pos == start + 1) { octal = false; }
|
5177 | var next = this.input.charCodeAt(this.pos);
|
5178 | if (next === 46 && !octal) {
|
5179 | ++this.pos;
|
5180 | this.readInt(10);
|
5181 | isFloat = true;
|
5182 | next = this.input.charCodeAt(this.pos);
|
5183 | }
|
5184 | if ((next === 69 || next === 101) && !octal) {
|
5185 | next = this.input.charCodeAt(++this.pos);
|
5186 | if (next === 43 || next === 45) { ++this.pos; }
|
5187 | if (this.readInt(10) === null) { this.raise(start, "Invalid number"); }
|
5188 | isFloat = true;
|
5189 | }
|
5190 | if (isIdentifierStart(this.fullCharCodeAtPos())) { this.raise(this.pos, "Identifier directly after number"); }
|
5191 |
|
5192 | var str = this.input.slice(start, this.pos), val;
|
5193 | if (isFloat) { val = parseFloat(str); }
|
5194 | else if (!octal || str.length === 1) { val = parseInt(str, 10); }
|
5195 | else if (this.strict) { this.raise(start, "Invalid number"); }
|
5196 | else if (/[89]/.test(str)) { val = parseInt(str, 10); }
|
5197 | else { val = parseInt(str, 8); }
|
5198 | return this.finishToken(types.num, val)
|
5199 | };
|
5200 |
|
5201 |
|
5202 |
|
5203 | pp$8.readCodePoint = function() {
|
5204 | var ch = this.input.charCodeAt(this.pos), code;
|
5205 |
|
5206 | if (ch === 123) {
|
5207 | if (this.options.ecmaVersion < 6) { this.unexpected(); }
|
5208 | var codePos = ++this.pos;
|
5209 | code = this.readHexChar(this.input.indexOf("}", this.pos) - this.pos);
|
5210 | ++this.pos;
|
5211 | if (code > 0x10FFFF) { this.invalidStringToken(codePos, "Code point out of bounds"); }
|
5212 | } else {
|
5213 | code = this.readHexChar(4);
|
5214 | }
|
5215 | return code
|
5216 | };
|
5217 |
|
5218 | function codePointToString(code) {
|
5219 |
|
5220 | if (code <= 0xFFFF) { return String.fromCharCode(code) }
|
5221 | code -= 0x10000;
|
5222 | return String.fromCharCode((code >> 10) + 0xD800, (code & 1023) + 0xDC00)
|
5223 | }
|
5224 |
|
5225 | pp$8.readString = function(quote) {
|
5226 | var this$1 = this;
|
5227 |
|
5228 | var out = "", chunkStart = ++this.pos;
|
5229 | for (;;) {
|
5230 | if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated string constant"); }
|
5231 | var ch = this$1.input.charCodeAt(this$1.pos);
|
5232 | if (ch === quote) { break }
|
5233 | if (ch === 92) {
|
5234 | out += this$1.input.slice(chunkStart, this$1.pos);
|
5235 | out += this$1.readEscapedChar(false);
|
5236 | chunkStart = this$1.pos;
|
5237 | } else {
|
5238 | if (isNewLine(ch)) { this$1.raise(this$1.start, "Unterminated string constant"); }
|
5239 | ++this$1.pos;
|
5240 | }
|
5241 | }
|
5242 | out += this.input.slice(chunkStart, this.pos++);
|
5243 | return this.finishToken(types.string, out)
|
5244 | };
|
5245 |
|
5246 |
|
5247 |
|
5248 | var INVALID_TEMPLATE_ESCAPE_ERROR = {};
|
5249 |
|
5250 | pp$8.tryReadTemplateToken = function() {
|
5251 | this.inTemplateElement = true;
|
5252 | try {
|
5253 | this.readTmplToken();
|
5254 | } catch (err) {
|
5255 | if (err === INVALID_TEMPLATE_ESCAPE_ERROR) {
|
5256 | this.readInvalidTemplateToken();
|
5257 | } else {
|
5258 | throw err
|
5259 | }
|
5260 | }
|
5261 |
|
5262 | this.inTemplateElement = false;
|
5263 | };
|
5264 |
|
5265 | pp$8.invalidStringToken = function(position, message) {
|
5266 | if (this.inTemplateElement && this.options.ecmaVersion >= 9) {
|
5267 | throw INVALID_TEMPLATE_ESCAPE_ERROR
|
5268 | } else {
|
5269 | this.raise(position, message);
|
5270 | }
|
5271 | };
|
5272 |
|
5273 | pp$8.readTmplToken = function() {
|
5274 | var this$1 = this;
|
5275 |
|
5276 | var out = "", chunkStart = this.pos;
|
5277 | for (;;) {
|
5278 | if (this$1.pos >= this$1.input.length) { this$1.raise(this$1.start, "Unterminated template"); }
|
5279 | var ch = this$1.input.charCodeAt(this$1.pos);
|
5280 | if (ch === 96 || ch === 36 && this$1.input.charCodeAt(this$1.pos + 1) === 123) {
|
5281 | if (this$1.pos === this$1.start && (this$1.type === types.template || this$1.type === types.invalidTemplate)) {
|
5282 | if (ch === 36) {
|
5283 | this$1.pos += 2;
|
5284 | return this$1.finishToken(types.dollarBraceL)
|
5285 | } else {
|
5286 | ++this$1.pos;
|
5287 | return this$1.finishToken(types.backQuote)
|
5288 | }
|
5289 | }
|
5290 | out += this$1.input.slice(chunkStart, this$1.pos);
|
5291 | return this$1.finishToken(types.template, out)
|
5292 | }
|
5293 | if (ch === 92) {
|
5294 | out += this$1.input.slice(chunkStart, this$1.pos);
|
5295 | out += this$1.readEscapedChar(true);
|
5296 | chunkStart = this$1.pos;
|
5297 | } else if (isNewLine(ch)) {
|
5298 | out += this$1.input.slice(chunkStart, this$1.pos);
|
5299 | ++this$1.pos;
|
5300 | switch (ch) {
|
5301 | case 13:
|
5302 | if (this$1.input.charCodeAt(this$1.pos) === 10) { ++this$1.pos; }
|
5303 | case 10:
|
5304 | out += "\n";
|
5305 | break
|
5306 | default:
|
5307 | out += String.fromCharCode(ch);
|
5308 | break
|
5309 | }
|
5310 | if (this$1.options.locations) {
|
5311 | ++this$1.curLine;
|
5312 | this$1.lineStart = this$1.pos;
|
5313 | }
|
5314 | chunkStart = this$1.pos;
|
5315 | } else {
|
5316 | ++this$1.pos;
|
5317 | }
|
5318 | }
|
5319 | };
|
5320 |
|
5321 |
|
5322 | pp$8.readInvalidTemplateToken = function() {
|
5323 | var this$1 = this;
|
5324 |
|
5325 | for (; this.pos < this.input.length; this.pos++) {
|
5326 | switch (this$1.input[this$1.pos]) {
|
5327 | case "\\":
|
5328 | ++this$1.pos;
|
5329 | break
|
5330 |
|
5331 | case "$":
|
5332 | if (this$1.input[this$1.pos + 1] !== "{") {
|
5333 | break
|
5334 | }
|
5335 |
|
5336 |
|
5337 | case "`":
|
5338 | return this$1.finishToken(types.invalidTemplate, this$1.input.slice(this$1.start, this$1.pos))
|
5339 |
|
5340 |
|
5341 | }
|
5342 | }
|
5343 | this.raise(this.start, "Unterminated template");
|
5344 | };
|
5345 |
|
5346 |
|
5347 |
|
5348 | pp$8.readEscapedChar = function(inTemplate) {
|
5349 | var ch = this.input.charCodeAt(++this.pos);
|
5350 | ++this.pos;
|
5351 | switch (ch) {
|
5352 | case 110: return "\n"
|
5353 | case 114: return "\r"
|
5354 | case 120: return String.fromCharCode(this.readHexChar(2))
|
5355 | case 117: return codePointToString(this.readCodePoint())
|
5356 | case 116: return "\t"
|
5357 | case 98: return "\b"
|
5358 | case 118: return "\u000b"
|
5359 | case 102: return "\f"
|
5360 | case 13: if (this.input.charCodeAt(this.pos) === 10) { ++this.pos; }
|
5361 | case 10:
|
5362 | if (this.options.locations) { this.lineStart = this.pos; ++this.curLine; }
|
5363 | return ""
|
5364 | default:
|
5365 | if (ch >= 48 && ch <= 55) {
|
5366 | var octalStr = this.input.substr(this.pos - 1, 3).match(/^[0-7]+/)[0];
|
5367 | var octal = parseInt(octalStr, 8);
|
5368 | if (octal > 255) {
|
5369 | octalStr = octalStr.slice(0, -1);
|
5370 | octal = parseInt(octalStr, 8);
|
5371 | }
|
5372 | if (octalStr !== "0" && (this.strict || inTemplate)) {
|
5373 | this.invalidStringToken(this.pos - 2, "Octal literal in strict mode");
|
5374 | }
|
5375 | this.pos += octalStr.length - 1;
|
5376 | return String.fromCharCode(octal)
|
5377 | }
|
5378 | return String.fromCharCode(ch)
|
5379 | }
|
5380 | };
|
5381 |
|
5382 |
|
5383 |
|
5384 | pp$8.readHexChar = function(len) {
|
5385 | var codePos = this.pos;
|
5386 | var n = this.readInt(16, len);
|
5387 | if (n === null) { this.invalidStringToken(codePos, "Bad character escape sequence"); }
|
5388 | return n
|
5389 | };
|
5390 |
|
5391 |
|
5392 |
|
5393 |
|
5394 |
|
5395 |
|
5396 |
|
5397 | pp$8.readWord1 = function() {
|
5398 | var this$1 = this;
|
5399 |
|
5400 | this.containsEsc = false;
|
5401 | var word = "", first = true, chunkStart = this.pos;
|
5402 | var astral = this.options.ecmaVersion >= 6;
|
5403 | while (this.pos < this.input.length) {
|
5404 | var ch = this$1.fullCharCodeAtPos();
|
5405 | if (isIdentifierChar(ch, astral)) {
|
5406 | this$1.pos += ch <= 0xffff ? 1 : 2;
|
5407 | } else if (ch === 92) {
|
5408 | this$1.containsEsc = true;
|
5409 | word += this$1.input.slice(chunkStart, this$1.pos);
|
5410 | var escStart = this$1.pos;
|
5411 | if (this$1.input.charCodeAt(++this$1.pos) != 117)
|
5412 | { this$1.invalidStringToken(this$1.pos, "Expecting Unicode escape sequence \\uXXXX"); }
|
5413 | ++this$1.pos;
|
5414 | var esc = this$1.readCodePoint();
|
5415 | if (!(first ? isIdentifierStart : isIdentifierChar)(esc, astral))
|
5416 | { this$1.invalidStringToken(escStart, "Invalid Unicode escape"); }
|
5417 | word += codePointToString(esc);
|
5418 | chunkStart = this$1.pos;
|
5419 | } else {
|
5420 | break
|
5421 | }
|
5422 | first = false;
|
5423 | }
|
5424 | return word + this.input.slice(chunkStart, this.pos)
|
5425 | };
|
5426 |
|
5427 |
|
5428 |
|
5429 |
|
5430 | pp$8.readWord = function() {
|
5431 | var word = this.readWord1();
|
5432 | var type = types.name;
|
5433 | if (this.keywords.test(word)) {
|
5434 | if (this.containsEsc) { this.raiseRecoverable(this.start, "Escape sequence in keyword " + word); }
|
5435 | type = keywords$1[word];
|
5436 | }
|
5437 | return this.finishToken(type, word)
|
5438 | };
|
5439 |
|
5440 |
|
5441 |
|
5442 |
|
5443 |
|
5444 |
|
5445 |
|
5446 |
|
5447 | function parse(input, options) {
|
5448 | return new Parser(options, input).parse()
|
5449 | }
|
5450 |
|
5451 | function getLocator$1(source, options) {
|
5452 | if (options === void 0) { options = {}; }
|
5453 | var offsetLine = options.offsetLine || 0;
|
5454 | var offsetColumn = options.offsetColumn || 0;
|
5455 | var originalLines = source.split('\n');
|
5456 | var start = 0;
|
5457 | var lineRanges = originalLines.map(function (line, i) {
|
5458 | var end = start + line.length + 1;
|
5459 | var range = { start: start, end: end, line: i };
|
5460 | start = end;
|
5461 | return range;
|
5462 | });
|
5463 | var i = 0;
|
5464 | function rangeContains(range, index) {
|
5465 | return range.start <= index && index < range.end;
|
5466 | }
|
5467 | function getLocation(range, index) {
|
5468 | return { line: offsetLine + range.line, column: offsetColumn + index - range.start, character: index };
|
5469 | }
|
5470 | function locate(search, startIndex) {
|
5471 | if (typeof search === 'string') {
|
5472 | search = source.indexOf(search, startIndex || 0);
|
5473 | }
|
5474 | var range = lineRanges[i];
|
5475 | var d = search >= range.end ? 1 : -1;
|
5476 | while (range) {
|
5477 | if (rangeContains(range, search))
|
5478 | return getLocation(range, search);
|
5479 | i += d;
|
5480 | range = lineRanges[i];
|
5481 | }
|
5482 | }
|
5483 |
|
5484 | return locate;
|
5485 | }
|
5486 | function locate(source, search, options) {
|
5487 | if (typeof options === 'number') {
|
5488 | throw new Error('locate takes a { startIndex, offsetLine, offsetColumn } object as the third argument');
|
5489 | }
|
5490 | return getLocator$1(source, options)(search, options && options.startIndex);
|
5491 | }
|
5492 |
|
5493 | var reservedWords$1 = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public'.split( ' ' );
|
5494 | var builtins = 'Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl'.split( ' ' );
|
5495 |
|
5496 | var blacklisted = blank();
|
5497 | reservedWords$1.concat( builtins ).forEach( function (word) { return blacklisted[ word ] = true; } );
|
5498 |
|
5499 | var illegalCharacters = /[^$_a-zA-Z0-9]/g;
|
5500 |
|
5501 | var startsWithDigit = function (str) { return /\d/.test( str[0] ); };
|
5502 |
|
5503 | function isLegal ( str ) {
|
5504 | if ( startsWithDigit(str) || blacklisted[ str ] ) {
|
5505 | return false;
|
5506 | }
|
5507 | if ( illegalCharacters.test(str) ) {
|
5508 | return false;
|
5509 | }
|
5510 | return true;
|
5511 | }
|
5512 |
|
5513 | function makeLegal ( str ) {
|
5514 | str = str
|
5515 | .replace( /-(\w)/g, function ( _, letter ) { return letter.toUpperCase(); } )
|
5516 | .replace( illegalCharacters, '_' );
|
5517 |
|
5518 | if ( startsWithDigit(str) || blacklisted[ str ] ) { str = "_" + str; }
|
5519 |
|
5520 | return str;
|
5521 | }
|
5522 |
|
5523 | function spaces ( i ) {
|
5524 | var result = '';
|
5525 | while ( i-- ) { result += ' '; }
|
5526 | return result;
|
5527 | }
|
5528 |
|
5529 |
|
5530 | function tabsToSpaces ( str ) {
|
5531 | return str.replace( /^\t+/, function (match) { return match.split( '\t' ).join( ' ' ); } );
|
5532 | }
|
5533 |
|
5534 | function getCodeFrame ( source, line, column ) {
|
5535 | var lines = source.split( '\n' );
|
5536 |
|
5537 | var frameStart = Math.max( 0, line - 3 );
|
5538 | var frameEnd = Math.min( line + 2, lines.length );
|
5539 |
|
5540 | lines = lines.slice( frameStart, frameEnd );
|
5541 | while ( !/\S/.test( lines[ lines.length - 1 ] ) ) {
|
5542 | lines.pop();
|
5543 | frameEnd -= 1;
|
5544 | }
|
5545 |
|
5546 | var digits = String( frameEnd ).length;
|
5547 |
|
5548 | return lines
|
5549 | .map( function ( str, i ) {
|
5550 | var isErrorLine = frameStart + i + 1 === line;
|
5551 |
|
5552 | var lineNum = String( i + frameStart + 1 );
|
5553 | while ( lineNum.length < digits ) { lineNum = " " + lineNum; }
|
5554 |
|
5555 | if ( isErrorLine ) {
|
5556 | var indicator = spaces( digits + 2 + tabsToSpaces( str.slice( 0, column ) ).length ) + '^';
|
5557 | return (lineNum + ": " + (tabsToSpaces( str )) + "\n" + indicator);
|
5558 | }
|
5559 |
|
5560 | return (lineNum + ": " + (tabsToSpaces( str )));
|
5561 | })
|
5562 | .join( '\n' );
|
5563 | }
|
5564 |
|
5565 | function relativeId ( id ) {
|
5566 | if ( typeof process === 'undefined' || !isAbsolute( id ) ) { return id; }
|
5567 | return relative( process.cwd(), id );
|
5568 | }
|
5569 |
|
5570 |
|
5571 | var ARRAY = { ARRAY: true, toString: function () { return '[[ARRAY]]'; } };
|
5572 |
|
5573 |
|
5574 | var NUMBER = { NUMBER: true, toString: function () { return '[[NUMBER]]'; } };
|
5575 | var OBJECT = { OBJECT: true, toString: function () { return '[[OBJECT]]'; } };
|
5576 | var STRING = { STRING: true, toString: function () { return '[[STRING]]'; } };
|
5577 | var UNKNOWN = { UNKNOWN: true, toString: function () { return '[[UNKNOWN]]'; } };
|
5578 |
|
5579 | var Declaration = function Declaration ( node, isParam ) {
|
5580 | this.node = node;
|
5581 |
|
5582 | this.name = node.id ? node.id.name : node.name;
|
5583 | this.exportName = null;
|
5584 | this.isParam = isParam;
|
5585 |
|
5586 | this.isReassigned = false;
|
5587 | };
|
5588 |
|
5589 | Declaration.prototype.activate = function activate () {
|
5590 | if ( this.activated ) { return; }
|
5591 | this.activated = true;
|
5592 |
|
5593 | if ( this.isParam ) { return; }
|
5594 | this.node.activate();
|
5595 | };
|
5596 |
|
5597 | Declaration.prototype.addReference = function addReference ( reference ) {
|
5598 | reference.declaration = this;
|
5599 |
|
5600 | if ( reference.name !== this.name ) {
|
5601 | this.name = makeLegal( reference.name );
|
5602 | }
|
5603 |
|
5604 | if ( reference.isReassignment ) { this.isReassigned = true; }
|
5605 | };
|
5606 |
|
5607 | Declaration.prototype.render = function render ( es ) {
|
5608 | if ( es ) { return this.name; }
|
5609 | if ( !this.isReassigned || !this.exportName ) { return this.name; }
|
5610 |
|
5611 | return ("exports." + (this.exportName));
|
5612 | };
|
5613 |
|
5614 | var SyntheticNamespaceDeclaration = function SyntheticNamespaceDeclaration ( module ) {
|
5615 | var this$1 = this;
|
5616 |
|
5617 | this.isNamespace = true;
|
5618 | this.module = module;
|
5619 | this.name = module.basename();
|
5620 |
|
5621 | this.needsNamespaceBlock = false;
|
5622 |
|
5623 | this.originals = blank();
|
5624 | module.getExports().concat( module.getReexports() ).forEach( function (name) {
|
5625 | this$1.originals[ name ] = module.traceExport( name );
|
5626 | });
|
5627 | };
|
5628 |
|
5629 | SyntheticNamespaceDeclaration.prototype.activate = function activate () {
|
5630 | this.needsNamespaceBlock = true;
|
5631 |
|
5632 |
|
5633 |
|
5634 | forOwn( this.originals, function (original) {
|
5635 | original.activate();
|
5636 | });
|
5637 | };
|
5638 |
|
5639 | SyntheticNamespaceDeclaration.prototype.addReference = function addReference ( node ) {
|
5640 | this.name = node.name;
|
5641 | };
|
5642 |
|
5643 | SyntheticNamespaceDeclaration.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
5644 | values.add( UNKNOWN );
|
5645 | };
|
5646 |
|
5647 | SyntheticNamespaceDeclaration.prototype.getName = function getName () {
|
5648 | return this.name;
|
5649 | };
|
5650 |
|
5651 | SyntheticNamespaceDeclaration.prototype.renderBlock = function renderBlock ( es, legacy, indentString ) {
|
5652 | var this$1 = this;
|
5653 |
|
5654 | var members = keys( this.originals ).map( function (name) {
|
5655 | var original = this$1.originals[ name ];
|
5656 |
|
5657 | if ( original.isReassigned && !legacy ) {
|
5658 | return (indentString + "get " + name + " () { return " + (original.getName( es )) + "; }");
|
5659 | }
|
5660 |
|
5661 | if ( legacy && ~reservedWords$1.indexOf( name ) ) { name = "'" + name + "'"; }
|
5662 | return ("" + indentString + name + ": " + (original.getName( es )));
|
5663 | });
|
5664 |
|
5665 | var callee = legacy ? "(Object.freeze || Object)" : "Object.freeze";
|
5666 | return ((this.module.bundle.varOrConst) + " " + (this.getName( es )) + " = " + callee + "({\n" + (members.join( ',\n' )) + "\n});\n\n");
|
5667 | };
|
5668 |
|
5669 | var ExternalDeclaration = function ExternalDeclaration ( module, name ) {
|
5670 | this.module = module;
|
5671 | this.name = name;
|
5672 | this.safeName = null;
|
5673 | this.isExternal = true;
|
5674 |
|
5675 | this.activated = false;
|
5676 |
|
5677 | this.isNamespace = name === '*';
|
5678 | };
|
5679 |
|
5680 | ExternalDeclaration.prototype.activate = function activate () {
|
5681 | this.module.used = true;
|
5682 | this.activated = true;
|
5683 | };
|
5684 |
|
5685 | ExternalDeclaration.prototype.addReference = function addReference ( reference ) {
|
5686 | reference.declaration = this;
|
5687 |
|
5688 | if ( this.name === 'default' || this.name === '*' ) {
|
5689 | this.module.suggestName( reference.name );
|
5690 | }
|
5691 | };
|
5692 |
|
5693 | ExternalDeclaration.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
5694 | values.add( UNKNOWN );
|
5695 | };
|
5696 |
|
5697 | ExternalDeclaration.prototype.getName = function getName ( es ) {
|
5698 | if ( this.name === '*' ) {
|
5699 | return this.module.name;
|
5700 | }
|
5701 |
|
5702 | if ( this.name === 'default' ) {
|
5703 | return this.module.exportsNamespace || ( !es && this.module.exportsNames ) ?
|
5704 | ((this.module.name) + "__default") :
|
5705 | this.module.name;
|
5706 | }
|
5707 |
|
5708 | return es ? this.safeName : ((this.module.name) + "." + (this.name));
|
5709 | };
|
5710 |
|
5711 | ExternalDeclaration.prototype.setSafeName = function setSafeName ( name ) {
|
5712 | this.safeName = name;
|
5713 | };
|
5714 |
|
5715 | function extractNames ( param ) {
|
5716 | var names = [];
|
5717 | extractors[ param.type ]( names, param );
|
5718 | return names;
|
5719 | }
|
5720 |
|
5721 | var extractors = {
|
5722 | Identifier: function Identifier ( names, param ) {
|
5723 | names.push( param.name );
|
5724 | },
|
5725 |
|
5726 | ObjectPattern: function ObjectPattern ( names, param ) {
|
5727 | param.properties.forEach( function (prop) {
|
5728 | extractors[ prop.value.type ]( names, prop.value );
|
5729 | });
|
5730 | },
|
5731 |
|
5732 | ArrayPattern: function ArrayPattern ( names, param ) {
|
5733 | param.elements.forEach( function (element) {
|
5734 | if ( element ) { extractors[ element.type ]( names, element ); }
|
5735 | });
|
5736 | },
|
5737 |
|
5738 | RestElement: function RestElement ( names, param ) {
|
5739 | extractors[ param.argument.type ]( names, param.argument );
|
5740 | },
|
5741 |
|
5742 | AssignmentPattern: function AssignmentPattern ( names, param ) {
|
5743 | extractors[ param.left.type ]( names, param.left );
|
5744 | }
|
5745 | };
|
5746 |
|
5747 | var Node$1 = function Node () {};
|
5748 |
|
5749 | Node$1.prototype.bind = function bind () {
|
5750 | this.eachChild( function (child) { return child.bind(); } );
|
5751 | };
|
5752 |
|
5753 | Node$1.prototype.eachChild = function eachChild ( callback ) {
|
5754 | var this$1 = this;
|
5755 |
|
5756 | for ( var key of this$1.keys ) {
|
5757 | if ( this$1.shorthand && key === 'key' ) { continue; }
|
5758 |
|
5759 | var value = this$1[ key ];
|
5760 |
|
5761 | if ( value ) {
|
5762 | if ( 'length' in value ) {
|
5763 | for ( var child of value ) {
|
5764 | if ( child ) { callback( child ); }
|
5765 | }
|
5766 | } else if ( value ) {
|
5767 | callback( value );
|
5768 | }
|
5769 | }
|
5770 | }
|
5771 | };
|
5772 |
|
5773 | Node$1.prototype.findParent = function findParent ( selector ) {
|
5774 | return selector.test( this.type ) ? this : this.parent.findParent( selector );
|
5775 | };
|
5776 |
|
5777 | Node$1.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
5778 |
|
5779 | values.add( UNKNOWN );
|
5780 | };
|
5781 |
|
5782 | Node$1.prototype.getValue = function getValue () {
|
5783 | return UNKNOWN;
|
5784 | };
|
5785 |
|
5786 | Node$1.prototype.hasEffects = function hasEffects () {
|
5787 | var this$1 = this;
|
5788 |
|
5789 | for ( var key of this$1.keys ) {
|
5790 | var value = this$1[ key ];
|
5791 |
|
5792 | if ( value ) {
|
5793 | if ( 'length' in value ) {
|
5794 | for ( var child of value ) {
|
5795 | if ( child && child.hasEffects() ) {
|
5796 | return true;
|
5797 | }
|
5798 | }
|
5799 | } else if ( value.hasEffects() ) {
|
5800 | return true;
|
5801 | }
|
5802 | }
|
5803 | }
|
5804 | };
|
5805 |
|
5806 | Node$1.prototype.initialise = function initialise ( parentScope ) {
|
5807 | this.initialiseScope( parentScope );
|
5808 | this.initialiseNode( parentScope );
|
5809 | this.initialiseChildren( parentScope );
|
5810 | };
|
5811 |
|
5812 |
|
5813 | Node$1.prototype.initialiseChildren = function initialiseChildren () {
|
5814 | var this$1 = this;
|
5815 |
|
5816 | this.eachChild( function (child) { return child.initialise( this$1.scope ); } );
|
5817 | };
|
5818 |
|
5819 |
|
5820 | Node$1.prototype.initialiseNode = function initialiseNode () {};
|
5821 |
|
5822 |
|
5823 | Node$1.prototype.initialiseScope = function initialiseScope ( parentScope ) {
|
5824 | this.scope = parentScope;
|
5825 | };
|
5826 |
|
5827 | Node$1.prototype.insertSemicolon = function insertSemicolon ( code ) {
|
5828 | if ( code.original[ this.end - 1 ] !== ';' ) {
|
5829 | code.appendLeft( this.end, ';' );
|
5830 | }
|
5831 | };
|
5832 |
|
5833 | Node$1.prototype.locate = function locate$1 () {
|
5834 |
|
5835 | var location = locate( this.module.code, this.start, { offsetLine: 1 } );
|
5836 | location.file = this.module.id;
|
5837 | location.toString = function () { return JSON.stringify( location ); };
|
5838 |
|
5839 | return location;
|
5840 | };
|
5841 |
|
5842 | Node$1.prototype.render = function render ( code, es ) {
|
5843 | this.eachChild( function (child) { return child.render( code, es ); } );
|
5844 | };
|
5845 |
|
5846 | Node$1.prototype.run = function run () {
|
5847 | if ( this.ran ) { return; }
|
5848 | this.ran = true;
|
5849 |
|
5850 | this.eachChild( function (child) { return child.run(); } );
|
5851 | };
|
5852 |
|
5853 | Node$1.prototype.toString = function toString () {
|
5854 | return this.module.code.slice( this.start, this.end );
|
5855 | };
|
5856 |
|
5857 | var ArrayExpression = (function (Node) {
|
5858 | function ArrayExpression () {
|
5859 | Node.apply(this, arguments);
|
5860 | }
|
5861 |
|
5862 | if ( Node ) ArrayExpression.__proto__ = Node;
|
5863 | ArrayExpression.prototype = Object.create( Node && Node.prototype );
|
5864 | ArrayExpression.prototype.constructor = ArrayExpression;
|
5865 |
|
5866 | ArrayExpression.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
5867 | values.add( ARRAY );
|
5868 | };
|
5869 |
|
5870 | return ArrayExpression;
|
5871 | }(Node$1));
|
5872 |
|
5873 | var Parameter = function Parameter ( name ) {
|
5874 | this.name = name;
|
5875 |
|
5876 | this.isParam = true;
|
5877 | this.activated = true;
|
5878 | };
|
5879 |
|
5880 | Parameter.prototype.activate = function activate () {
|
5881 |
|
5882 | };
|
5883 |
|
5884 | Parameter.prototype.addReference = function addReference () {
|
5885 |
|
5886 | };
|
5887 |
|
5888 | Parameter.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
5889 | values.add( UNKNOWN );
|
5890 | };
|
5891 |
|
5892 | Parameter.prototype.getName = function getName () {
|
5893 | return this.name;
|
5894 | };
|
5895 |
|
5896 | var Scope = function Scope ( options ) {
|
5897 | if ( options === void 0 ) options = {};
|
5898 |
|
5899 | this.parent = options.parent;
|
5900 | this.isBlockScope = !!options.isBlockScope;
|
5901 | this.isLexicalBoundary = !!options.isLexicalBoundary;
|
5902 | this.isModuleScope = !!options.isModuleScope;
|
5903 |
|
5904 | this.children = [];
|
5905 | if ( this.parent ) { this.parent.children.push( this ); }
|
5906 |
|
5907 | this.declarations = blank();
|
5908 |
|
5909 | if ( this.isLexicalBoundary && !this.isModuleScope ) {
|
5910 | this.declarations.arguments = new Parameter( 'arguments' );
|
5911 | }
|
5912 | };
|
5913 |
|
5914 | Scope.prototype.addDeclaration = function addDeclaration ( name, declaration, isVar, isParam ) {
|
5915 | if ( isVar && this.isBlockScope ) {
|
5916 | this.parent.addDeclaration( name, declaration, isVar, isParam );
|
5917 | } else {
|
5918 | var existingDeclaration = this.declarations[ name ];
|
5919 |
|
5920 | if ( existingDeclaration && existingDeclaration.duplicates ) {
|
5921 |
|
5922 | existingDeclaration.duplicates.push( declaration );
|
5923 | } else {
|
5924 | this.declarations[ name ] = isParam ? new Parameter( name ) : declaration;
|
5925 | }
|
5926 | }
|
5927 | };
|
5928 |
|
5929 | Scope.prototype.contains = function contains ( name ) {
|
5930 | return !!this.declarations[ name ] ||
|
5931 | ( this.parent ? this.parent.contains( name ) : false );
|
5932 | };
|
5933 |
|
5934 | Scope.prototype.deshadow = function deshadow ( names ) {
|
5935 | var this$1 = this;
|
5936 |
|
5937 | keys( this.declarations ).forEach( function (key) {
|
5938 | var declaration = this$1.declarations[ key ];
|
5939 |
|
5940 |
|
5941 | if ( declaration.exportName && declaration.isReassigned ) { return; }
|
5942 |
|
5943 | var name = declaration.getName( true );
|
5944 | var deshadowed = name;
|
5945 |
|
5946 | var i = 1;
|
5947 |
|
5948 | while ( names.has( deshadowed ) ) {
|
5949 | deshadowed = name + "$$" + (i++);
|
5950 | }
|
5951 |
|
5952 | declaration.name = deshadowed;
|
5953 | });
|
5954 |
|
5955 | this.children.forEach( function (scope) { return scope.deshadow( names ); } );
|
5956 | };
|
5957 |
|
5958 | Scope.prototype.findDeclaration = function findDeclaration ( name ) {
|
5959 | return this.declarations[ name ] ||
|
5960 | ( this.parent && this.parent.findDeclaration( name ) );
|
5961 | };
|
5962 |
|
5963 | Scope.prototype.findLexicalBoundary = function findLexicalBoundary () {
|
5964 | return this.isLexicalBoundary ? this : this.parent.findLexicalBoundary();
|
5965 | };
|
5966 |
|
5967 | var Function = (function (Node) {
|
5968 | function Function () {
|
5969 | Node.apply(this, arguments);
|
5970 | }
|
5971 |
|
5972 | if ( Node ) Function.__proto__ = Node;
|
5973 | Function.prototype = Object.create( Node && Node.prototype );
|
5974 | Function.prototype.constructor = Function;
|
5975 |
|
5976 | Function.prototype.bind = function bind () {
|
5977 | if ( this.id ) { this.id.bind(); }
|
5978 | this.params.forEach( function (param) { return param.bind(); } );
|
5979 | this.body.bind();
|
5980 | };
|
5981 |
|
5982 | Function.prototype.hasEffects = function hasEffects () {
|
5983 | return false;
|
5984 | };
|
5985 |
|
5986 | Function.prototype.initialiseChildren = function initialiseChildren () {
|
5987 | var this$1 = this;
|
5988 |
|
5989 | this.params.forEach( function (param) {
|
5990 | param.initialise( this$1.scope );
|
5991 | extractNames( param ).forEach( function (name) { return this$1.scope.addDeclaration( name, null, false, true ); } );
|
5992 | } );
|
5993 | this.body.initialiseAndReplaceScope ?
|
5994 | this.body.initialiseAndReplaceScope( this.scope ) :
|
5995 | this.body.initialise( this.scope );
|
5996 | };
|
5997 |
|
5998 | Function.prototype.initialiseScope = function initialiseScope ( parentScope ) {
|
5999 | this.scope = new Scope( {
|
6000 | parent: parentScope,
|
6001 | isBlockScope: false,
|
6002 | isLexicalBoundary: true
|
6003 | } );
|
6004 | };
|
6005 |
|
6006 | return Function;
|
6007 | }(Node$1));
|
6008 |
|
6009 | var ArrowFunctionExpression = (function (Function$$1) {
|
6010 | function ArrowFunctionExpression () {
|
6011 | Function$$1.apply(this, arguments);
|
6012 | }
|
6013 |
|
6014 | if ( Function$$1 ) ArrowFunctionExpression.__proto__ = Function$$1;
|
6015 | ArrowFunctionExpression.prototype = Object.create( Function$$1 && Function$$1.prototype );
|
6016 | ArrowFunctionExpression.prototype.constructor = ArrowFunctionExpression;
|
6017 |
|
6018 | ArrowFunctionExpression.prototype.initialiseScope = function initialiseScope ( parentScope ) {
|
6019 | this.scope = new Scope( {
|
6020 | parent: parentScope,
|
6021 | isBlockScope: false,
|
6022 | isLexicalBoundary: false
|
6023 | } );
|
6024 | };
|
6025 |
|
6026 | return ArrowFunctionExpression;
|
6027 | }(Function));
|
6028 |
|
6029 |
|
6030 | function disallowIllegalReassignment ( scope, node ) {
|
6031 | if ( node.type === 'MemberExpression' && node.object.type === 'Identifier' ) {
|
6032 | var declaration = scope.findDeclaration( node.object.name );
|
6033 | if ( declaration.isNamespace ) {
|
6034 | node.module.error({
|
6035 | code: 'ILLEGAL_NAMESPACE_REASSIGNMENT',
|
6036 | message: ("Illegal reassignment to import '" + (node.object.name) + "'")
|
6037 | }, node.start );
|
6038 | }
|
6039 | }
|
6040 |
|
6041 | else if ( node.type === 'Identifier' ) {
|
6042 | if ( node.module.imports[ node.name ] && !scope.contains( node.name ) ) {
|
6043 | node.module.error({
|
6044 | code: 'ILLEGAL_REASSIGNMENT',
|
6045 | message: ("Illegal reassignment to import '" + (node.name) + "'")
|
6046 | }, node.start );
|
6047 | }
|
6048 | }
|
6049 | }
|
6050 |
|
6051 | function isUsedByBundle ( scope, node ) {
|
6052 |
|
6053 | while ( node.type === 'MemberExpression' ) { node = node.object; }
|
6054 |
|
6055 | var declaration = scope.findDeclaration( node.name );
|
6056 |
|
6057 | if ( declaration.isParam ) {
|
6058 | return true;
|
6059 |
|
6060 |
|
6061 |
|
6062 | }
|
6063 |
|
6064 | if ( declaration.activated ) { return true; }
|
6065 |
|
6066 | var values = new Set();
|
6067 | declaration.gatherPossibleValues( values );
|
6068 | for ( var value of values ) {
|
6069 | if ( value === UNKNOWN ) {
|
6070 | return true;
|
6071 | }
|
6072 |
|
6073 | if ( value.type === 'Identifier' ) {
|
6074 | if ( value.declaration.activated ) {
|
6075 | return true;
|
6076 | }
|
6077 | value.declaration.gatherPossibleValues( values );
|
6078 | }
|
6079 |
|
6080 | else if ( value.gatherPossibleValues ) {
|
6081 | value.gatherPossibleValues( values );
|
6082 | }
|
6083 | }
|
6084 |
|
6085 | return false;
|
6086 | }
|
6087 |
|
6088 | function isProgramLevel ( node ) {
|
6089 | do {
|
6090 | if ( node.type === 'Program' ) {
|
6091 | return true;
|
6092 | }
|
6093 | node = node.parent;
|
6094 | } while ( node && !/Function/.test( node.type ) );
|
6095 |
|
6096 | return false;
|
6097 | }
|
6098 |
|
6099 | var AssignmentExpression = (function (Node) {
|
6100 | function AssignmentExpression () {
|
6101 | Node.apply(this, arguments);
|
6102 | }
|
6103 |
|
6104 | if ( Node ) AssignmentExpression.__proto__ = Node;
|
6105 | AssignmentExpression.prototype = Object.create( Node && Node.prototype );
|
6106 | AssignmentExpression.prototype.constructor = AssignmentExpression;
|
6107 |
|
6108 | AssignmentExpression.prototype.bind = function bind () {
|
6109 | var subject = this.left;
|
6110 |
|
6111 | this.subject = subject;
|
6112 | disallowIllegalReassignment( this.scope, subject );
|
6113 |
|
6114 | if ( subject.type === 'Identifier' ) {
|
6115 | var declaration = this.scope.findDeclaration( subject.name );
|
6116 | declaration.isReassigned = true;
|
6117 |
|
6118 | if ( declaration.possibleValues ) {
|
6119 | if ( this.operator === '=' ) {
|
6120 | declaration.possibleValues.add( this.right );
|
6121 | } else if ( this.operator === '+=' ) {
|
6122 | declaration.possibleValues.add( STRING ).add( NUMBER );
|
6123 | } else {
|
6124 | declaration.possibleValues.add( NUMBER );
|
6125 | }
|
6126 | }
|
6127 | }
|
6128 |
|
6129 | Node.prototype.bind.call(this);
|
6130 | };
|
6131 |
|
6132 | AssignmentExpression.prototype.hasEffects = function hasEffects () {
|
6133 | var hasEffects = this.isUsedByBundle() || this.right.hasEffects();
|
6134 | return hasEffects;
|
6135 | };
|
6136 |
|
6137 | AssignmentExpression.prototype.initialiseNode = function initialiseNode () {
|
6138 | if ( isProgramLevel( this ) ) {
|
6139 | this.module.bundle.dependentExpressions.push( this );
|
6140 | }
|
6141 | };
|
6142 |
|
6143 | AssignmentExpression.prototype.isUsedByBundle = function isUsedByBundle$1 () {
|
6144 | return isUsedByBundle( this.scope, this.subject );
|
6145 | };
|
6146 |
|
6147 | return AssignmentExpression;
|
6148 | }(Node$1));
|
6149 |
|
6150 | var operators = {
|
6151 | '==': function ( left, right ) { return left == right; },
|
6152 | '!=': function ( left, right ) { return left != right; },
|
6153 | '===': function ( left, right ) { return left === right; },
|
6154 | '!==': function ( left, right ) { return left !== right; },
|
6155 | '<': function ( left, right ) { return left < right; },
|
6156 | '<=': function ( left, right ) { return left <= right; },
|
6157 | '>': function ( left, right ) { return left > right; },
|
6158 | '>=': function ( left, right ) { return left >= right; },
|
6159 | '<<': function ( left, right ) { return left << right; },
|
6160 | '>>': function ( left, right ) { return left >> right; },
|
6161 | '>>>': function ( left, right ) { return left >>> right; },
|
6162 | '+': function ( left, right ) { return left + right; },
|
6163 | '-': function ( left, right ) { return left - right; },
|
6164 | '*': function ( left, right ) { return left * right; },
|
6165 | '/': function ( left, right ) { return left / right; },
|
6166 | '%': function ( left, right ) { return left % right; },
|
6167 | '|': function ( left, right ) { return left | right; },
|
6168 | '^': function ( left, right ) { return left ^ right; },
|
6169 | '&': function ( left, right ) { return left & right; },
|
6170 | '**': function ( left, right ) { return Math.pow( left, right ); },
|
6171 | in: function ( left, right ) { return left in right; },
|
6172 | instanceof: function ( left, right ) { return left instanceof right; }
|
6173 | };
|
6174 |
|
6175 | var BinaryExpression = (function (Node) {
|
6176 | function BinaryExpression () {
|
6177 | Node.apply(this, arguments);
|
6178 | }
|
6179 |
|
6180 | if ( Node ) BinaryExpression.__proto__ = Node;
|
6181 | BinaryExpression.prototype = Object.create( Node && Node.prototype );
|
6182 | BinaryExpression.prototype.constructor = BinaryExpression;
|
6183 |
|
6184 | BinaryExpression.prototype.getValue = function getValue () {
|
6185 | var leftValue = this.left.getValue();
|
6186 | if ( leftValue === UNKNOWN ) { return UNKNOWN; }
|
6187 |
|
6188 | var rightValue = this.right.getValue();
|
6189 | if ( rightValue === UNKNOWN ) { return UNKNOWN; }
|
6190 |
|
6191 | if ( !operators[ this.operator ] ) { return UNKNOWN; }
|
6192 |
|
6193 | return operators[ this.operator ]( leftValue, rightValue );
|
6194 | };
|
6195 |
|
6196 | return BinaryExpression;
|
6197 | }(Node$1));
|
6198 |
|
6199 | var Statement = (function (Node) {
|
6200 | function Statement () {
|
6201 | Node.apply(this, arguments);
|
6202 | }
|
6203 |
|
6204 | if ( Node ) Statement.__proto__ = Node;
|
6205 | Statement.prototype = Object.create( Node && Node.prototype );
|
6206 | Statement.prototype.constructor = Statement;
|
6207 |
|
6208 | Statement.prototype.render = function render ( code, es ) {
|
6209 | if ( !this.module.bundle.treeshake || this.shouldInclude ) {
|
6210 | Node.prototype.render.call( this, code, es );
|
6211 | } else {
|
6212 | code.remove( this.leadingCommentStart || this.start, this.next || this.end );
|
6213 | }
|
6214 | };
|
6215 |
|
6216 | Statement.prototype.run = function run () {
|
6217 | this.shouldInclude = true;
|
6218 | Node.prototype.run.call(this);
|
6219 | };
|
6220 |
|
6221 | return Statement;
|
6222 | }(Node$1));
|
6223 |
|
6224 | var BlockStatement = (function (Statement$$1) {
|
6225 | function BlockStatement () {
|
6226 | Statement$$1.apply(this, arguments);
|
6227 | }
|
6228 |
|
6229 | if ( Statement$$1 ) BlockStatement.__proto__ = Statement$$1;
|
6230 | BlockStatement.prototype = Object.create( Statement$$1 && Statement$$1.prototype );
|
6231 | BlockStatement.prototype.constructor = BlockStatement;
|
6232 |
|
6233 | BlockStatement.prototype.bind = function bind () {
|
6234 | this.body.forEach( function (node) { return node.bind(); } );
|
6235 | };
|
6236 |
|
6237 | BlockStatement.prototype.initialiseAndReplaceScope = function initialiseAndReplaceScope ( scope ) {
|
6238 | this.scope = scope;
|
6239 | this.initialiseNode();
|
6240 | this.initialiseChildren( scope );
|
6241 | };
|
6242 |
|
6243 | BlockStatement.prototype.initialiseChildren = function initialiseChildren () {
|
6244 | var this$1 = this;
|
6245 |
|
6246 | var lastNode;
|
6247 | for ( var node of this$1.body ) {
|
6248 | node.initialise( this$1.scope );
|
6249 |
|
6250 | if ( lastNode ) { lastNode.next = node.start; }
|
6251 | lastNode = node;
|
6252 | }
|
6253 | };
|
6254 |
|
6255 | BlockStatement.prototype.initialiseScope = function initialiseScope ( parentScope ) {
|
6256 | this.scope = new Scope( {
|
6257 | parent: parentScope,
|
6258 | isBlockScope: true,
|
6259 | isLexicalBoundary: false
|
6260 | } );
|
6261 | };
|
6262 |
|
6263 | BlockStatement.prototype.render = function render ( code, es ) {
|
6264 | var this$1 = this;
|
6265 |
|
6266 | if ( this.body.length ) {
|
6267 | for ( var node of this$1.body ) {
|
6268 | node.render( code, es );
|
6269 | }
|
6270 | } else {
|
6271 | Statement$$1.prototype.render.call( this, code, es );
|
6272 | }
|
6273 | };
|
6274 |
|
6275 | return BlockStatement;
|
6276 | }(Statement));
|
6277 |
|
6278 | function isReference (node, parent) {
|
6279 | if (node.type === 'MemberExpression') {
|
6280 | return !node.computed && isReference(node.object, node);
|
6281 | }
|
6282 |
|
6283 | if (node.type === 'Identifier') {
|
6284 |
|
6285 |
|
6286 |
|
6287 | if (!parent) return true;
|
6288 |
|
6289 |
|
6290 | if (parent.type === 'MemberExpression' || parent.type === 'MethodDefinition') {
|
6291 | return parent.computed || node === parent.object;
|
6292 | }
|
6293 |
|
6294 |
|
6295 | if (parent.type === 'Property') return parent.computed || node === parent.value;
|
6296 |
|
6297 |
|
6298 | if (parent.type === 'MethodDefinition') return false;
|
6299 |
|
6300 |
|
6301 | if (parent.type === 'ExportSpecifier' && node !== parent.local) return false;
|
6302 |
|
6303 | return true;
|
6304 | }
|
6305 |
|
6306 | return false;
|
6307 | }
|
6308 |
|
6309 | function flatten ( node ) {
|
6310 | var parts = [];
|
6311 | while ( node.type === 'MemberExpression' ) {
|
6312 | if ( node.computed ) { return null; }
|
6313 | parts.unshift( node.property.name );
|
6314 |
|
6315 | node = node.object;
|
6316 | }
|
6317 |
|
6318 | if ( node.type !== 'Identifier' ) { return null; }
|
6319 |
|
6320 | var name = node.name;
|
6321 | parts.unshift( name );
|
6322 |
|
6323 | return { name: name, keypath: parts.join( '.' ) };
|
6324 | }
|
6325 |
|
6326 | var pureFunctions = {};
|
6327 |
|
6328 | var arrayTypes = 'Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array'.split( ' ' );
|
6329 | var simdTypes = 'Int8x16 Int16x8 Int32x4 Float32x4 Float64x2'.split( ' ' );
|
6330 | var simdMethods = 'abs add and bool check div equal extractLane fromFloat32x4 fromFloat32x4Bits fromFloat64x2 fromFloat64x2Bits fromInt16x8Bits fromInt32x4 fromInt32x4Bits fromInt8x16Bits greaterThan greaterThanOrEqual lessThan lessThanOrEqual load max maxNum min minNum mul neg not notEqual or reciprocalApproximation reciprocalSqrtApproximation replaceLane select selectBits shiftLeftByScalar shiftRightArithmeticByScalar shiftRightLogicalByScalar shuffle splat sqrt store sub swizzle xor'.split( ' ' );
|
6331 | var allSimdMethods = [];
|
6332 | simdTypes.forEach( function (t) {
|
6333 | simdMethods.forEach( function (m) {
|
6334 | allSimdMethods.push( ("SIMD." + t + "." + m) );
|
6335 | });
|
6336 | });
|
6337 |
|
6338 | [
|
6339 | 'Array.isArray',
|
6340 | 'Error', 'EvalError', 'InternalError', 'RangeError', 'ReferenceError', 'SyntaxError', 'TypeError', 'URIError',
|
6341 | 'isFinite', 'isNaN', 'parseFloat', 'parseInt', 'decodeURI', 'decodeURIComponent', 'encodeURI', 'encodeURIComponent', 'escape', 'unescape',
|
6342 | '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',
|
6343 | 'Function', 'Boolean',
|
6344 | 'Number', 'Number.isFinite', 'Number.isInteger', 'Number.isNaN', 'Number.isSafeInteger', 'Number.parseFloat', 'Number.parseInt',
|
6345 | 'Symbol', 'Symbol.for', 'Symbol.keyFor',
|
6346 | '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',
|
6347 | 'Date', 'Date.UTC', 'Date.now', 'Date.parse',
|
6348 | 'String', 'String.fromCharCode', 'String.fromCodePoint', 'String.raw',
|
6349 | 'RegExp',
|
6350 | 'Map', 'Set', 'WeakMap', 'WeakSet',
|
6351 | 'ArrayBuffer', 'ArrayBuffer.isView',
|
6352 | 'DataView',
|
6353 | 'JSON.parse', 'JSON.stringify',
|
6354 | 'Promise', 'Promise.all', 'Promise.race', 'Promise.reject', 'Promise.resolve',
|
6355 | 'Intl.Collator', 'Intl.Collator.supportedLocalesOf', 'Intl.DateTimeFormat', 'Intl.DateTimeFormat.supportedLocalesOf', 'Intl.NumberFormat', 'Intl.NumberFormat.supportedLocalesOf'
|
6356 |
|
6357 |
|
6358 | ].concat(
|
6359 | arrayTypes,
|
6360 | arrayTypes.map( function (t) { return (t + ".from"); } ),
|
6361 | arrayTypes.map( function (t) { return (t + ".of"); } ),
|
6362 | simdTypes.map( function (t) { return ("SIMD." + t); } ),
|
6363 | allSimdMethods
|
6364 | ).forEach( function (name) { return pureFunctions[ name ] = true; } );
|
6365 |
|
6366 | var currentlyCalling = new Set();
|
6367 |
|
6368 | function isES5Function ( node ) {
|
6369 | return node.type === 'FunctionExpression' || node.type === 'FunctionDeclaration';
|
6370 | }
|
6371 |
|
6372 | function hasEffectsNew ( node ) {
|
6373 | var inner = node;
|
6374 |
|
6375 | if ( inner.type === 'ExpressionStatement' ) {
|
6376 | inner = inner.expression;
|
6377 |
|
6378 | if ( inner.type === 'AssignmentExpression' ) {
|
6379 | if ( inner.right.hasEffects() ) {
|
6380 | return true;
|
6381 |
|
6382 | } else {
|
6383 | inner = inner.left;
|
6384 |
|
6385 | if ( inner.type === 'MemberExpression' ) {
|
6386 | if ( inner.computed && inner.property.hasEffects() ) {
|
6387 | return true;
|
6388 |
|
6389 | } else {
|
6390 | inner = inner.object;
|
6391 |
|
6392 | if ( inner.type === 'ThisExpression' ) {
|
6393 | return false;
|
6394 | }
|
6395 | }
|
6396 | }
|
6397 | }
|
6398 | }
|
6399 | }
|
6400 |
|
6401 | return node.hasEffects();
|
6402 | }
|
6403 |
|
6404 | function fnHasEffects ( fn, isNew ) {
|
6405 | if ( currentlyCalling.has( fn ) ) { return false; }
|
6406 | currentlyCalling.add( fn );
|
6407 |
|
6408 |
|
6409 | var body = fn.body.type === 'BlockStatement' ? fn.body.body : [ fn.body ];
|
6410 |
|
6411 | for ( var node of body ) {
|
6412 | if ( isNew ? hasEffectsNew( node ) : node.hasEffects() ) {
|
6413 | currentlyCalling.delete( fn );
|
6414 | return true;
|
6415 | }
|
6416 | }
|
6417 |
|
6418 | currentlyCalling.delete( fn );
|
6419 | return false;
|
6420 | }
|
6421 |
|
6422 | function callHasEffects ( scope, callee, isNew ) {
|
6423 | var values = new Set( [ callee ] );
|
6424 |
|
6425 | for ( var node of values ) {
|
6426 | if ( node === UNKNOWN ) { return true; }
|
6427 |
|
6428 | if ( /Function/.test( node.type ) ) {
|
6429 | if ( fnHasEffects( node, isNew && isES5Function( node ) ) ) { return true; }
|
6430 | }
|
6431 |
|
6432 | else if ( /Class/.test( node.type ) ) {
|
6433 |
|
6434 | return true;
|
6435 | }
|
6436 |
|
6437 | else if ( isReference( node ) ) {
|
6438 | var flattened = flatten( node );
|
6439 | var declaration = scope.findDeclaration( flattened.name );
|
6440 |
|
6441 | if ( declaration.isGlobal ) {
|
6442 | if ( !pureFunctions[ flattened.keypath ] ) { return true; }
|
6443 | }
|
6444 |
|
6445 | else if ( declaration.isExternal ) {
|
6446 | return true;
|
6447 | }
|
6448 |
|
6449 | else {
|
6450 | if ( node.declaration ) {
|
6451 | node.declaration.gatherPossibleValues( values );
|
6452 | } else {
|
6453 | return true;
|
6454 | }
|
6455 | }
|
6456 | }
|
6457 |
|
6458 | else if ( node.gatherPossibleValues ) {
|
6459 | node.gatherPossibleValues( values );
|
6460 | }
|
6461 |
|
6462 | else {
|
6463 |
|
6464 | return true;
|
6465 | }
|
6466 | }
|
6467 |
|
6468 | return false;
|
6469 | }
|
6470 |
|
6471 | var CallExpression = (function (Node) {
|
6472 | function CallExpression () {
|
6473 | Node.apply(this, arguments);
|
6474 | }
|
6475 |
|
6476 | if ( Node ) CallExpression.__proto__ = Node;
|
6477 | CallExpression.prototype = Object.create( Node && Node.prototype );
|
6478 | CallExpression.prototype.constructor = CallExpression;
|
6479 |
|
6480 | CallExpression.prototype.bind = function bind () {
|
6481 | if ( this.callee.type === 'Identifier' ) {
|
6482 | var declaration = this.scope.findDeclaration( this.callee.name );
|
6483 |
|
6484 | if ( declaration.isNamespace ) {
|
6485 | this.module.error( {
|
6486 | code: 'CANNOT_CALL_NAMESPACE',
|
6487 | message: ("Cannot call a namespace ('" + (this.callee.name) + "')")
|
6488 | }, this.start );
|
6489 | }
|
6490 |
|
6491 | if ( this.callee.name === 'eval' && declaration.isGlobal ) {
|
6492 | this.module.warn( {
|
6493 | code: 'EVAL',
|
6494 | message: "Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification",
|
6495 | url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval'
|
6496 | }, this.start );
|
6497 | }
|
6498 | }
|
6499 |
|
6500 | Node.prototype.bind.call(this);
|
6501 | };
|
6502 |
|
6503 | CallExpression.prototype.hasEffects = function hasEffects () {
|
6504 | return callHasEffects( this.scope, this.callee, false );
|
6505 | };
|
6506 |
|
6507 | CallExpression.prototype.initialiseNode = function initialiseNode () {
|
6508 | if ( isProgramLevel( this ) ) {
|
6509 | this.module.bundle.dependentExpressions.push( this );
|
6510 | }
|
6511 | };
|
6512 |
|
6513 | CallExpression.prototype.isUsedByBundle = function isUsedByBundle () {
|
6514 | return this.hasEffects();
|
6515 | };
|
6516 |
|
6517 | return CallExpression;
|
6518 | }(Node$1));
|
6519 |
|
6520 | var CatchClause = (function (Node) {
|
6521 | function CatchClause () {
|
6522 | Node.apply(this, arguments);
|
6523 | }
|
6524 |
|
6525 | if ( Node ) CatchClause.__proto__ = Node;
|
6526 | CatchClause.prototype = Object.create( Node && Node.prototype );
|
6527 | CatchClause.prototype.constructor = CatchClause;
|
6528 |
|
6529 | CatchClause.prototype.initialiseChildren = function initialiseChildren () {
|
6530 | var this$1 = this;
|
6531 |
|
6532 | if ( this.param ) {
|
6533 | this.param.initialise( this.scope );
|
6534 | extractNames( this.param ).forEach( function (name) { return this$1.scope.addDeclaration( name, null, false, true ); } );
|
6535 | }
|
6536 | this.body.initialiseAndReplaceScope( this.scope );
|
6537 | };
|
6538 |
|
6539 | CatchClause.prototype.initialiseScope = function initialiseScope ( parentScope ) {
|
6540 | this.scope = new Scope( {
|
6541 | parent: parentScope,
|
6542 | isBlockScope: true,
|
6543 | isLexicalBoundary: false
|
6544 | } );
|
6545 | };
|
6546 |
|
6547 | return CatchClause;
|
6548 | }(Node$1));
|
6549 |
|
6550 | var ClassExpression = (function (Node) {
|
6551 | function ClassExpression () {
|
6552 | Node.apply(this, arguments);
|
6553 | }
|
6554 |
|
6555 | if ( Node ) ClassExpression.__proto__ = Node;
|
6556 | ClassExpression.prototype = Object.create( Node && Node.prototype );
|
6557 | ClassExpression.prototype.constructor = ClassExpression;
|
6558 |
|
6559 | ClassExpression.prototype.activate = function activate () {
|
6560 | if ( this.activated ) { return; }
|
6561 | this.activated = true;
|
6562 |
|
6563 | if ( this.superClass ) { this.superClass.run(); }
|
6564 | this.body.run();
|
6565 | };
|
6566 |
|
6567 | ClassExpression.prototype.addReference = function addReference () {};
|
6568 |
|
6569 | ClassExpression.prototype.getName = function getName () {
|
6570 | return this.name;
|
6571 | };
|
6572 |
|
6573 | ClassExpression.prototype.initialiseChildren = function initialiseChildren () {
|
6574 | if ( this.superClass ) {
|
6575 | this.superClass.initialise( this.scope );
|
6576 | }
|
6577 | this.body.initialise( this.scope );
|
6578 | };
|
6579 |
|
6580 | ClassExpression.prototype.initialiseScope = function initialiseScope ( parentScope ) {
|
6581 | this.scope = new Scope( {
|
6582 | parent: parentScope,
|
6583 | isBlockScope: true
|
6584 | } );
|
6585 | };
|
6586 |
|
6587 | return ClassExpression;
|
6588 | }(Node$1));
|
6589 |
|
6590 | var ClassDeclaration = (function (Class$$1) {
|
6591 | function ClassDeclaration () {
|
6592 | Class$$1.apply(this, arguments);
|
6593 | }
|
6594 |
|
6595 | if ( Class$$1 ) ClassDeclaration.__proto__ = Class$$1;
|
6596 | ClassDeclaration.prototype = Object.create( Class$$1 && Class$$1.prototype );
|
6597 | ClassDeclaration.prototype.constructor = ClassDeclaration;
|
6598 |
|
6599 | ClassDeclaration.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
6600 | values.add( this );
|
6601 | };
|
6602 |
|
6603 | ClassDeclaration.prototype.hasEffects = function hasEffects () {
|
6604 | return false;
|
6605 | };
|
6606 |
|
6607 | ClassDeclaration.prototype.initialiseChildren = function initialiseChildren ( parentScope ) {
|
6608 | if ( this.id ) {
|
6609 | this.name = this.id.name;
|
6610 | parentScope.addDeclaration( this.name, this, false, false );
|
6611 | this.id.initialise( parentScope );
|
6612 | }
|
6613 | Class$$1.prototype.initialiseChildren.call( this, parentScope );
|
6614 | };
|
6615 |
|
6616 | ClassDeclaration.prototype.render = function render ( code, es ) {
|
6617 | if ( !this.module.bundle.treeshake || this.activated ) {
|
6618 | Class$$1.prototype.render.call( this, code, es );
|
6619 | } else {
|
6620 | code.remove( this.leadingCommentStart || this.start, this.next || this.end );
|
6621 | }
|
6622 | };
|
6623 |
|
6624 | ClassDeclaration.prototype.run = function run () {
|
6625 | if ( this.parent.type === 'ExportDefaultDeclaration' ) {
|
6626 | Class$$1.prototype.run.call(this);
|
6627 | }
|
6628 | };
|
6629 |
|
6630 | return ClassDeclaration;
|
6631 | }(ClassExpression));
|
6632 |
|
6633 | var ClassExpression$1 = (function (Class) {
|
6634 | function ClassExpression$$1 () {
|
6635 | Class.apply(this, arguments);
|
6636 | }
|
6637 |
|
6638 | if ( Class ) ClassExpression$$1.__proto__ = Class;
|
6639 | ClassExpression$$1.prototype = Object.create( Class && Class.prototype );
|
6640 | ClassExpression$$1.prototype.constructor = ClassExpression$$1;
|
6641 |
|
6642 | ClassExpression$$1.prototype.initialiseChildren = function initialiseChildren (parentScope) {
|
6643 | if ( this.id ) {
|
6644 | this.name = this.id.name;
|
6645 | this.scope.addDeclaration( this.name, this, false, false );
|
6646 | this.id.initialise( this.scope );
|
6647 | }
|
6648 | Class.prototype.initialiseChildren.call(this, parentScope);
|
6649 | };
|
6650 |
|
6651 | return ClassExpression$$1;
|
6652 | }(ClassExpression));
|
6653 |
|
6654 | var ConditionalExpression = (function (Node) {
|
6655 | function ConditionalExpression () {
|
6656 | Node.apply(this, arguments);
|
6657 | }
|
6658 |
|
6659 | if ( Node ) ConditionalExpression.__proto__ = Node;
|
6660 | ConditionalExpression.prototype = Object.create( Node && Node.prototype );
|
6661 | ConditionalExpression.prototype.constructor = ConditionalExpression;
|
6662 |
|
6663 | ConditionalExpression.prototype.initialiseChildren = function initialiseChildren ( parentScope ) {
|
6664 | if ( this.module.bundle.treeshake ) {
|
6665 | this.testValue = this.test.getValue();
|
6666 |
|
6667 | if ( this.testValue === UNKNOWN ) {
|
6668 | Node.prototype.initialiseChildren.call( this, parentScope );
|
6669 | } else if ( this.testValue ) {
|
6670 | this.consequent.initialise( this.scope );
|
6671 | this.alternate = null;
|
6672 | } else if ( this.alternate ) {
|
6673 | this.alternate.initialise( this.scope );
|
6674 | this.consequent = null;
|
6675 | }
|
6676 | } else {
|
6677 | Node.prototype.initialiseChildren.call( this, parentScope );
|
6678 | }
|
6679 | };
|
6680 |
|
6681 | ConditionalExpression.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
6682 | var testValue = this.test.getValue();
|
6683 |
|
6684 | if ( testValue === UNKNOWN ) {
|
6685 | values.add( this.consequent ).add( this.alternate );
|
6686 | } else {
|
6687 | values.add( testValue ? this.consequent : this.alternate );
|
6688 | }
|
6689 | };
|
6690 |
|
6691 | ConditionalExpression.prototype.getValue = function getValue () {
|
6692 | var testValue = this.test.getValue();
|
6693 | if ( testValue === UNKNOWN ) { return UNKNOWN; }
|
6694 |
|
6695 | return testValue ? this.consequent.getValue() : this.alternate.getValue();
|
6696 | };
|
6697 |
|
6698 | ConditionalExpression.prototype.render = function render ( code, es ) {
|
6699 | if ( !this.module.bundle.treeshake ) {
|
6700 | Node.prototype.render.call( this, code, es );
|
6701 | }
|
6702 |
|
6703 | else {
|
6704 | if ( this.testValue === UNKNOWN ) {
|
6705 | Node.prototype.render.call( this, code, es );
|
6706 | }
|
6707 |
|
6708 | else if ( this.testValue ) {
|
6709 | code.remove( this.start, this.consequent.start );
|
6710 | code.remove( this.consequent.end, this.end );
|
6711 | if ( this.consequent.type === 'SequenceExpression' ) {
|
6712 | code.prependRight( this.consequent.start, '(' );
|
6713 | code.appendLeft( this.consequent.end, ')' );
|
6714 | }
|
6715 | this.consequent.render( code, es );
|
6716 | } else {
|
6717 | code.remove( this.start, this.alternate.start );
|
6718 | code.remove( this.alternate.end, this.end );
|
6719 | if ( this.alternate.type === 'SequenceExpression' ) {
|
6720 | code.prependRight( this.alternate.start, '(' );
|
6721 | code.appendLeft( this.alternate.end, ')' );
|
6722 | }
|
6723 | this.alternate.render( code, es );
|
6724 | }
|
6725 | }
|
6726 | };
|
6727 |
|
6728 | return ConditionalExpression;
|
6729 | }(Node$1));
|
6730 |
|
6731 | var EmptyStatement = (function (Statement$$1) {
|
6732 | function EmptyStatement () {
|
6733 | Statement$$1.apply(this, arguments);
|
6734 | }
|
6735 |
|
6736 | if ( Statement$$1 ) EmptyStatement.__proto__ = Statement$$1;
|
6737 | EmptyStatement.prototype = Object.create( Statement$$1 && Statement$$1.prototype );
|
6738 | EmptyStatement.prototype.constructor = EmptyStatement;
|
6739 |
|
6740 | EmptyStatement.prototype.render = function render ( code ) {
|
6741 | if ( this.parent.type === 'BlockStatement' || this.parent.type === 'Program' ) {
|
6742 | code.remove( this.start, this.end );
|
6743 | }
|
6744 | };
|
6745 |
|
6746 | return EmptyStatement;
|
6747 | }(Statement));
|
6748 |
|
6749 | var ExportAllDeclaration = (function (Node) {
|
6750 | function ExportAllDeclaration () {
|
6751 | Node.apply(this, arguments);
|
6752 | }
|
6753 |
|
6754 | if ( Node ) ExportAllDeclaration.__proto__ = Node;
|
6755 | ExportAllDeclaration.prototype = Object.create( Node && Node.prototype );
|
6756 | ExportAllDeclaration.prototype.constructor = ExportAllDeclaration;
|
6757 |
|
6758 | ExportAllDeclaration.prototype.initialiseNode = function initialiseNode () {
|
6759 | this.isExportDeclaration = true;
|
6760 | };
|
6761 |
|
6762 | ExportAllDeclaration.prototype.render = function render ( code ) {
|
6763 | code.remove( this.leadingCommentStart || this.start, this.next || this.end );
|
6764 | };
|
6765 |
|
6766 | return ExportAllDeclaration;
|
6767 | }(Node$1));
|
6768 |
|
6769 | var functionOrClassDeclaration = /^(?:Function|Class)Declaration/;
|
6770 |
|
6771 | var ExportDefaultDeclaration = (function (Node) {
|
6772 | function ExportDefaultDeclaration () {
|
6773 | Node.apply(this, arguments);
|
6774 | }
|
6775 |
|
6776 | if ( Node ) ExportDefaultDeclaration.__proto__ = Node;
|
6777 | ExportDefaultDeclaration.prototype = Object.create( Node && Node.prototype );
|
6778 | ExportDefaultDeclaration.prototype.constructor = ExportDefaultDeclaration;
|
6779 |
|
6780 | ExportDefaultDeclaration.prototype.activate = function activate () {
|
6781 | if ( this.activated ) { return; }
|
6782 | this.activated = true;
|
6783 |
|
6784 | this.run();
|
6785 | };
|
6786 |
|
6787 | ExportDefaultDeclaration.prototype.addReference = function addReference ( reference ) {
|
6788 | this.name = reference.name;
|
6789 | if ( this.original ) { this.original.addReference( reference ); }
|
6790 | };
|
6791 |
|
6792 | ExportDefaultDeclaration.prototype.bind = function bind () {
|
6793 | var name = ( this.declaration.id && this.declaration.id.name ) || this.declaration.name;
|
6794 | if ( name ) { this.original = this.scope.findDeclaration( name ); }
|
6795 |
|
6796 | this.declaration.bind();
|
6797 | };
|
6798 |
|
6799 | ExportDefaultDeclaration.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
6800 | this.declaration.gatherPossibleValues( values );
|
6801 | };
|
6802 |
|
6803 | ExportDefaultDeclaration.prototype.getName = function getName ( es ) {
|
6804 | if ( this.original && !this.original.isReassigned ) {
|
6805 | return this.original.getName( es );
|
6806 | }
|
6807 |
|
6808 | return this.name;
|
6809 | };
|
6810 |
|
6811 | ExportDefaultDeclaration.prototype.initialiseNode = function initialiseNode () {
|
6812 | this.isExportDeclaration = true;
|
6813 | this.isDefault = true;
|
6814 |
|
6815 | this.name = ( this.declaration.id && this.declaration.id.name ) || this.declaration.name || this.module.basename();
|
6816 | this.scope.declarations.default = this;
|
6817 | };
|
6818 |
|
6819 |
|
6820 | ExportDefaultDeclaration.prototype.render = function render ( code, es ) {
|
6821 | var treeshake = this.module.bundle.treeshake;
|
6822 | var name = this.getName( es );
|
6823 |
|
6824 |
|
6825 | var declaration_start;
|
6826 | if ( this.declaration ) {
|
6827 | var statementStr = code.original.slice( this.start, this.end );
|
6828 | declaration_start = this.start + statementStr.match( /^\s*export\s+default\s*/ )[ 0 ].length;
|
6829 | }
|
6830 |
|
6831 | if ( this.shouldInclude || this.declaration.activated ) {
|
6832 | if ( this.activated ) {
|
6833 | if ( functionOrClassDeclaration.test( this.declaration.type ) ) {
|
6834 | if ( this.declaration.id ) {
|
6835 | code.remove( this.start, declaration_start );
|
6836 | } else {
|
6837 | code.overwrite( this.start, declaration_start, ("var " + (this.name) + " = ") );
|
6838 | if ( code.original[ this.end - 1 ] !== ';' ) { code.appendLeft( this.end, ';' ); }
|
6839 | }
|
6840 | }
|
6841 |
|
6842 | else {
|
6843 | if ( this.original && this.original.getName( es ) === name ) {
|
6844 |
|
6845 | code.remove( this.leadingCommentStart || this.start, this.next || this.end );
|
6846 | return;
|
6847 | } else {
|
6848 | code.overwrite( this.start, declaration_start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
|
6849 | }
|
6850 |
|
6851 | this.insertSemicolon( code );
|
6852 | }
|
6853 | } else {
|
6854 |
|
6855 | code.remove( this.start, declaration_start );
|
6856 | }
|
6857 |
|
6858 | Node.prototype.render.call( this, code, es );
|
6859 | } else {
|
6860 | if ( treeshake ) {
|
6861 | if ( functionOrClassDeclaration.test( this.declaration.type ) ) {
|
6862 | code.remove( this.leadingCommentStart || this.start, this.next || this.end );
|
6863 | } else {
|
6864 | var hasEffects = this.declaration.hasEffects();
|
6865 | code.remove( this.start, hasEffects ? declaration_start : this.next || this.end );
|
6866 | }
|
6867 | } else if ( name === this.declaration.name ) {
|
6868 | code.remove( this.start, this.next || this.end );
|
6869 | } else {
|
6870 | code.overwrite( this.start, declaration_start, ((this.module.bundle.varOrConst) + " " + name + " = ") );
|
6871 | }
|
6872 |
|
6873 | }
|
6874 | };
|
6875 |
|
6876 | ExportDefaultDeclaration.prototype.run = function run () {
|
6877 | this.shouldInclude = true;
|
6878 | Node.prototype.run.call(this);
|
6879 |
|
6880 |
|
6881 | if ( functionOrClassDeclaration.test( this.declaration.type ) && !this.declaration.id ) {
|
6882 | this.declaration.activate();
|
6883 | }
|
6884 | };
|
6885 |
|
6886 | return ExportDefaultDeclaration;
|
6887 | }(Node$1));
|
6888 |
|
6889 | var ExportNamedDeclaration = (function (Node) {
|
6890 | function ExportNamedDeclaration () {
|
6891 | Node.apply(this, arguments);
|
6892 | }
|
6893 |
|
6894 | if ( Node ) ExportNamedDeclaration.__proto__ = Node;
|
6895 | ExportNamedDeclaration.prototype = Object.create( Node && Node.prototype );
|
6896 | ExportNamedDeclaration.prototype.constructor = ExportNamedDeclaration;
|
6897 |
|
6898 | ExportNamedDeclaration.prototype.bind = function bind () {
|
6899 | if ( this.declaration ) { this.declaration.bind(); }
|
6900 | };
|
6901 |
|
6902 | ExportNamedDeclaration.prototype.initialiseNode = function initialiseNode () {
|
6903 | this.isExportDeclaration = true;
|
6904 | };
|
6905 |
|
6906 | ExportNamedDeclaration.prototype.render = function render ( code, es ) {
|
6907 | if ( this.declaration ) {
|
6908 | code.remove( this.start, this.declaration.start );
|
6909 | this.declaration.render( code, es );
|
6910 | } else {
|
6911 | var start = this.leadingCommentStart || this.start;
|
6912 | var end = this.next || this.end;
|
6913 |
|
6914 | if ( this.defaultExport ) {
|
6915 | var name = this.defaultExport.getName( es );
|
6916 | var originalName = this.defaultExport.original.getName( es );
|
6917 |
|
6918 | if ( name !== originalName ) {
|
6919 | code.overwrite( start, end, ("var " + name + " = " + originalName + ";") );
|
6920 | return;
|
6921 | }
|
6922 | }
|
6923 |
|
6924 | code.remove( start, end );
|
6925 | }
|
6926 | };
|
6927 |
|
6928 | return ExportNamedDeclaration;
|
6929 | }(Node$1));
|
6930 |
|
6931 | var ExpressionStatement = (function (Statement$$1) {
|
6932 | function ExpressionStatement () {
|
6933 | Statement$$1.apply(this, arguments);
|
6934 | }
|
6935 |
|
6936 | if ( Statement$$1 ) ExpressionStatement.__proto__ = Statement$$1;
|
6937 | ExpressionStatement.prototype = Object.create( Statement$$1 && Statement$$1.prototype );
|
6938 | ExpressionStatement.prototype.constructor = ExpressionStatement;
|
6939 |
|
6940 | ExpressionStatement.prototype.render = function render ( code, es ) {
|
6941 | Statement$$1.prototype.render.call( this, code, es );
|
6942 | if ( this.shouldInclude ) { this.insertSemicolon( code ); }
|
6943 | };
|
6944 |
|
6945 | return ExpressionStatement;
|
6946 | }(Statement));
|
6947 |
|
6948 | var ForStatement = (function (Statement$$1) {
|
6949 | function ForStatement () {
|
6950 | Statement$$1.apply(this, arguments);
|
6951 | }
|
6952 |
|
6953 | if ( Statement$$1 ) ForStatement.__proto__ = Statement$$1;
|
6954 | ForStatement.prototype = Object.create( Statement$$1 && Statement$$1.prototype );
|
6955 | ForStatement.prototype.constructor = ForStatement;
|
6956 |
|
6957 | ForStatement.prototype.initialiseChildren = function initialiseChildren () {
|
6958 | if ( this.init ) { this.init.initialise( this.scope ); }
|
6959 | if ( this.test ) { this.test.initialise( this.scope ); }
|
6960 | if ( this.update ) { this.update.initialise( this.scope ); }
|
6961 |
|
6962 | if ( this.body.type === 'BlockStatement' ) {
|
6963 | this.body.initialiseScope( this.scope );
|
6964 | this.body.initialiseChildren();
|
6965 | } else {
|
6966 | this.body.initialise( this.scope );
|
6967 | }
|
6968 | };
|
6969 |
|
6970 | ForStatement.prototype.initialiseScope = function initialiseScope ( parentScope ) {
|
6971 | this.scope = new Scope( {
|
6972 | parent: parentScope,
|
6973 | isBlockScope: true,
|
6974 | isLexicalBoundary: false
|
6975 | } );
|
6976 | };
|
6977 |
|
6978 | return ForStatement;
|
6979 | }(Statement));
|
6980 |
|
6981 | function assignToForLoopLeft ( node, scope, value ) {
|
6982 | if ( node.type === 'VariableDeclaration' ) {
|
6983 | for ( var proxy of node.declarations[0].proxies.values() ) {
|
6984 | proxy.possibleValues.add( value );
|
6985 | }
|
6986 | }
|
6987 |
|
6988 | else {
|
6989 | if ( node.type === 'MemberExpression' ) {
|
6990 |
|
6991 |
|
6992 |
|
6993 |
|
6994 | }
|
6995 |
|
6996 | else {
|
6997 | for ( var name of extractNames( node ) ) {
|
6998 | var declaration = scope.findDeclaration( name );
|
6999 | if ( declaration.possibleValues ) {
|
7000 | declaration.possibleValues.add( value );
|
7001 | }
|
7002 | }
|
7003 | }
|
7004 | }
|
7005 | }
|
7006 |
|
7007 | var ForInStatement = (function (Statement$$1) {
|
7008 | function ForInStatement () {
|
7009 | Statement$$1.apply(this, arguments);
|
7010 | }
|
7011 |
|
7012 | if ( Statement$$1 ) ForInStatement.__proto__ = Statement$$1;
|
7013 | ForInStatement.prototype = Object.create( Statement$$1 && Statement$$1.prototype );
|
7014 | ForInStatement.prototype.constructor = ForInStatement;
|
7015 |
|
7016 | ForInStatement.prototype.initialiseChildren = function initialiseChildren () {
|
7017 | this.left.initialise( this.scope );
|
7018 | this.right.initialise( this.scope.parent );
|
7019 | this.body.initialiseAndReplaceScope ?
|
7020 | this.body.initialiseAndReplaceScope( this.scope ) :
|
7021 | this.body.initialise( this.scope );
|
7022 | assignToForLoopLeft( this.left, this.scope, STRING );
|
7023 | };
|
7024 |
|
7025 | ForInStatement.prototype.initialiseScope = function initialiseScope ( parentScope ) {
|
7026 | this.scope = new Scope({
|
7027 | parent: parentScope,
|
7028 | isBlockScope: true,
|
7029 | isLexicalBoundary: false
|
7030 | });
|
7031 | };
|
7032 |
|
7033 | return ForInStatement;
|
7034 | }(Statement));
|
7035 |
|
7036 | var ForOfStatement = (function (Statement$$1) {
|
7037 | function ForOfStatement () {
|
7038 | Statement$$1.apply(this, arguments);
|
7039 | }
|
7040 |
|
7041 | if ( Statement$$1 ) ForOfStatement.__proto__ = Statement$$1;
|
7042 | ForOfStatement.prototype = Object.create( Statement$$1 && Statement$$1.prototype );
|
7043 | ForOfStatement.prototype.constructor = ForOfStatement;
|
7044 |
|
7045 | ForOfStatement.prototype.initialiseChildren = function initialiseChildren () {
|
7046 | this.left.initialise( this.scope );
|
7047 | this.right.initialise( this.scope.parent );
|
7048 | this.body.initialiseAndReplaceScope ?
|
7049 | this.body.initialiseAndReplaceScope( this.scope ) :
|
7050 | this.body.initialise( this.scope );
|
7051 | assignToForLoopLeft( this.left, this.scope, UNKNOWN );
|
7052 | };
|
7053 |
|
7054 | ForOfStatement.prototype.initialiseScope = function initialiseScope ( parentScope ) {
|
7055 | this.scope = new Scope( {
|
7056 | parent: parentScope,
|
7057 | isBlockScope: true,
|
7058 | isLexicalBoundary: false
|
7059 | } );
|
7060 | };
|
7061 |
|
7062 | return ForOfStatement;
|
7063 | }(Statement));
|
7064 |
|
7065 | var FunctionDeclaration = (function (Function$$1) {
|
7066 | function FunctionDeclaration () {
|
7067 | Function$$1.apply(this, arguments);
|
7068 | }
|
7069 |
|
7070 | if ( Function$$1 ) FunctionDeclaration.__proto__ = Function$$1;
|
7071 | FunctionDeclaration.prototype = Object.create( Function$$1 && Function$$1.prototype );
|
7072 | FunctionDeclaration.prototype.constructor = FunctionDeclaration;
|
7073 |
|
7074 | FunctionDeclaration.prototype.activate = function activate () {
|
7075 | if ( this.activated ) { return; }
|
7076 | this.activated = true;
|
7077 |
|
7078 | this.params.forEach( function (param) { return param.run(); } );
|
7079 | this.body.run();
|
7080 | };
|
7081 |
|
7082 | FunctionDeclaration.prototype.addReference = function addReference () {};
|
7083 |
|
7084 | FunctionDeclaration.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
7085 | values.add( this );
|
7086 | };
|
7087 |
|
7088 | FunctionDeclaration.prototype.getName = function getName () {
|
7089 | return this.name;
|
7090 | };
|
7091 |
|
7092 | FunctionDeclaration.prototype.initialiseChildren = function initialiseChildren ( parentScope ) {
|
7093 | if ( this.id ) {
|
7094 | this.name = this.id.name;
|
7095 | parentScope.addDeclaration( this.name, this, false, false );
|
7096 | this.id.initialise( parentScope );
|
7097 | }
|
7098 | Function$$1.prototype.initialiseChildren.call( this, parentScope );
|
7099 | };
|
7100 |
|
7101 | FunctionDeclaration.prototype.render = function render ( code, es ) {
|
7102 | if ( !this.module.bundle.treeshake || this.activated ) {
|
7103 | Function$$1.prototype.render.call( this, code, es );
|
7104 | } else {
|
7105 | code.remove( this.leadingCommentStart || this.start, this.next || this.end );
|
7106 | }
|
7107 | };
|
7108 |
|
7109 | FunctionDeclaration.prototype.run = function run () {
|
7110 | if ( this.parent.type === 'ExportDefaultDeclaration' ) {
|
7111 | Function$$1.prototype.run.call(this);
|
7112 | }
|
7113 | };
|
7114 |
|
7115 | return FunctionDeclaration;
|
7116 | }(Function));
|
7117 |
|
7118 | var FunctionExpression = (function (Function$$1) {
|
7119 | function FunctionExpression () {
|
7120 | Function$$1.apply(this, arguments);
|
7121 | }
|
7122 |
|
7123 | if ( Function$$1 ) FunctionExpression.__proto__ = Function$$1;
|
7124 | FunctionExpression.prototype = Object.create( Function$$1 && Function$$1.prototype );
|
7125 | FunctionExpression.prototype.constructor = FunctionExpression;
|
7126 |
|
7127 | FunctionExpression.prototype.activate = function activate () {
|
7128 | if ( this.activated ) { return; }
|
7129 | this.activated = true;
|
7130 |
|
7131 | this.params.forEach( function (param) { return param.run(); } );
|
7132 | this.body.run();
|
7133 | };
|
7134 |
|
7135 | FunctionExpression.prototype.addReference = function addReference () {};
|
7136 |
|
7137 | FunctionExpression.prototype.getName = function getName () {
|
7138 | return this.name;
|
7139 | };
|
7140 |
|
7141 | FunctionExpression.prototype.initialiseChildren = function initialiseChildren ( parentScope ) {
|
7142 | if ( this.id ) {
|
7143 | this.name = this.id.name;
|
7144 | this.scope.addDeclaration( this.name, this, false, false );
|
7145 | this.id.initialise( this.scope );
|
7146 | }
|
7147 | Function$$1.prototype.initialiseChildren.call( this, parentScope );
|
7148 | };
|
7149 |
|
7150 | return FunctionExpression;
|
7151 | }(Function));
|
7152 |
|
7153 | function isAssignmentPatternLhs (node, parent) {
|
7154 |
|
7155 |
|
7156 |
|
7157 |
|
7158 |
|
7159 |
|
7160 | return (
|
7161 | parent.type === "Property" &&
|
7162 | parent.shorthand &&
|
7163 | parent.value.type === "AssignmentPattern" &&
|
7164 | parent.value.left === node
|
7165 | );
|
7166 | }
|
7167 |
|
7168 | var Identifier = (function (Node) {
|
7169 | function Identifier () {
|
7170 | Node.apply(this, arguments);
|
7171 | }
|
7172 |
|
7173 | if ( Node ) Identifier.__proto__ = Node;
|
7174 | Identifier.prototype = Object.create( Node && Node.prototype );
|
7175 | Identifier.prototype.constructor = Identifier;
|
7176 |
|
7177 | Identifier.prototype.bind = function bind () {
|
7178 | if (isReference(this, this.parent) || isAssignmentPatternLhs(this, this.parent)) {
|
7179 | this.declaration = this.scope.findDeclaration(this.name);
|
7180 | this.declaration.addReference(this);
|
7181 | }
|
7182 | };
|
7183 |
|
7184 | Identifier.prototype.gatherPossibleValues = function gatherPossibleValues (values) {
|
7185 | if (isReference(this, this.parent)) {
|
7186 | values.add(this);
|
7187 | }
|
7188 | };
|
7189 |
|
7190 | Identifier.prototype.render = function render (code, es) {
|
7191 | if (this.declaration) {
|
7192 | var name = this.declaration.getName(es);
|
7193 | if (name !== this.name) {
|
7194 | code.overwrite(this.start, this.end, name, { storeName: true, contentOnly: false });
|
7195 |
|
7196 |
|
7197 | if (this.parent.type === "Property" && this.parent.shorthand) {
|
7198 | code.appendLeft(this.start, ((this.name) + ": "));
|
7199 | }
|
7200 | }
|
7201 | }
|
7202 | };
|
7203 |
|
7204 | Identifier.prototype.run = function run () {
|
7205 | if (this.declaration) { this.declaration.activate(); }
|
7206 | };
|
7207 |
|
7208 | return Identifier;
|
7209 | }(Node$1));
|
7210 |
|
7211 |
|
7212 | var statementsWithIfStatements = new Set( [
|
7213 | 'DoWhileStatement',
|
7214 | 'ForInStatement',
|
7215 | 'ForOfStatement',
|
7216 | 'ForStatement',
|
7217 | 'IfStatement',
|
7218 | 'WhileStatement'
|
7219 | ] );
|
7220 |
|
7221 | function handleVarDeclarations ( node, scope ) {
|
7222 | var hoistedVars = [];
|
7223 |
|
7224 | function visit ( node ) {
|
7225 | if ( node.type === 'VariableDeclaration' && node.kind === 'var' ) {
|
7226 | node.declarations.forEach( function (declarator) {
|
7227 | declarator.init = null;
|
7228 | declarator.initialise( scope );
|
7229 |
|
7230 | extractNames( declarator.id ).forEach( function (name) {
|
7231 | if ( !~hoistedVars.indexOf( name ) ) { hoistedVars.push( name ); }
|
7232 | } );
|
7233 | } );
|
7234 | }
|
7235 |
|
7236 | else if ( !/Function/.test( node.type ) ) {
|
7237 | node.eachChild( visit );
|
7238 | }
|
7239 | }
|
7240 |
|
7241 | visit( node );
|
7242 |
|
7243 | return hoistedVars;
|
7244 | }
|
7245 |
|
7246 |
|
7247 | var IfStatement = (function (Statement$$1) {
|
7248 | function IfStatement () {
|
7249 | Statement$$1.apply(this, arguments);
|
7250 | }
|
7251 |
|
7252 | if ( Statement$$1 ) IfStatement.__proto__ = Statement$$1;
|
7253 | IfStatement.prototype = Object.create( Statement$$1 && Statement$$1.prototype );
|
7254 | IfStatement.prototype.constructor = IfStatement;
|
7255 |
|
7256 | IfStatement.prototype.initialiseChildren = function initialiseChildren ( parentScope ) {
|
7257 | if ( this.module.bundle.treeshake ) {
|
7258 | this.testValue = this.test.getValue();
|
7259 |
|
7260 | if ( this.testValue === UNKNOWN ) {
|
7261 | Statement$$1.prototype.initialiseChildren.call( this, parentScope );
|
7262 | } else if ( this.testValue ) {
|
7263 | this.consequent.initialise( this.scope );
|
7264 | if ( this.alternate ) {
|
7265 | this.hoistedVars = handleVarDeclarations( this.alternate, this.scope );
|
7266 | this.alternate = null;
|
7267 | }
|
7268 | } else {
|
7269 | if ( this.alternate ) {
|
7270 | this.alternate.initialise( this.scope );
|
7271 | }
|
7272 | this.hoistedVars = handleVarDeclarations( this.consequent, this.scope );
|
7273 | this.consequent = null;
|
7274 | }
|
7275 | } else {
|
7276 | Statement$$1.prototype.initialiseChildren.call( this, parentScope );
|
7277 | }
|
7278 | };
|
7279 |
|
7280 | IfStatement.prototype.render = function render ( code, es ) {
|
7281 | var this$1 = this;
|
7282 |
|
7283 | if ( this.module.bundle.treeshake ) {
|
7284 | if ( this.testValue === UNKNOWN ) {
|
7285 | Statement$$1.prototype.render.call( this, code, es );
|
7286 | }
|
7287 |
|
7288 | else {
|
7289 | code.overwrite( this.test.start, this.test.end, JSON.stringify( this.testValue ) );
|
7290 |
|
7291 |
|
7292 |
|
7293 |
|
7294 | if ( this.hoistedVars ) {
|
7295 | var names = this.hoistedVars
|
7296 | .map( function (name) {
|
7297 | var declaration = this$1.scope.findDeclaration( name );
|
7298 | return declaration.activated ? declaration.getName() : null;
|
7299 | } )
|
7300 | .filter( Boolean );
|
7301 |
|
7302 | if ( names.length > 0 ) {
|
7303 | code.appendLeft( this.start, ("var " + (names.join( ', ' )) + ";\n\n") );
|
7304 | }
|
7305 | }
|
7306 |
|
7307 | if ( this.testValue ) {
|
7308 | code.remove( this.start, this.consequent.start );
|
7309 | code.remove( this.consequent.end, this.end );
|
7310 | this.consequent.render( code, es );
|
7311 | }
|
7312 |
|
7313 | else {
|
7314 | code.remove( this.start, this.alternate ? this.alternate.start : this.next || this.end );
|
7315 |
|
7316 | if ( this.alternate ) {
|
7317 | this.alternate.render( code, es );
|
7318 | }
|
7319 |
|
7320 | else if ( statementsWithIfStatements.has( this.parent.type ) ) {
|
7321 | code.prependRight( this.start, '{}' );
|
7322 | }
|
7323 | }
|
7324 | }
|
7325 | }
|
7326 |
|
7327 | else {
|
7328 | Statement$$1.prototype.render.call( this, code, es );
|
7329 | }
|
7330 | };
|
7331 |
|
7332 | return IfStatement;
|
7333 | }(Statement));
|
7334 |
|
7335 | var ImportDeclaration = (function (Node) {
|
7336 | function ImportDeclaration () {
|
7337 | Node.apply(this, arguments);
|
7338 | }
|
7339 |
|
7340 | if ( Node ) ImportDeclaration.__proto__ = Node;
|
7341 | ImportDeclaration.prototype = Object.create( Node && Node.prototype );
|
7342 | ImportDeclaration.prototype.constructor = ImportDeclaration;
|
7343 |
|
7344 | ImportDeclaration.prototype.bind = function bind () {
|
7345 |
|
7346 |
|
7347 | };
|
7348 |
|
7349 | ImportDeclaration.prototype.initialiseNode = function initialiseNode () {
|
7350 | this.isImportDeclaration = true;
|
7351 | };
|
7352 |
|
7353 | ImportDeclaration.prototype.render = function render ( code ) {
|
7354 | code.remove( this.start, this.next || this.end );
|
7355 | };
|
7356 |
|
7357 | return ImportDeclaration;
|
7358 | }(Node$1));
|
7359 |
|
7360 | var Literal = (function (Node) {
|
7361 | function Literal () {
|
7362 | Node.apply(this, arguments);
|
7363 | }
|
7364 |
|
7365 | if ( Node ) Literal.__proto__ = Node;
|
7366 | Literal.prototype = Object.create( Node && Node.prototype );
|
7367 | Literal.prototype.constructor = Literal;
|
7368 |
|
7369 | Literal.prototype.getValue = function getValue () {
|
7370 | return this.value;
|
7371 | };
|
7372 |
|
7373 | Literal.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
7374 | values.add( this );
|
7375 | };
|
7376 |
|
7377 | Literal.prototype.render = function render ( code ) {
|
7378 | if ( typeof this.value === 'string' ) {
|
7379 | code.indentExclusionRanges.push( [ this.start + 1, this.end - 1 ] );
|
7380 | }
|
7381 | };
|
7382 |
|
7383 | return Literal;
|
7384 | }(Node$1));
|
7385 |
|
7386 | var operators$1 = {
|
7387 | '&&': function ( left, right ) { return left && right; },
|
7388 | '||': function ( left, right ) { return left || right; }
|
7389 | };
|
7390 |
|
7391 | var LogicalExpression = (function (Node) {
|
7392 | function LogicalExpression () {
|
7393 | Node.apply(this, arguments);
|
7394 | }
|
7395 |
|
7396 | if ( Node ) LogicalExpression.__proto__ = Node;
|
7397 | LogicalExpression.prototype = Object.create( Node && Node.prototype );
|
7398 | LogicalExpression.prototype.constructor = LogicalExpression;
|
7399 |
|
7400 | LogicalExpression.prototype.getValue = function getValue () {
|
7401 | var leftValue = this.left.getValue();
|
7402 | if ( leftValue === UNKNOWN ) { return UNKNOWN; }
|
7403 |
|
7404 | var rightValue = this.right.getValue();
|
7405 | if ( rightValue === UNKNOWN ) { return UNKNOWN; }
|
7406 |
|
7407 | return operators$1[ this.operator ]( leftValue, rightValue );
|
7408 | };
|
7409 |
|
7410 | return LogicalExpression;
|
7411 | }(Node$1));
|
7412 |
|
7413 | var validProp = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
|
7414 |
|
7415 | var Keypath = function Keypath ( node ) {
|
7416 | var this$1 = this;
|
7417 |
|
7418 | this.parts = [];
|
7419 |
|
7420 | while ( node.type === 'MemberExpression' ) {
|
7421 | var prop = node.property;
|
7422 |
|
7423 | if ( node.computed ) {
|
7424 | if ( prop.type !== 'Literal' || typeof prop.value !== 'string' || !validProp.test( prop.value ) ) {
|
7425 | this$1.computed = true;
|
7426 | return;
|
7427 | }
|
7428 | }
|
7429 |
|
7430 | this$1.parts.unshift( prop );
|
7431 | node = node.object;
|
7432 | }
|
7433 |
|
7434 | this.root = node;
|
7435 | };
|
7436 |
|
7437 | var MemberExpression = (function (Node) {
|
7438 | function MemberExpression () {
|
7439 | Node.apply(this, arguments);
|
7440 | }
|
7441 |
|
7442 | if ( Node ) MemberExpression.__proto__ = Node;
|
7443 | MemberExpression.prototype = Object.create( Node && Node.prototype );
|
7444 | MemberExpression.prototype.constructor = MemberExpression;
|
7445 |
|
7446 | MemberExpression.prototype.bind = function bind () {
|
7447 | var this$1 = this;
|
7448 |
|
7449 |
|
7450 |
|
7451 |
|
7452 | var keypath = new Keypath( this );
|
7453 |
|
7454 | if ( !keypath.computed && keypath.root.type === 'Identifier' ) {
|
7455 | var declaration = this.scope.findDeclaration( keypath.root.name );
|
7456 |
|
7457 | while ( declaration.isNamespace && keypath.parts.length ) {
|
7458 | var exporterId = declaration.module.id;
|
7459 |
|
7460 | var part = keypath.parts[ 0 ];
|
7461 | declaration = declaration.module.traceExport( part.name || part.value );
|
7462 |
|
7463 | if ( !declaration ) {
|
7464 | this$1.module.warn( {
|
7465 | code: 'MISSING_EXPORT',
|
7466 | missing: part.name || part.value,
|
7467 | importer: relativeId( this$1.module.id ),
|
7468 | exporter: relativeId( exporterId ),
|
7469 | message: ("'" + (part.name || part.value) + "' is not exported by '" + (relativeId( exporterId )) + "'"),
|
7470 | url: "https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module"
|
7471 | }, part.start );
|
7472 | this$1.replacement = 'undefined';
|
7473 | return;
|
7474 | }
|
7475 |
|
7476 | keypath.parts.shift();
|
7477 | }
|
7478 |
|
7479 | if ( keypath.parts.length ) {
|
7480 | Node.prototype.bind.call(this);
|
7481 | return;
|
7482 | }
|
7483 |
|
7484 | this.declaration = declaration;
|
7485 |
|
7486 | if ( declaration.isExternal ) {
|
7487 | declaration.module.suggestName( keypath.root.name );
|
7488 | }
|
7489 | }
|
7490 |
|
7491 | else {
|
7492 | Node.prototype.bind.call(this);
|
7493 | }
|
7494 | };
|
7495 |
|
7496 | MemberExpression.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
7497 | values.add( UNKNOWN );
|
7498 | };
|
7499 |
|
7500 | MemberExpression.prototype.render = function render ( code, es ) {
|
7501 | if ( this.declaration ) {
|
7502 | var name = this.declaration.getName( es );
|
7503 | if ( name !== this.name ) { code.overwrite( this.start, this.end, name, { storeName: true, contentOnly: false } ); }
|
7504 | }
|
7505 |
|
7506 | else if ( this.replacement ) {
|
7507 | code.overwrite( this.start, this.end, this.replacement, { storeName: true, contentOnly: false } );
|
7508 | }
|
7509 |
|
7510 | Node.prototype.render.call( this, code, es );
|
7511 | };
|
7512 |
|
7513 | MemberExpression.prototype.run = function run () {
|
7514 | if ( this.declaration ) { this.declaration.activate(); }
|
7515 | Node.prototype.run.call(this);
|
7516 | };
|
7517 |
|
7518 | return MemberExpression;
|
7519 | }(Node$1));
|
7520 |
|
7521 | var NewExpression = (function (Node) {
|
7522 | function NewExpression () {
|
7523 | Node.apply(this, arguments);
|
7524 | }
|
7525 |
|
7526 | if ( Node ) NewExpression.__proto__ = Node;
|
7527 | NewExpression.prototype = Object.create( Node && Node.prototype );
|
7528 | NewExpression.prototype.constructor = NewExpression;
|
7529 |
|
7530 | NewExpression.prototype.hasEffects = function hasEffects () {
|
7531 | return callHasEffects( this.scope, this.callee, true );
|
7532 | };
|
7533 |
|
7534 | return NewExpression;
|
7535 | }(Node$1));
|
7536 |
|
7537 | var ObjectExpression = (function (Node) {
|
7538 | function ObjectExpression () {
|
7539 | Node.apply(this, arguments);
|
7540 | }
|
7541 |
|
7542 | if ( Node ) ObjectExpression.__proto__ = Node;
|
7543 | ObjectExpression.prototype = Object.create( Node && Node.prototype );
|
7544 | ObjectExpression.prototype.constructor = ObjectExpression;
|
7545 |
|
7546 | ObjectExpression.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
7547 | values.add( OBJECT );
|
7548 | };
|
7549 |
|
7550 | return ObjectExpression;
|
7551 | }(Node$1));
|
7552 |
|
7553 | var SwitchStatement = (function (Statement$$1) {
|
7554 | function SwitchStatement () {
|
7555 | Statement$$1.apply(this, arguments);
|
7556 | }
|
7557 |
|
7558 | if ( Statement$$1 ) SwitchStatement.__proto__ = Statement$$1;
|
7559 | SwitchStatement.prototype = Object.create( Statement$$1 && Statement$$1.prototype );
|
7560 | SwitchStatement.prototype.constructor = SwitchStatement;
|
7561 |
|
7562 | SwitchStatement.prototype.initialiseScope = function initialiseScope ( parentScope ) {
|
7563 | this.scope = new Scope( {
|
7564 | parent: parentScope,
|
7565 | isBlockScope: true,
|
7566 | isLexicalBoundary: false
|
7567 | } );
|
7568 | };
|
7569 |
|
7570 | return SwitchStatement;
|
7571 | }(Statement));
|
7572 |
|
7573 | var TaggedTemplateExpression = (function (Node) {
|
7574 | function TaggedTemplateExpression () {
|
7575 | Node.apply(this, arguments);
|
7576 | }
|
7577 |
|
7578 | if ( Node ) TaggedTemplateExpression.__proto__ = Node;
|
7579 | TaggedTemplateExpression.prototype = Object.create( Node && Node.prototype );
|
7580 | TaggedTemplateExpression.prototype.constructor = TaggedTemplateExpression;
|
7581 |
|
7582 | TaggedTemplateExpression.prototype.bind = function bind () {
|
7583 | if ( this.tag.type === 'Identifier' ) {
|
7584 | var declaration = this.scope.findDeclaration( this.tag.name );
|
7585 |
|
7586 | if ( declaration.isNamespace ) {
|
7587 | this.module.error({
|
7588 | code: 'CANNOT_CALL_NAMESPACE',
|
7589 | message: ("Cannot call a namespace ('" + (this.tag.name) + "')")
|
7590 | }, this.start );
|
7591 | }
|
7592 |
|
7593 | if ( this.tag.name === 'eval' && declaration.isGlobal ) {
|
7594 | this.module.warn({
|
7595 | code: 'EVAL',
|
7596 | message: "Use of eval is strongly discouraged, as it poses security risks and may cause issues with minification",
|
7597 | url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval'
|
7598 | }, this.start );
|
7599 | }
|
7600 | }
|
7601 |
|
7602 | Node.prototype.bind.call(this);
|
7603 | };
|
7604 |
|
7605 | TaggedTemplateExpression.prototype.hasEffects = function hasEffects () {
|
7606 | return this.quasi.hasEffects() || callHasEffects( this.scope, this.tag, false );
|
7607 | };
|
7608 |
|
7609 | TaggedTemplateExpression.prototype.initialiseNode = function initialiseNode () {
|
7610 | if ( isProgramLevel( this ) ) {
|
7611 | this.module.bundle.dependentExpressions.push( this );
|
7612 | }
|
7613 | };
|
7614 |
|
7615 | TaggedTemplateExpression.prototype.isUsedByBundle = function isUsedByBundle () {
|
7616 | return this.hasEffects();
|
7617 | };
|
7618 |
|
7619 | return TaggedTemplateExpression;
|
7620 | }(Node$1));
|
7621 |
|
7622 | var TemplateLiteral = (function (Node) {
|
7623 | function TemplateLiteral () {
|
7624 | Node.apply(this, arguments);
|
7625 | }
|
7626 |
|
7627 | if ( Node ) TemplateLiteral.__proto__ = Node;
|
7628 | TemplateLiteral.prototype = Object.create( Node && Node.prototype );
|
7629 | TemplateLiteral.prototype.constructor = TemplateLiteral;
|
7630 |
|
7631 | TemplateLiteral.prototype.render = function render ( code, es ) {
|
7632 | code.indentExclusionRanges.push( [ this.start, this.end ] );
|
7633 | Node.prototype.render.call( this, code, es );
|
7634 | };
|
7635 |
|
7636 | return TemplateLiteral;
|
7637 | }(Node$1));
|
7638 |
|
7639 | var ThisExpression = (function (Node) {
|
7640 | function ThisExpression () {
|
7641 | Node.apply(this, arguments);
|
7642 | }
|
7643 |
|
7644 | if ( Node ) ThisExpression.__proto__ = Node;
|
7645 | ThisExpression.prototype = Object.create( Node && Node.prototype );
|
7646 | ThisExpression.prototype.constructor = ThisExpression;
|
7647 |
|
7648 | ThisExpression.prototype.initialiseNode = function initialiseNode () {
|
7649 | var lexicalBoundary = this.scope.findLexicalBoundary();
|
7650 |
|
7651 | if ( lexicalBoundary.isModuleScope ) {
|
7652 | this.alias = this.module.context;
|
7653 | if ( this.alias === 'undefined' ) {
|
7654 | this.module.warn( {
|
7655 | code: 'THIS_IS_UNDEFINED',
|
7656 | message: "The 'this' keyword is equivalent to 'undefined' at the top level of an ES module, and has been rewritten",
|
7657 | url: "https://github.com/rollup/rollup/wiki/Troubleshooting#this-is-undefined"
|
7658 | }, this.start );
|
7659 | }
|
7660 | }
|
7661 | };
|
7662 |
|
7663 | ThisExpression.prototype.render = function render ( code ) {
|
7664 | if ( this.alias ) {
|
7665 | code.overwrite( this.start, this.end, this.alias, { storeName: true, contentOnly: false } );
|
7666 | }
|
7667 | };
|
7668 |
|
7669 | return ThisExpression;
|
7670 | }(Node$1));
|
7671 |
|
7672 | var ThrowStatement = (function (Node) {
|
7673 | function ThrowStatement () {
|
7674 | Node.apply(this, arguments);
|
7675 | }
|
7676 |
|
7677 | if ( Node ) ThrowStatement.__proto__ = Node;
|
7678 | ThrowStatement.prototype = Object.create( Node && Node.prototype );
|
7679 | ThrowStatement.prototype.constructor = ThrowStatement;
|
7680 |
|
7681 | ThrowStatement.prototype.hasEffects = function hasEffects () {
|
7682 | return true;
|
7683 | };
|
7684 |
|
7685 | return ThrowStatement;
|
7686 | }(Node$1));
|
7687 |
|
7688 | var operators$2 = {
|
7689 | '-': function (value) { return -value; },
|
7690 | '+': function (value) { return +value; },
|
7691 | '!': function (value) { return !value; },
|
7692 | '~': function (value) { return ~value; },
|
7693 | typeof: function (value) { return typeof value; },
|
7694 | void: function () { return undefined; },
|
7695 | delete: function () { return UNKNOWN; }
|
7696 | };
|
7697 |
|
7698 | var UnaryExpression = (function (Node) {
|
7699 | function UnaryExpression () {
|
7700 | Node.apply(this, arguments);
|
7701 | }
|
7702 |
|
7703 | if ( Node ) UnaryExpression.__proto__ = Node;
|
7704 | UnaryExpression.prototype = Object.create( Node && Node.prototype );
|
7705 | UnaryExpression.prototype.constructor = UnaryExpression;
|
7706 |
|
7707 | UnaryExpression.prototype.bind = function bind () {
|
7708 | if ( this.value === UNKNOWN ) { Node.prototype.bind.call(this); }
|
7709 | };
|
7710 |
|
7711 | UnaryExpression.prototype.getValue = function getValue () {
|
7712 | var argumentValue = this.argument.getValue();
|
7713 | if ( argumentValue === UNKNOWN ) { return UNKNOWN; }
|
7714 |
|
7715 | return operators$2[ this.operator ]( argumentValue );
|
7716 | };
|
7717 |
|
7718 | UnaryExpression.prototype.hasEffects = function hasEffects () {
|
7719 | return this.operator === 'delete' || this.argument.hasEffects();
|
7720 | };
|
7721 |
|
7722 | UnaryExpression.prototype.initialiseNode = function initialiseNode () {
|
7723 | this.value = this.getValue();
|
7724 | };
|
7725 |
|
7726 | return UnaryExpression;
|
7727 | }(Node$1));
|
7728 |
|
7729 | var UpdateExpression = (function (Node) {
|
7730 | function UpdateExpression () {
|
7731 | Node.apply(this, arguments);
|
7732 | }
|
7733 |
|
7734 | if ( Node ) UpdateExpression.__proto__ = Node;
|
7735 | UpdateExpression.prototype = Object.create( Node && Node.prototype );
|
7736 | UpdateExpression.prototype.constructor = UpdateExpression;
|
7737 |
|
7738 | UpdateExpression.prototype.bind = function bind () {
|
7739 | var subject = this.argument;
|
7740 |
|
7741 | this.subject = subject;
|
7742 | disallowIllegalReassignment( this.scope, this.argument );
|
7743 |
|
7744 | if ( subject.type === 'Identifier' ) {
|
7745 | var declaration = this.scope.findDeclaration( subject.name );
|
7746 | declaration.isReassigned = true;
|
7747 |
|
7748 | if ( declaration.possibleValues ) {
|
7749 | declaration.possibleValues.add( NUMBER );
|
7750 | }
|
7751 | }
|
7752 |
|
7753 | Node.prototype.bind.call(this);
|
7754 | };
|
7755 |
|
7756 | UpdateExpression.prototype.hasEffects = function hasEffects () {
|
7757 | return isUsedByBundle( this.scope, this.subject );
|
7758 | };
|
7759 |
|
7760 | UpdateExpression.prototype.initialiseNode = function initialiseNode () {
|
7761 | this.module.bundle.dependentExpressions.push( this );
|
7762 | };
|
7763 |
|
7764 | UpdateExpression.prototype.isUsedByBundle = function isUsedByBundle$1 () {
|
7765 | return isUsedByBundle( this.scope, this.subject );
|
7766 | };
|
7767 |
|
7768 | return UpdateExpression;
|
7769 | }(Node$1));
|
7770 |
|
7771 | var DeclaratorProxy = function DeclaratorProxy ( name, declarator, isTopLevel, init ) {
|
7772 | this.name = name;
|
7773 | this.declarator = declarator;
|
7774 |
|
7775 | this.activated = false;
|
7776 | this.isReassigned = false;
|
7777 | this.exportName = null;
|
7778 |
|
7779 | this.duplicates = [];
|
7780 | this.possibleValues = new Set( init ? [ init ] : null );
|
7781 | };
|
7782 |
|
7783 | DeclaratorProxy.prototype.activate = function activate () {
|
7784 | this.activated = true;
|
7785 | this.declarator.activate();
|
7786 | this.duplicates.forEach( function (dupe) { return dupe.activate(); } );
|
7787 | };
|
7788 |
|
7789 | DeclaratorProxy.prototype.addReference = function addReference () {
|
7790 |
|
7791 | };
|
7792 |
|
7793 | DeclaratorProxy.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
7794 | this.possibleValues.forEach( function (value) { return values.add( value ); } );
|
7795 | };
|
7796 |
|
7797 | DeclaratorProxy.prototype.getName = function getName ( es ) {
|
7798 |
|
7799 | if ( es ) { return this.name; }
|
7800 | if ( !this.isReassigned || !this.exportName ) { return this.name; }
|
7801 |
|
7802 | return ("exports." + (this.exportName));
|
7803 | };
|
7804 |
|
7805 | DeclaratorProxy.prototype.toString = function toString () {
|
7806 | return this.name;
|
7807 | };
|
7808 |
|
7809 | var VariableDeclarator = (function (Node) {
|
7810 | function VariableDeclarator () {
|
7811 | Node.apply(this, arguments);
|
7812 | }
|
7813 |
|
7814 | if ( Node ) VariableDeclarator.__proto__ = Node;
|
7815 | VariableDeclarator.prototype = Object.create( Node && Node.prototype );
|
7816 | VariableDeclarator.prototype.constructor = VariableDeclarator;
|
7817 |
|
7818 | VariableDeclarator.prototype.activate = function activate () {
|
7819 | if ( this.activated ) { return; }
|
7820 | this.activated = true;
|
7821 |
|
7822 | this.run();
|
7823 |
|
7824 |
|
7825 |
|
7826 | if ( this.parent.kind === 'var' ) {
|
7827 | var node = this.parent.parent;
|
7828 | while ( /Statement/.test( node.type ) ) {
|
7829 | node.shouldInclude = true;
|
7830 | node = node.parent;
|
7831 | }
|
7832 | }
|
7833 | };
|
7834 |
|
7835 | VariableDeclarator.prototype.hasEffects = function hasEffects () {
|
7836 | return this.init && this.init.hasEffects();
|
7837 | };
|
7838 |
|
7839 | VariableDeclarator.prototype.initialiseNode = function initialiseNode () {
|
7840 | var this$1 = this;
|
7841 |
|
7842 | this.proxies = new Map();
|
7843 | var lexicalBoundary = this.scope.findLexicalBoundary();
|
7844 | var init = this.init ? ( this.id.type === 'Identifier' ? this.init : UNKNOWN ) :
|
7845 | null;
|
7846 |
|
7847 | extractNames( this.id ).forEach( function (name) {
|
7848 | var proxy = new DeclaratorProxy( name, this$1, lexicalBoundary.isModuleScope, init );
|
7849 |
|
7850 | this$1.proxies.set( name, proxy );
|
7851 | this$1.scope.addDeclaration( name, proxy, this$1.parent.kind === 'var' );
|
7852 | } );
|
7853 | };
|
7854 |
|
7855 | VariableDeclarator.prototype.render = function render ( code, es ) {
|
7856 | var this$1 = this;
|
7857 |
|
7858 | extractNames( this.id ).forEach( function (name) {
|
7859 | var declaration = this$1.proxies.get( name );
|
7860 |
|
7861 | if ( !es && declaration.exportName && declaration.isReassigned ) {
|
7862 | if ( this$1.init ) {
|
7863 | code.overwrite( this$1.start, this$1.id.end, declaration.getName( es ) );
|
7864 | } else if ( this$1.module.bundle.treeshake ) {
|
7865 | code.remove( this$1.start, this$1.end );
|
7866 | }
|
7867 | }
|
7868 | } );
|
7869 |
|
7870 | Node.prototype.render.call( this, code, es );
|
7871 | };
|
7872 |
|
7873 | return VariableDeclarator;
|
7874 | }(Node$1));
|
7875 |
|
7876 | function getSeparator (code, start) {
|
7877 | var c = start;
|
7878 |
|
7879 | while (c > 0 && code[c - 1] !== "\n") {
|
7880 | c -= 1;
|
7881 | if (code[c] === ";" || code[c] === "{") { return "; "; }
|
7882 | }
|
7883 |
|
7884 | var lineStart = code.slice(c, start).match(/^\s*/)[0];
|
7885 |
|
7886 | return (";\n" + lineStart);
|
7887 | }
|
7888 |
|
7889 | var forStatement = /^For(?:Of|In)?Statement/;
|
7890 |
|
7891 | var VariableDeclaration = (function (Node) {
|
7892 | function VariableDeclaration () {
|
7893 | Node.apply(this, arguments);
|
7894 | }
|
7895 |
|
7896 | if ( Node ) VariableDeclaration.__proto__ = Node;
|
7897 | VariableDeclaration.prototype = Object.create( Node && Node.prototype );
|
7898 | VariableDeclaration.prototype.constructor = VariableDeclaration;
|
7899 |
|
7900 | VariableDeclaration.prototype.render = function render (code, es) {
|
7901 | var this$1 = this;
|
7902 |
|
7903 | var treeshake = this.module.bundle.treeshake;
|
7904 |
|
7905 | var shouldSeparate = false;
|
7906 | var separator;
|
7907 |
|
7908 | if (this.scope.isModuleScope && !forStatement.test(this.parent.type)) {
|
7909 | shouldSeparate = true;
|
7910 | separator = getSeparator(this.module.code, this.start);
|
7911 | }
|
7912 |
|
7913 | var c = this.start;
|
7914 | var empty = true;
|
7915 |
|
7916 | var loop = function ( i ) {
|
7917 | var declarator = this$1.declarations[i];
|
7918 |
|
7919 | var prefix = empty ? "" : separator;
|
7920 |
|
7921 | if (declarator.id.type === "Identifier") {
|
7922 | var proxy = declarator.proxies.get(declarator.id.name);
|
7923 | var isExportedAndReassigned = !es && proxy.exportName && proxy.isReassigned;
|
7924 |
|
7925 | if (isExportedAndReassigned) {
|
7926 | if (declarator.init) {
|
7927 | if (shouldSeparate) { code.overwrite(c, declarator.start, prefix); }
|
7928 | c = declarator.end;
|
7929 | empty = false;
|
7930 | }
|
7931 | } else if (!treeshake || proxy.activated) {
|
7932 | if (shouldSeparate) { code.overwrite(c, declarator.start, ("" + prefix + (this$1.kind) + " ")); }
|
7933 | c = declarator.end;
|
7934 | empty = false;
|
7935 | }
|
7936 | } else {
|
7937 | var exportAssignments = [];
|
7938 | var activated = false;
|
7939 |
|
7940 | extractNames(declarator.id).forEach(function (name) {
|
7941 | var proxy = declarator.proxies.get(name);
|
7942 | var isExportedAndReassigned = !es && proxy.exportName && proxy.isReassigned;
|
7943 |
|
7944 | if (isExportedAndReassigned) {
|
7945 |
|
7946 |
|
7947 |
|
7948 | exportAssignments.push("TODO");
|
7949 | } else if (declarator.activated) {
|
7950 | activated = true;
|
7951 | }
|
7952 | });
|
7953 |
|
7954 | if (!treeshake || activated) {
|
7955 | if (shouldSeparate) { code.overwrite(c, declarator.start, ("" + prefix + (this$1.kind) + " ")); }
|
7956 | c = declarator.end;
|
7957 | empty = false;
|
7958 | }
|
7959 |
|
7960 | if (exportAssignments.length) {
|
7961 | throw new Error("TODO");
|
7962 | }
|
7963 | }
|
7964 |
|
7965 | declarator.render(code, es);
|
7966 | };
|
7967 |
|
7968 | for (var i = 0; i < this.declarations.length; i += 1) loop( i );
|
7969 |
|
7970 | if (treeshake && empty) {
|
7971 | code.remove(this.leadingCommentStart || this.start, this.next || this.end);
|
7972 | } else {
|
7973 |
|
7974 |
|
7975 | var needsSemicolon = !forStatement.test( this.parent.type ) || this === this.parent.body;
|
7976 |
|
7977 | if (this.end > c) {
|
7978 | code.overwrite(c, this.end, needsSemicolon ? ";" : "");
|
7979 | } else if (needsSemicolon) {
|
7980 | this.insertSemicolon(code);
|
7981 | }
|
7982 | }
|
7983 | };
|
7984 |
|
7985 | return VariableDeclaration;
|
7986 | }(Node$1));
|
7987 |
|
7988 | var nodes = {
|
7989 | ArrayExpression: ArrayExpression,
|
7990 | ArrowFunctionExpression: ArrowFunctionExpression,
|
7991 | AssignmentExpression: AssignmentExpression,
|
7992 | BinaryExpression: BinaryExpression,
|
7993 | BlockStatement: BlockStatement,
|
7994 | CallExpression: CallExpression,
|
7995 | CatchClause: CatchClause,
|
7996 | ClassDeclaration: ClassDeclaration,
|
7997 | ClassExpression: ClassExpression$1,
|
7998 | ConditionalExpression: ConditionalExpression,
|
7999 | DoWhileStatement: Statement,
|
8000 | EmptyStatement: EmptyStatement,
|
8001 | ExportAllDeclaration: ExportAllDeclaration,
|
8002 | ExportDefaultDeclaration: ExportDefaultDeclaration,
|
8003 | ExportNamedDeclaration: ExportNamedDeclaration,
|
8004 | ExpressionStatement: ExpressionStatement,
|
8005 | ForStatement: ForStatement,
|
8006 | ForInStatement: ForInStatement,
|
8007 | ForOfStatement: ForOfStatement,
|
8008 | FunctionDeclaration: FunctionDeclaration,
|
8009 | FunctionExpression: FunctionExpression,
|
8010 | Identifier: Identifier,
|
8011 | IfStatement: IfStatement,
|
8012 | ImportDeclaration: ImportDeclaration,
|
8013 | Literal: Literal,
|
8014 | LogicalExpression: LogicalExpression,
|
8015 | MemberExpression: MemberExpression,
|
8016 | NewExpression: NewExpression,
|
8017 | ObjectExpression: ObjectExpression,
|
8018 | ReturnStatement: Statement,
|
8019 | SwitchStatement: SwitchStatement,
|
8020 | TaggedTemplateExpression: TaggedTemplateExpression,
|
8021 | TemplateLiteral: TemplateLiteral,
|
8022 | ThisExpression: ThisExpression,
|
8023 | ThrowStatement: ThrowStatement,
|
8024 | TryStatement: Statement,
|
8025 | UnaryExpression: UnaryExpression,
|
8026 | UpdateExpression: UpdateExpression,
|
8027 | VariableDeclarator: VariableDeclarator,
|
8028 | VariableDeclaration: VariableDeclaration,
|
8029 | WhileStatement: Statement
|
8030 | };
|
8031 |
|
8032 | var keys$1 = {
|
8033 | Program: [ 'body' ],
|
8034 | Literal: []
|
8035 | };
|
8036 |
|
8037 | var newline = /\n/;
|
8038 |
|
8039 | function enhance ( ast, module, comments ) {
|
8040 | enhanceNode( ast, module, module, module.magicString );
|
8041 |
|
8042 | var comment = comments.shift();
|
8043 |
|
8044 | for ( var node of ast.body ) {
|
8045 | if ( comment && ( comment.start < node.start ) ) {
|
8046 | node.leadingCommentStart = comment.start;
|
8047 | }
|
8048 |
|
8049 | while ( comment && comment.end < node.end ) { comment = comments.shift(); }
|
8050 |
|
8051 |
|
8052 |
|
8053 | if ( comment && !newline.test( module.code.slice( node.end, comment.start ) ) ) {
|
8054 | node.trailingCommentEnd = comment.end;
|
8055 | comment = comments.shift();
|
8056 | }
|
8057 |
|
8058 | node.initialise( module.scope );
|
8059 | }
|
8060 | }
|
8061 |
|
8062 | function enhanceNode ( raw, parent, module, code ) {
|
8063 | if ( !raw ) { return; }
|
8064 |
|
8065 | if ( 'length' in raw ) {
|
8066 | for ( var i = 0; i < raw.length; i += 1 ) {
|
8067 | enhanceNode( raw[i], parent, module, code );
|
8068 | }
|
8069 |
|
8070 | return;
|
8071 | }
|
8072 |
|
8073 |
|
8074 |
|
8075 | if ( raw.__enhanced ) { return; }
|
8076 | raw.__enhanced = true;
|
8077 |
|
8078 | if ( !keys$1[ raw.type ] ) {
|
8079 | keys$1[ raw.type ] = Object.keys( raw ).filter( function (key) { return typeof raw[ key ] === 'object'; } );
|
8080 | }
|
8081 |
|
8082 | raw.parent = parent;
|
8083 | raw.module = module;
|
8084 | raw.keys = keys$1[ raw.type ];
|
8085 |
|
8086 | code.addSourcemapLocation( raw.start );
|
8087 | code.addSourcemapLocation( raw.end );
|
8088 |
|
8089 | for ( var key of keys$1[ raw.type ] ) {
|
8090 | enhanceNode( raw[ key ], raw, module, code );
|
8091 | }
|
8092 |
|
8093 | var type = nodes[ raw.type ] || Node$1;
|
8094 | raw.__proto__ = type.prototype;
|
8095 | }
|
8096 |
|
8097 | function clone ( node ) {
|
8098 | if ( !node ) { return node; }
|
8099 | if ( typeof node !== 'object' ) { return node; }
|
8100 |
|
8101 | if ( Array.isArray( node ) ) {
|
8102 | var cloned$1 = new Array( node.length );
|
8103 | for ( var i = 0; i < node.length; i += 1 ) { cloned$1[i] = clone( node[i] ); }
|
8104 | return cloned$1;
|
8105 | }
|
8106 |
|
8107 | var cloned = {};
|
8108 | for ( var key in node ) {
|
8109 | cloned[ key ] = clone( node[ key ] );
|
8110 | }
|
8111 |
|
8112 | return cloned;
|
8113 | }
|
8114 |
|
8115 | var ModuleScope = (function (Scope$$1) {
|
8116 | function ModuleScope ( module ) {
|
8117 | Scope$$1.call(this, {
|
8118 | isBlockScope: false,
|
8119 | isLexicalBoundary: true,
|
8120 | isModuleScope: true,
|
8121 | parent: module.bundle.scope
|
8122 | });
|
8123 |
|
8124 | this.module = module;
|
8125 | }
|
8126 |
|
8127 | if ( Scope$$1 ) ModuleScope.__proto__ = Scope$$1;
|
8128 | ModuleScope.prototype = Object.create( Scope$$1 && Scope$$1.prototype );
|
8129 | ModuleScope.prototype.constructor = ModuleScope;
|
8130 |
|
8131 | ModuleScope.prototype.deshadow = function deshadow ( names ) {
|
8132 | var this$1 = this;
|
8133 |
|
8134 | names = new Set( names );
|
8135 |
|
8136 | forOwn( this.module.imports, function (specifier) {
|
8137 | if ( specifier.module.isExternal ) { return; }
|
8138 |
|
8139 | var addDeclaration = function (declaration) {
|
8140 | if ( declaration.isNamespace && !declaration.isExternal ) {
|
8141 | declaration.module.getExports().forEach( function (name) {
|
8142 | addDeclaration( declaration.module.traceExport(name) );
|
8143 | });
|
8144 | }
|
8145 |
|
8146 | names.add( declaration.name );
|
8147 | };
|
8148 |
|
8149 | specifier.module.getExports().forEach( function (name) {
|
8150 | addDeclaration( specifier.module.traceExport(name) );
|
8151 | });
|
8152 |
|
8153 | if ( specifier.name !== '*' ) {
|
8154 | var declaration = specifier.module.traceExport( specifier.name );
|
8155 | if ( !declaration ) {
|
8156 | this$1.module.warn({
|
8157 | code: 'NON_EXISTENT_EXPORT',
|
8158 | name: specifier.name,
|
8159 | source: specifier.module.id,
|
8160 | message: ("Non-existent export '" + (specifier.name) + "' is imported from " + (relativeId( specifier.module.id )))
|
8161 | }, specifier.specifier.start );
|
8162 | return;
|
8163 | }
|
8164 |
|
8165 | var name = declaration.getName( true );
|
8166 | if ( name !== specifier.name ) {
|
8167 | names.add( declaration.getName( true ) );
|
8168 | }
|
8169 |
|
8170 | if ( specifier.name !== 'default' && specifier.specifier.imported.name !== specifier.specifier.local.name ) {
|
8171 | names.add( specifier.specifier.imported.name );
|
8172 | }
|
8173 | }
|
8174 | });
|
8175 |
|
8176 | Scope$$1.prototype.deshadow.call( this, names );
|
8177 | };
|
8178 |
|
8179 | ModuleScope.prototype.findDeclaration = function findDeclaration ( name ) {
|
8180 | if ( this.declarations[ name ] ) {
|
8181 | return this.declarations[ name ];
|
8182 | }
|
8183 |
|
8184 | return this.module.trace( name ) || this.parent.findDeclaration( name );
|
8185 | };
|
8186 |
|
8187 | ModuleScope.prototype.findLexicalBoundary = function findLexicalBoundary () {
|
8188 | return this;
|
8189 | };
|
8190 |
|
8191 | return ModuleScope;
|
8192 | }(Scope));
|
8193 |
|
8194 | function tryParse ( module, acornOptions ) {
|
8195 | try {
|
8196 | return parse( module.code, assign( {
|
8197 | ecmaVersion: 8,
|
8198 | sourceType: 'module',
|
8199 | onComment: function ( block, text, start, end ) { return module.comments.push( { block: block, text: text, start: start, end: end } ); },
|
8200 | preserveParens: false
|
8201 | }, acornOptions ) );
|
8202 | } catch ( err ) {
|
8203 | module.error( {
|
8204 | code: 'PARSE_ERROR',
|
8205 | message: err.message.replace( / \(\d+:\d+\)$/, '' )
|
8206 | }, err.pos );
|
8207 | }
|
8208 | }
|
8209 |
|
8210 | var Module = function Module ( ref ) {
|
8211 | var this$1 = this;
|
8212 | var id = ref.id;
|
8213 | var code = ref.code;
|
8214 | var originalCode = ref.originalCode;
|
8215 | var originalSourceMap = ref.originalSourceMap;
|
8216 | var ast = ref.ast;
|
8217 | var sourceMapChain = ref.sourceMapChain;
|
8218 | var resolvedIds = ref.resolvedIds;
|
8219 | var resolvedExternalIds = ref.resolvedExternalIds;
|
8220 | var bundle = ref.bundle;
|
8221 |
|
8222 | this.code = code;
|
8223 | this.id = id;
|
8224 | this.bundle = bundle;
|
8225 | this.originalCode = originalCode;
|
8226 | this.originalSourceMap = originalSourceMap;
|
8227 | this.sourceMapChain = sourceMapChain;
|
8228 |
|
8229 | this.comments = [];
|
8230 |
|
8231 | timeStart( 'ast' );
|
8232 |
|
8233 | if ( ast ) {
|
8234 |
|
8235 |
|
8236 | this.ast = clone( ast );
|
8237 | this.astClone = ast;
|
8238 | } else {
|
8239 | this.ast = tryParse( this, bundle.acornOptions );
|
8240 | this.astClone = clone( this.ast );
|
8241 | }
|
8242 |
|
8243 | timeEnd( 'ast' );
|
8244 |
|
8245 | this.excludeFromSourcemap = /\0/.test( id );
|
8246 | this.context = bundle.getModuleContext( id );
|
8247 |
|
8248 |
|
8249 | this.sources = [];
|
8250 | this.dependencies = [];
|
8251 | this.resolvedIds = resolvedIds || blank();
|
8252 | this.resolvedExternalIds = resolvedExternalIds || blank();
|
8253 |
|
8254 |
|
8255 | this.imports = blank();
|
8256 | this.exports = blank();
|
8257 | this.exportsAll = blank();
|
8258 | this.reexports = blank();
|
8259 |
|
8260 | this.exportAllSources = [];
|
8261 | this.exportAllModules = null;
|
8262 |
|
8263 |
|
8264 |
|
8265 | this.magicString = new MagicString$1( code, {
|
8266 | filename: this.excludeFromSourcemap ? null : id,
|
8267 | indentExclusionRanges: []
|
8268 | } );
|
8269 |
|
8270 |
|
8271 | this.comments = this.comments.filter( function (comment) {
|
8272 |
|
8273 | var isSourceMapComment = !comment.block && SOURCEMAPPING_URL_RE.test( comment.text );
|
8274 | if ( isSourceMapComment ) {
|
8275 | this$1.magicString.remove( comment.start, comment.end );
|
8276 | }
|
8277 | return !isSourceMapComment;
|
8278 | } );
|
8279 |
|
8280 | this.declarations = blank();
|
8281 | this.type = 'Module';
|
8282 | this.scope = new ModuleScope( this );
|
8283 |
|
8284 | timeStart( 'analyse' );
|
8285 |
|
8286 | this.analyse();
|
8287 |
|
8288 | timeEnd( 'analyse' );
|
8289 |
|
8290 | this.strongDependencies = [];
|
8291 | };
|
8292 |
|
8293 | Module.prototype.addExport = function addExport ( node ) {
|
8294 | var this$1 = this;
|
8295 |
|
8296 | var source = node.source && node.source.value;
|
8297 |
|
8298 |
|
8299 | if ( source ) {
|
8300 | if ( !~this.sources.indexOf( source ) ) { this.sources.push( source ); }
|
8301 |
|
8302 | if ( node.type === 'ExportAllDeclaration' ) {
|
8303 |
|
8304 |
|
8305 | this.exportAllSources.push( source );
|
8306 | }
|
8307 |
|
8308 | else {
|
8309 | node.specifiers.forEach( function (specifier) {
|
8310 | var name = specifier.exported.name;
|
8311 |
|
8312 | if ( this$1.exports[ name ] || this$1.reexports[ name ] ) {
|
8313 | this$1.error( {
|
8314 | code: 'DUPLICATE_EXPORT',
|
8315 | message: ("A module cannot have multiple exports with the same name ('" + name + "')")
|
8316 | }, specifier.start );
|
8317 | }
|
8318 |
|
8319 | this$1.reexports[ name ] = {
|
8320 | start: specifier.start,
|
8321 | source: source,
|
8322 | localName: specifier.local.name,
|
8323 | module: null
|
8324 | };
|
8325 | } );
|
8326 | }
|
8327 | }
|
8328 |
|
8329 |
|
8330 |
|
8331 |
|
8332 | else if ( node.type === 'ExportDefaultDeclaration' ) {
|
8333 | var identifier = ( node.declaration.id && node.declaration.id.name ) || node.declaration.name;
|
8334 |
|
8335 | if ( this.exports.default ) {
|
8336 | this.error( {
|
8337 | code: 'DUPLICATE_EXPORT',
|
8338 | message: "A module can only have one default export"
|
8339 | }, node.start );
|
8340 | }
|
8341 |
|
8342 | this.exports.default = {
|
8343 | localName: 'default',
|
8344 | identifier: identifier
|
8345 | };
|
8346 |
|
8347 |
|
8348 |
|
8349 | }
|
8350 |
|
8351 |
|
8352 |
|
8353 |
|
8354 |
|
8355 | else if ( node.declaration ) {
|
8356 | var declaration = node.declaration;
|
8357 |
|
8358 | if ( declaration.type === 'VariableDeclaration' ) {
|
8359 | declaration.declarations.forEach( function (decl) {
|
8360 | extractNames( decl.id ).forEach( function (localName) {
|
8361 | this$1.exports[ localName ] = { localName: localName };
|
8362 | } );
|
8363 | } );
|
8364 | } else {
|
8365 |
|
8366 | var localName = declaration.id.name;
|
8367 | this.exports[ localName ] = { localName: localName };
|
8368 | }
|
8369 | }
|
8370 |
|
8371 |
|
8372 | else {
|
8373 | node.specifiers.forEach( function (specifier) {
|
8374 | var localName = specifier.local.name;
|
8375 | var exportedName = specifier.exported.name;
|
8376 |
|
8377 | if ( this$1.exports[ exportedName ] || this$1.reexports[ exportedName ] ) {
|
8378 | this$1.error({
|
8379 | code: 'DUPLICATE_EXPORT',
|
8380 | message: ("A module cannot have multiple exports with the same name ('" + exportedName + "')")
|
8381 | }, specifier.start );
|
8382 | }
|
8383 |
|
8384 | this$1.exports[ exportedName ] = { localName: localName };
|
8385 | });
|
8386 | }
|
8387 | };
|
8388 |
|
8389 | Module.prototype.addImport = function addImport ( node ) {
|
8390 | var this$1 = this;
|
8391 |
|
8392 | var source = node.source.value;
|
8393 |
|
8394 | if ( !~this.sources.indexOf( source ) ) { this.sources.push( source ); }
|
8395 |
|
8396 | node.specifiers.forEach( function (specifier) {
|
8397 | var localName = specifier.local.name;
|
8398 |
|
8399 | if ( this$1.imports[ localName ] ) {
|
8400 | this$1.error( {
|
8401 | code: 'DUPLICATE_IMPORT',
|
8402 | message: ("Duplicated import '" + localName + "'")
|
8403 | }, specifier.start );
|
8404 | }
|
8405 |
|
8406 | var isDefault = specifier.type === 'ImportDefaultSpecifier';
|
8407 | var isNamespace = specifier.type === 'ImportNamespaceSpecifier';
|
8408 |
|
8409 | var name = isDefault ? 'default' : isNamespace ? '*' : specifier.imported.name;
|
8410 | this$1.imports[ localName ] = { source: source, specifier: specifier, name: name, module: null };
|
8411 | } );
|
8412 | };
|
8413 |
|
8414 | Module.prototype.analyse = function analyse () {
|
8415 | var this$1 = this;
|
8416 |
|
8417 | enhance( this.ast, this, this.comments );
|
8418 |
|
8419 |
|
8420 | var lastNode;
|
8421 |
|
8422 | for ( var node of this$1.ast.body ) {
|
8423 | if ( node.isImportDeclaration ) {
|
8424 | this$1.addImport( node );
|
8425 | } else if ( node.isExportDeclaration ) {
|
8426 | this$1.addExport( node );
|
8427 | }
|
8428 |
|
8429 | if ( lastNode ) { lastNode.next = node.leadingCommentStart || node.start; }
|
8430 | lastNode = node;
|
8431 | }
|
8432 | };
|
8433 |
|
8434 | Module.prototype.basename = function basename$1 () {
|
8435 | var base = basename( this.id );
|
8436 | var ext = extname( this.id );
|
8437 |
|
8438 | return makeLegal( ext ? base.slice( 0, -ext.length ) : base );
|
8439 | };
|
8440 |
|
8441 | Module.prototype.bindImportSpecifiers = function bindImportSpecifiers () {
|
8442 | var this$1 = this;
|
8443 |
|
8444 | [ this.imports, this.reexports ].forEach( function (specifiers) {
|
8445 | keys( specifiers ).forEach( function (name) {
|
8446 | var specifier = specifiers[ name ];
|
8447 |
|
8448 | var id = this$1.resolvedIds[ specifier.source ] || this$1.resolvedExternalIds[ specifier.source ];
|
8449 | specifier.module = this$1.bundle.moduleById.get( id );
|
8450 | } );
|
8451 | } );
|
8452 |
|
8453 | this.exportAllModules = this.exportAllSources.map( function (source) {
|
8454 | var id = this$1.resolvedIds[ source ] || this$1.resolvedExternalIds[ source ];
|
8455 | return this$1.bundle.moduleById.get( id );
|
8456 | } );
|
8457 |
|
8458 | this.sources.forEach( function (source) {
|
8459 | var id = this$1.resolvedIds[ source ];
|
8460 |
|
8461 | if ( id ) {
|
8462 | var module = this$1.bundle.moduleById.get( id );
|
8463 | this$1.dependencies.push( module );
|
8464 | }
|
8465 | } );
|
8466 | };
|
8467 |
|
8468 | Module.prototype.bindReferences = function bindReferences () {
|
8469 | var this$1 = this;
|
8470 |
|
8471 | for ( var node of this$1.ast.body ) {
|
8472 | node.bind();
|
8473 | }
|
8474 |
|
8475 |
|
8476 |
|
8477 |
|
8478 |
|
8479 |
|
8480 |
|
8481 | };
|
8482 |
|
8483 | Module.prototype.error = function error$1 ( props, pos ) {
|
8484 | if ( pos !== undefined ) {
|
8485 | props.pos = pos;
|
8486 |
|
8487 | var ref = locate( this.code, pos, { offsetLine: 1 } );
|
8488 | var line = ref.line;
|
8489 | var column = ref.column;
|
8490 |
|
8491 | props.loc = { file: this.id, line: line, column: column };
|
8492 | props.frame = getCodeFrame( this.code, line, column );
|
8493 | }
|
8494 |
|
8495 | error( props );
|
8496 | };
|
8497 |
|
8498 | Module.prototype.findParent = function findParent () {
|
8499 |
|
8500 | return null;
|
8501 | };
|
8502 |
|
8503 | Module.prototype.getExports = function getExports () {
|
8504 | return keys( this.exports );
|
8505 | };
|
8506 |
|
8507 | Module.prototype.getReexports = function getReexports () {
|
8508 | var reexports = blank();
|
8509 |
|
8510 | keys( this.reexports ).forEach( function (name) {
|
8511 | reexports[ name ] = true;
|
8512 | } );
|
8513 |
|
8514 | this.exportAllModules.forEach( function (module) {
|
8515 | if ( module.isExternal ) {
|
8516 | reexports[ ("*" + (module.id)) ] = true;
|
8517 | return;
|
8518 | }
|
8519 |
|
8520 | module.getExports().concat( module.getReexports() ).forEach( function (name) {
|
8521 | if ( name !== 'default' ) { reexports[ name ] = true; }
|
8522 | } );
|
8523 | } );
|
8524 |
|
8525 | return keys( reexports );
|
8526 | };
|
8527 |
|
8528 | Module.prototype.namespace = function namespace () {
|
8529 | if ( !this.declarations[ '*' ] ) {
|
8530 | this.declarations[ '*' ] = new SyntheticNamespaceDeclaration( this );
|
8531 | }
|
8532 |
|
8533 | return this.declarations[ '*' ];
|
8534 | };
|
8535 |
|
8536 | Module.prototype.render = function render ( es, legacy ) {
|
8537 | var this$1 = this;
|
8538 |
|
8539 | var magicString = this.magicString.clone();
|
8540 |
|
8541 | for ( var node of this$1.ast.body ) {
|
8542 | node.render( magicString, es );
|
8543 | }
|
8544 |
|
8545 | if ( this.namespace().needsNamespaceBlock ) {
|
8546 | magicString.append( '\n\n' + this.namespace().renderBlock( es, legacy, '\t' ) );
|
8547 | }
|
8548 |
|
8549 | return magicString.trim();
|
8550 | };
|
8551 |
|
8552 | Module.prototype.run = function run () {
|
8553 | var this$1 = this;
|
8554 |
|
8555 | for ( var node of this$1.ast.body ) {
|
8556 | if ( node.hasEffects() ) {
|
8557 | node.run();
|
8558 | }
|
8559 | }
|
8560 | };
|
8561 |
|
8562 | Module.prototype.toJSON = function toJSON () {
|
8563 | return {
|
8564 | id: this.id,
|
8565 | dependencies: this.dependencies.map( function (module) { return module.id; } ),
|
8566 | code: this.code,
|
8567 | originalCode: this.originalCode,
|
8568 | originalSourceMap: this.originalSourceMap,
|
8569 | ast: this.astClone,
|
8570 | sourceMapChain: this.sourceMapChain,
|
8571 | resolvedIds: this.resolvedIds,
|
8572 | resolvedExternalIds: this.resolvedExternalIds
|
8573 | };
|
8574 | };
|
8575 |
|
8576 | Module.prototype.trace = function trace ( name ) {
|
8577 |
|
8578 | if ( name in this.scope.declarations ) {
|
8579 | return this.scope.declarations[ name ];
|
8580 | }
|
8581 |
|
8582 | if ( name in this.imports ) {
|
8583 | var importDeclaration = this.imports[ name ];
|
8584 | var otherModule = importDeclaration.module;
|
8585 |
|
8586 | if ( importDeclaration.name === '*' && !otherModule.isExternal ) {
|
8587 | return otherModule.namespace();
|
8588 | }
|
8589 |
|
8590 | var declaration = otherModule.traceExport( importDeclaration.name );
|
8591 |
|
8592 | if ( !declaration ) {
|
8593 | this.error( {
|
8594 | code: 'MISSING_EXPORT',
|
8595 | message: ("'" + (importDeclaration.name) + "' is not exported by " + (relativeId( otherModule.id ))),
|
8596 | url: "https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module"
|
8597 | }, importDeclaration.specifier.start );
|
8598 | }
|
8599 |
|
8600 | return declaration;
|
8601 | }
|
8602 |
|
8603 | return null;
|
8604 | };
|
8605 |
|
8606 | Module.prototype.traceExport = function traceExport ( name ) {
|
8607 | var this$1 = this;
|
8608 |
|
8609 |
|
8610 | if ( name[ 0 ] === '*' ) {
|
8611 | var module = this.bundle.moduleById.get( name.slice( 1 ) );
|
8612 | return module.traceExport( '*' );
|
8613 | }
|
8614 |
|
8615 |
|
8616 | var reexportDeclaration = this.reexports[ name ];
|
8617 | if ( reexportDeclaration ) {
|
8618 | var declaration = reexportDeclaration.module.traceExport( reexportDeclaration.localName );
|
8619 |
|
8620 | if ( !declaration ) {
|
8621 | this.error( {
|
8622 | code: 'MISSING_EXPORT',
|
8623 | message: ("'" + (reexportDeclaration.localName) + "' is not exported by " + (relativeId( reexportDeclaration.module.id ))),
|
8624 | url: "https://github.com/rollup/rollup/wiki/Troubleshooting#name-is-not-exported-by-module"
|
8625 | }, reexportDeclaration.start );
|
8626 | }
|
8627 |
|
8628 | return declaration;
|
8629 | }
|
8630 |
|
8631 | var exportDeclaration = this.exports[ name ];
|
8632 | if ( exportDeclaration ) {
|
8633 | var name$1 = exportDeclaration.localName;
|
8634 | var declaration$1 = this.trace( name$1 );
|
8635 |
|
8636 | return declaration$1 || this.bundle.scope.findDeclaration( name$1 );
|
8637 | }
|
8638 |
|
8639 | if ( name === 'default' ) { return; }
|
8640 |
|
8641 | for ( var i = 0; i < this.exportAllModules.length; i += 1 ) {
|
8642 | var module$1 = this$1.exportAllModules[ i ];
|
8643 | var declaration$2 = module$1.traceExport( name );
|
8644 |
|
8645 | if ( declaration$2 ) { return declaration$2; }
|
8646 | }
|
8647 | };
|
8648 |
|
8649 | Module.prototype.warn = function warn ( warning, pos ) {
|
8650 | if ( pos !== undefined ) {
|
8651 | warning.pos = pos;
|
8652 |
|
8653 | var ref = locate( this.code, pos, { offsetLine: 1 } );
|
8654 | var line = ref.line;
|
8655 | var column = ref.column;
|
8656 |
|
8657 | warning.loc = { file: this.id, line: line, column: column };
|
8658 | warning.frame = getCodeFrame( this.code, line, column );
|
8659 | }
|
8660 |
|
8661 | warning.id = this.id;
|
8662 | this.bundle.warn( warning );
|
8663 | };
|
8664 |
|
8665 | var ExternalModule = function ExternalModule ( id, relativePath ) {
|
8666 | this.id = id;
|
8667 | this.path = relativePath;
|
8668 |
|
8669 | this.name = makeLegal( relativePath );
|
8670 |
|
8671 | this.nameSuggestions = blank();
|
8672 | this.mostCommonSuggestion = 0;
|
8673 |
|
8674 | this.isExternal = true;
|
8675 | this.used = false;
|
8676 | this.declarations = blank();
|
8677 |
|
8678 | this.exportsNames = false;
|
8679 | };
|
8680 |
|
8681 | ExternalModule.prototype.suggestName = function suggestName ( name ) {
|
8682 | if ( !this.nameSuggestions[ name ] ) { this.nameSuggestions[ name ] = 0; }
|
8683 | this.nameSuggestions[ name ] += 1;
|
8684 |
|
8685 | if ( this.nameSuggestions[ name ] > this.mostCommonSuggestion ) {
|
8686 | this.mostCommonSuggestion = this.nameSuggestions[ name ];
|
8687 | this.name = name;
|
8688 | }
|
8689 | };
|
8690 |
|
8691 | ExternalModule.prototype.traceExport = function traceExport ( name ) {
|
8692 | if ( name !== 'default' && name !== '*' ) { this.exportsNames = true; }
|
8693 | if ( name === '*' ) { this.exportsNamespace = true; }
|
8694 |
|
8695 | return this.declarations[ name ] || (
|
8696 | this.declarations[ name ] = new ExternalDeclaration( this, name )
|
8697 | );
|
8698 | };
|
8699 |
|
8700 | function getName ( x ) {
|
8701 | return x.name;
|
8702 | }
|
8703 |
|
8704 | function quotePath ( x ) {
|
8705 | return ("'" + (x.path) + "'");
|
8706 | }
|
8707 |
|
8708 | function req ( x ) {
|
8709 | return ("require('" + (x.path) + "')");
|
8710 | }
|
8711 |
|
8712 | function getInteropBlock ( bundle, options ) {
|
8713 | return bundle.externalModules
|
8714 | .map( function (module) {
|
8715 | if ( !module.declarations.default || options.interop === false ) { return null; }
|
8716 |
|
8717 | if ( module.exportsNamespace ) {
|
8718 | return ((bundle.varOrConst) + " " + (module.name) + "__default = " + (module.name) + "['default'];");
|
8719 | }
|
8720 |
|
8721 | if ( module.exportsNames ) {
|
8722 | return ((bundle.varOrConst) + " " + (module.name) + "__default = 'default' in " + (module.name) + " ? " + (module.name) + "['default'] : " + (module.name) + ";");
|
8723 | }
|
8724 |
|
8725 | return ((module.name) + " = " + (module.name) + " && " + (module.name) + ".hasOwnProperty('default') ? " + (module.name) + "['default'] : " + (module.name) + ";");
|
8726 | })
|
8727 | .filter( Boolean )
|
8728 | .join( '\n' );
|
8729 | }
|
8730 |
|
8731 | function getExportBlock ( bundle, exportMode, mechanism ) {
|
8732 | if ( mechanism === void 0 ) mechanism = 'return';
|
8733 |
|
8734 | var entryModule = bundle.entryModule;
|
8735 |
|
8736 | if ( exportMode === 'default' ) {
|
8737 | return (mechanism + " " + (entryModule.traceExport( 'default' ).getName( false )) + ";");
|
8738 | }
|
8739 |
|
8740 | var exports = entryModule.getExports().concat( entryModule.getReexports() )
|
8741 | .map( function (name) {
|
8742 | if ( name[0] === '*' ) {
|
8743 |
|
8744 | var id = name.slice( 1 );
|
8745 | var module = bundle.moduleById.get( id );
|
8746 |
|
8747 | return ("Object.keys(" + (module.name) + ").forEach(function (key) { exports[key] = " + (module.name) + "[key]; });");
|
8748 | }
|
8749 |
|
8750 | var prop = name === 'default' ? "['default']" : ("." + name);
|
8751 | var declaration = entryModule.traceExport( name );
|
8752 |
|
8753 | var lhs = "exports" + prop;
|
8754 | var rhs = declaration ?
|
8755 | declaration.getName( false ) :
|
8756 | name;
|
8757 |
|
8758 |
|
8759 | if ( lhs === rhs ) { return null; }
|
8760 |
|
8761 | return (lhs + " = " + rhs + ";");
|
8762 | });
|
8763 |
|
8764 | return exports
|
8765 | .filter( Boolean )
|
8766 | .join( '\n' );
|
8767 | }
|
8768 |
|
8769 | var esModuleExport = "Object.defineProperty(exports, '__esModule', { value: true });";
|
8770 |
|
8771 | var builtins$1 = {
|
8772 | process: true,
|
8773 | events: true,
|
8774 | stream: true,
|
8775 | util: true,
|
8776 | path: true,
|
8777 | buffer: true,
|
8778 | querystring: true,
|
8779 | url: true,
|
8780 | string_decoder: true,
|
8781 | punycode: true,
|
8782 | http: true,
|
8783 | https: true,
|
8784 | os: true,
|
8785 | assert: true,
|
8786 | constants: true,
|
8787 | timers: true,
|
8788 | console: true,
|
8789 | vm: true,
|
8790 | zlib: true,
|
8791 | tty: true,
|
8792 | domain: true
|
8793 | };
|
8794 |
|
8795 |
|
8796 |
|
8797 | function warnOnBuiltins ( bundle ) {
|
8798 | var externalBuiltins = bundle.externalModules
|
8799 | .filter( function (mod) { return mod.id in builtins$1; } )
|
8800 | .map( function (mod) { return mod.id; } );
|
8801 |
|
8802 | if ( !externalBuiltins.length ) { return; }
|
8803 |
|
8804 | var detail = externalBuiltins.length === 1 ?
|
8805 | ("module ('" + (externalBuiltins[0]) + "')") :
|
8806 | ("modules (" + (externalBuiltins.slice( 0, -1 ).map( function (name) { return ("'" + name + "'"); } ).join( ', ' )) + " and '" + (externalBuiltins.slice( -1 )) + "')");
|
8807 |
|
8808 | bundle.warn({
|
8809 | code: 'MISSING_NODE_BUILTINS',
|
8810 | modules: externalBuiltins,
|
8811 | message: ("Creating a browser bundle that depends on Node.js built-in " + detail + ". You might need to include https://www.npmjs.com/package/rollup-plugin-node-builtins")
|
8812 | });
|
8813 | }
|
8814 |
|
8815 | function amd ( bundle, magicString, ref, options ) {
|
8816 | var exportMode = ref.exportMode;
|
8817 | var indentString = ref.indentString;
|
8818 | var intro = ref.intro;
|
8819 | var outro = ref.outro;
|
8820 |
|
8821 | warnOnBuiltins( bundle );
|
8822 | var deps = bundle.externalModules.map( quotePath );
|
8823 | var args = bundle.externalModules.map( getName );
|
8824 |
|
8825 | if ( exportMode === 'named' ) {
|
8826 | args.unshift( "exports" );
|
8827 | deps.unshift( "'exports'" );
|
8828 | }
|
8829 |
|
8830 | var amdOptions = options.amd || {};
|
8831 |
|
8832 | var params =
|
8833 | ( amdOptions.id ? ("'" + (amdOptions.id) + "', ") : "" ) +
|
8834 | ( deps.length ? ("[" + (deps.join( ', ' )) + "], ") : "" );
|
8835 |
|
8836 | var useStrict = options.useStrict !== false ? " 'use strict';" : "";
|
8837 | var define = amdOptions.define || 'define';
|
8838 | var wrapperStart = define + "(" + params + "function (" + (args.join( ', ' )) + ") {" + useStrict + "\n\n";
|
8839 |
|
8840 |
|
8841 | var interopBlock = getInteropBlock( bundle, options );
|
8842 | if ( interopBlock ) { magicString.prepend( interopBlock + '\n\n' ); }
|
8843 |
|
8844 | if ( intro ) { magicString.prepend( intro ); }
|
8845 |
|
8846 | var exportBlock = getExportBlock( bundle, exportMode );
|
8847 | if ( exportBlock ) { magicString.append( '\n\n' + exportBlock ); }
|
8848 | if ( exportMode === 'named' && options.legacy !== true ) { magicString.append( ("\n\n" + esModuleExport) ); }
|
8849 | if ( outro ) { magicString.append( outro ); }
|
8850 |
|
8851 | return magicString
|
8852 | .indent( indentString )
|
8853 | .append( '\n\n});' )
|
8854 | .prepend( wrapperStart );
|
8855 | }
|
8856 |
|
8857 | function cjs ( bundle, magicString, ref, options ) {
|
8858 | var exportMode = ref.exportMode;
|
8859 | var intro = ref.intro;
|
8860 | var outro = ref.outro;
|
8861 |
|
8862 | intro = ( options.useStrict === false ? intro : ("'use strict';\n\n" + intro) ) +
|
8863 | ( exportMode === 'named' && options.legacy !== true ? (esModuleExport + "\n\n") : '' );
|
8864 |
|
8865 | var needsInterop = false;
|
8866 |
|
8867 | var varOrConst = bundle.varOrConst;
|
8868 | var interop = options.interop !== false;
|
8869 |
|
8870 |
|
8871 | var importBlock = bundle.externalModules
|
8872 | .map( function (module) {
|
8873 | if ( interop && module.declarations.default ) {
|
8874 | if ( module.exportsNamespace ) {
|
8875 | return varOrConst + " " + (module.name) + " = require('" + (module.path) + "');" +
|
8876 | "\n" + varOrConst + " " + (module.name) + "__default = " + (module.name) + "['default'];";
|
8877 | }
|
8878 |
|
8879 | needsInterop = true;
|
8880 |
|
8881 | if ( module.exportsNames ) {
|
8882 | return varOrConst + " " + (module.name) + " = require('" + (module.path) + "');" +
|
8883 | "\n" + varOrConst + " " + (module.name) + "__default = _interopDefault(" + (module.name) + ");";
|
8884 | }
|
8885 |
|
8886 | return (varOrConst + " " + (module.name) + " = _interopDefault(require('" + (module.path) + "'));");
|
8887 | } else {
|
8888 | var activated = Object.keys( module.declarations )
|
8889 | .filter( function (name) { return module.declarations[ name ].activated; } );
|
8890 |
|
8891 | var needsVar = activated.length || module.reexported;
|
8892 |
|
8893 | return needsVar ?
|
8894 | (varOrConst + " " + (module.name) + " = require('" + (module.path) + "');") :
|
8895 | ("require('" + (module.path) + "');");
|
8896 | }
|
8897 | })
|
8898 | .join( '\n' );
|
8899 |
|
8900 | if ( needsInterop ) {
|
8901 | intro += "function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }\n\n";
|
8902 | }
|
8903 |
|
8904 | if ( importBlock ) {
|
8905 | intro += importBlock + '\n\n';
|
8906 | }
|
8907 |
|
8908 | magicString.prepend( intro );
|
8909 |
|
8910 | var exportBlock = getExportBlock( bundle, exportMode, 'module.exports =' );
|
8911 | if ( exportBlock ) { magicString.append( '\n\n' + exportBlock ); }
|
8912 | if ( outro ) { magicString.append( outro ); }
|
8913 |
|
8914 | return magicString;
|
8915 | }
|
8916 |
|
8917 | function notDefault ( name ) {
|
8918 | return name !== 'default';
|
8919 | }
|
8920 |
|
8921 | function es ( bundle, magicString, ref ) {
|
8922 | var intro = ref.intro;
|
8923 | var outro = ref.outro;
|
8924 |
|
8925 | var importBlock = bundle.externalModules
|
8926 | .map( function (module) {
|
8927 | var specifiers = [];
|
8928 | var specifiersList = [specifiers];
|
8929 | var importedNames = keys( module.declarations )
|
8930 | .filter( function (name) { return name !== '*' && name !== 'default'; } )
|
8931 | .filter( function (name) { return module.declarations[ name ].activated; } )
|
8932 | .map( function (name) {
|
8933 | if ( name[0] === '*' ) {
|
8934 | return ("* as " + (module.name));
|
8935 | }
|
8936 |
|
8937 | var declaration = module.declarations[ name ];
|
8938 |
|
8939 | if ( declaration.name === declaration.safeName ) { return declaration.name; }
|
8940 | return ((declaration.name) + " as " + (declaration.safeName));
|
8941 | })
|
8942 | .filter( Boolean );
|
8943 |
|
8944 | if ( module.declarations.default ) {
|
8945 | if ( module.exportsNamespace ) {
|
8946 | specifiersList.push([ ((module.name) + "__default") ]);
|
8947 | } else {
|
8948 | specifiers.push( module.name );
|
8949 | }
|
8950 | }
|
8951 |
|
8952 | var namespaceSpecifier = module.declarations['*'] && module.declarations['*'].activated ? ("* as " + (module.name)) : null;
|
8953 | var namedSpecifier = importedNames.length ? ("{ " + (importedNames.sort().join( ', ' )) + " }") : null;
|
8954 |
|
8955 | if ( namespaceSpecifier && namedSpecifier ) {
|
8956 |
|
8957 | specifiersList.push( [namespaceSpecifier] );
|
8958 | specifiers.push( namedSpecifier );
|
8959 | } else if ( namedSpecifier ) {
|
8960 | specifiers.push( namedSpecifier );
|
8961 | } else if ( namespaceSpecifier ) {
|
8962 | specifiers.push( namespaceSpecifier );
|
8963 | }
|
8964 |
|
8965 | return specifiersList
|
8966 | .map( function (specifiers) {
|
8967 | if ( specifiers.length ) {
|
8968 | return ("import " + (specifiers.join( ', ' )) + " from '" + (module.path) + "';");
|
8969 | }
|
8970 |
|
8971 | return module.reexported ?
|
8972 | null :
|
8973 | ("import '" + (module.path) + "';");
|
8974 | })
|
8975 | .filter( Boolean )
|
8976 | .join( '\n' );
|
8977 | })
|
8978 | .join( '\n' );
|
8979 |
|
8980 | if ( importBlock ) { intro += importBlock + '\n\n'; }
|
8981 | if ( intro ) { magicString.prepend( intro ); }
|
8982 |
|
8983 | var module = bundle.entryModule;
|
8984 |
|
8985 | var exportInternalSpecifiers = [];
|
8986 | var exportExternalSpecifiers = new Map();
|
8987 | var exportAllDeclarations = [];
|
8988 |
|
8989 | module.getExports()
|
8990 | .filter( notDefault )
|
8991 | .forEach( function (name) {
|
8992 | var declaration = module.traceExport( name );
|
8993 | var rendered = declaration.getName( true );
|
8994 | exportInternalSpecifiers.push( rendered === name ? name : (rendered + " as " + name) );
|
8995 | });
|
8996 |
|
8997 | module.getReexports()
|
8998 | .filter( notDefault )
|
8999 | .forEach( function (name) {
|
9000 | var declaration = module.traceExport( name );
|
9001 |
|
9002 | if ( declaration.isExternal ) {
|
9003 | if ( name[0] === '*' ) {
|
9004 |
|
9005 | exportAllDeclarations.push( ("export * from '" + (name.slice( 1 )) + "';") );
|
9006 | } else {
|
9007 | if ( !exportExternalSpecifiers.has( declaration.module.id ) ) { exportExternalSpecifiers.set( declaration.module.id, [] ); }
|
9008 | exportExternalSpecifiers.get( declaration.module.id ).push( name );
|
9009 | }
|
9010 |
|
9011 | return;
|
9012 | }
|
9013 |
|
9014 | var rendered = declaration.getName( true );
|
9015 | exportInternalSpecifiers.push( rendered === name ? name : (rendered + " as " + name) );
|
9016 | });
|
9017 |
|
9018 | var exportBlock = [];
|
9019 | if ( exportInternalSpecifiers.length ) { exportBlock.push( ("export { " + (exportInternalSpecifiers.join(', ')) + " };") ); }
|
9020 | if ( module.exports.default || module.reexports.default ) { exportBlock.push( ("export default " + (module.traceExport( 'default' ).getName( true )) + ";") ); }
|
9021 | if ( exportAllDeclarations.length ) { exportBlock.push( exportAllDeclarations.join( '\n' ) ); }
|
9022 | if ( exportExternalSpecifiers.size ) {
|
9023 | exportExternalSpecifiers.forEach( function ( specifiers, id ) {
|
9024 | exportBlock.push( ("export { " + (specifiers.join( ', ' )) + " } from '" + id + "';") );
|
9025 | });
|
9026 | }
|
9027 |
|
9028 | if ( exportBlock.length ) { magicString.append( '\n\n' + exportBlock.join( '\n' ).trim() ); }
|
9029 |
|
9030 | if ( outro ) { magicString.append( outro ); }
|
9031 |
|
9032 | return magicString.trim();
|
9033 | }
|
9034 |
|
9035 | function getGlobalNameMaker ( globals, bundle, fallback ) {
|
9036 | if ( fallback === void 0 ) fallback = null;
|
9037 |
|
9038 | var fn = typeof globals === 'function' ? globals : function (id) { return globals[ id ]; };
|
9039 |
|
9040 | return function ( module ) {
|
9041 | var name = fn( module.id );
|
9042 | if ( name ) { return name; }
|
9043 |
|
9044 | if ( Object.keys( module.declarations ).length > 0 ) {
|
9045 | bundle.warn({
|
9046 | code: 'MISSING_GLOBAL_NAME',
|
9047 | source: module.id,
|
9048 | guess: module.name,
|
9049 | message: ("No name was provided for external module '" + (module.id) + "' in options.globals – guessing '" + (module.name) + "'")
|
9050 | });
|
9051 |
|
9052 | return module.name;
|
9053 | }
|
9054 |
|
9055 | return fallback;
|
9056 | };
|
9057 | }
|
9058 |
|
9059 |
|
9060 |
|
9061 | var shouldUseDot = /^[a-zA-Z$_][a-zA-Z0-9$_]*$/;
|
9062 |
|
9063 | function property ( prop ) {
|
9064 | return shouldUseDot.test( prop ) ? ("." + prop) : ("['" + prop + "']");
|
9065 | }
|
9066 |
|
9067 | function keypath ( keypath ) {
|
9068 | return keypath.split( '.' ).map( property ).join( '' );
|
9069 | }
|
9070 |
|
9071 | function trimEmptyImports ( modules ) {
|
9072 | var i = modules.length;
|
9073 |
|
9074 | while ( i-- ) {
|
9075 | var module = modules[i];
|
9076 | if ( Object.keys( module.declarations ).length > 0 ) {
|
9077 | return modules.slice( 0, i + 1 );
|
9078 | }
|
9079 | }
|
9080 |
|
9081 | return [];
|
9082 | }
|
9083 |
|
9084 | function setupNamespace ( keypath$$1 ) {
|
9085 | var parts = keypath$$1.split( '.' );
|
9086 |
|
9087 | parts.pop();
|
9088 |
|
9089 | var acc = 'this';
|
9090 |
|
9091 | return parts
|
9092 | .map( function (part) { return ( acc += property( part ), (acc + " = " + acc + " || {};") ); } )
|
9093 | .join( '\n' ) + '\n';
|
9094 | }
|
9095 |
|
9096 | var thisProp = function (name) { return ("this" + (keypath( name ))); };
|
9097 |
|
9098 | function iife ( bundle, magicString, ref, options ) {
|
9099 | var exportMode = ref.exportMode;
|
9100 | var indentString = ref.indentString;
|
9101 | var intro = ref.intro;
|
9102 | var outro = ref.outro;
|
9103 |
|
9104 | var globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle, 'null' );
|
9105 |
|
9106 | var extend = options.extend;
|
9107 | var name = options.moduleName;
|
9108 | var isNamespaced = name && name.indexOf( '.' ) !== -1;
|
9109 | var possibleVariableAssignment = !extend && !isNamespaced;
|
9110 |
|
9111 | if ( name && possibleVariableAssignment && !isLegal(name) ) {
|
9112 | error({
|
9113 | code: 'ILLEGAL_IDENTIFIER_AS_NAME',
|
9114 | message: ("Given moduleName (" + name + ") is not legal JS identifier. If you need this you can try --extend option")
|
9115 | });
|
9116 | }
|
9117 |
|
9118 | warnOnBuiltins( bundle );
|
9119 |
|
9120 | var external = trimEmptyImports( bundle.externalModules );
|
9121 | var dependencies = external.map( globalNameMaker );
|
9122 | var args = external.map( getName );
|
9123 |
|
9124 | if ( exportMode !== 'none' && !name ) {
|
9125 | error({
|
9126 | code: 'INVALID_OPTION',
|
9127 | message: "You must supply options.moduleName for IIFE bundles"
|
9128 | });
|
9129 | }
|
9130 |
|
9131 | if ( extend ) {
|
9132 | dependencies.unshift( ("(" + (thisProp(name)) + " = " + (thisProp(name)) + " || {})") );
|
9133 | args.unshift( 'exports' );
|
9134 | } else if ( exportMode === 'named' ) {
|
9135 | dependencies.unshift( '{}' );
|
9136 | args.unshift( 'exports' );
|
9137 | }
|
9138 |
|
9139 | var useStrict = options.useStrict !== false ? (indentString + "'use strict';\n\n") : "";
|
9140 |
|
9141 | var wrapperIntro = "(function (" + args + ") {\n" + useStrict;
|
9142 |
|
9143 | if ( exportMode !== 'none' && !extend) {
|
9144 | wrapperIntro = ( isNamespaced ? thisProp(name) : ((bundle.varOrConst) + " " + name) ) + " = " + wrapperIntro;
|
9145 | }
|
9146 |
|
9147 | if ( isNamespaced ) {
|
9148 | wrapperIntro = setupNamespace( name ) + wrapperIntro;
|
9149 | }
|
9150 |
|
9151 | var wrapperOutro = "\n\n}(" + dependencies + "));";
|
9152 |
|
9153 | if (!extend && exportMode === 'named') {
|
9154 | wrapperOutro = "\n\n" + indentString + "return exports;" + wrapperOutro;
|
9155 | }
|
9156 |
|
9157 |
|
9158 | var interopBlock = getInteropBlock( bundle, options );
|
9159 | if ( interopBlock ) { magicString.prepend( interopBlock + '\n\n' ); }
|
9160 |
|
9161 | if ( intro ) { magicString.prepend( intro ); }
|
9162 |
|
9163 | var exportBlock = getExportBlock( bundle, exportMode );
|
9164 | if ( exportBlock ) { magicString.append( '\n\n' + exportBlock ); }
|
9165 | if ( outro ) { magicString.append( outro ); }
|
9166 |
|
9167 | return magicString
|
9168 | .indent( indentString )
|
9169 | .prepend( wrapperIntro )
|
9170 | .append( wrapperOutro );
|
9171 | }
|
9172 |
|
9173 | function globalProp ( name ) {
|
9174 | if ( !name ) { return 'null'; }
|
9175 | return ("global" + (keypath( name )));
|
9176 | }
|
9177 |
|
9178 | function setupNamespace$1 ( name ) {
|
9179 | var parts = name.split( '.' );
|
9180 | var last = property( parts.pop() );
|
9181 |
|
9182 | var acc = 'global';
|
9183 | return parts
|
9184 | .map( function (part) { return ( acc += property( part ), (acc + " = " + acc + " || {}") ); } )
|
9185 | .concat( ("" + acc + last) )
|
9186 | .join( ', ' );
|
9187 | }
|
9188 |
|
9189 | function safeAccess ( name ) {
|
9190 | var parts = name.split( '.' );
|
9191 |
|
9192 | var acc = 'global';
|
9193 | return parts
|
9194 | .map( function (part) { return ( acc += property( part ), acc ); } )
|
9195 | .join( " && " );
|
9196 | }
|
9197 |
|
9198 | var wrapperOutro = '\n\n})));';
|
9199 |
|
9200 | function umd ( bundle, magicString, ref, options ) {
|
9201 | var exportMode = ref.exportMode;
|
9202 | var indentString = ref.indentString;
|
9203 | var intro = ref.intro;
|
9204 | var outro = ref.outro;
|
9205 |
|
9206 | if ( exportMode !== 'none' && !options.moduleName ) {
|
9207 | error({
|
9208 | code: 'INVALID_OPTION',
|
9209 | message: 'You must supply options.moduleName for UMD bundles'
|
9210 | });
|
9211 | }
|
9212 |
|
9213 | warnOnBuiltins( bundle );
|
9214 |
|
9215 | var globalNameMaker = getGlobalNameMaker( options.globals || blank(), bundle );
|
9216 |
|
9217 | var amdDeps = bundle.externalModules.map( quotePath );
|
9218 | var cjsDeps = bundle.externalModules.map( req );
|
9219 |
|
9220 | var trimmed = trimEmptyImports( bundle.externalModules );
|
9221 | var globalDeps = trimmed.map( function (module) { return globalProp( globalNameMaker( module ) ); } );
|
9222 | var args = trimmed.map( getName );
|
9223 |
|
9224 | if ( exportMode === 'named' ) {
|
9225 | amdDeps.unshift( "'exports'" );
|
9226 | cjsDeps.unshift( "exports" );
|
9227 | globalDeps.unshift( ("(" + (setupNamespace$1(options.moduleName)) + " = " + (options.extend ? ((globalProp(options.moduleName)) + " || ") : '') + "{})") );
|
9228 |
|
9229 | args.unshift( 'exports' );
|
9230 | }
|
9231 |
|
9232 | var amdOptions = options.amd || {};
|
9233 |
|
9234 | var amdParams =
|
9235 | ( amdOptions.id ? ("'" + (amdOptions.id) + "', ") : "" ) +
|
9236 | ( amdDeps.length ? ("[" + (amdDeps.join( ', ' )) + "], ") : "" );
|
9237 |
|
9238 | var define = amdOptions.define || 'define';
|
9239 |
|
9240 | var cjsExport = exportMode === 'default' ? "module.exports = " : "";
|
9241 | var defaultExport = exportMode === 'default' ? ((setupNamespace$1(options.moduleName)) + " = ") : '';
|
9242 |
|
9243 | var useStrict = options.useStrict !== false ? " 'use strict';" : "";
|
9244 |
|
9245 | var globalExport;
|
9246 |
|
9247 | if (options.noConflict === true) {
|
9248 | var factory;
|
9249 |
|
9250 | if ( exportMode === 'default' ) {
|
9251 | factory = "var exports = factory(" + globalDeps + ");";
|
9252 | } else if ( exportMode === 'named' ) {
|
9253 | var module = globalDeps.shift();
|
9254 | factory = "var exports = " + module + ";\n\t\t\t\tfactory(" + (['exports'].concat(globalDeps)) + ");";
|
9255 | }
|
9256 | globalExport = "(function() {\n\t\t\t\tvar current = " + (safeAccess(options.moduleName)) + ";\n\t\t\t\t" + factory + "\n\t\t\t\t" + (globalProp(options.moduleName)) + " = exports;\n\t\t\t\texports.noConflict = function() { " + (globalProp(options.moduleName)) + " = current; return exports; };\n\t\t\t})()";
|
9257 | } else {
|
9258 | globalExport = "(" + defaultExport + "factory(" + globalDeps + "))";
|
9259 | }
|
9260 |
|
9261 | var wrapperIntro =
|
9262 | ("(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, indentString || '\t' );
|
9263 |
|
9264 |
|
9265 | var interopBlock = getInteropBlock( bundle, options );
|
9266 | if ( interopBlock ) { magicString.prepend( interopBlock + '\n\n' ); }
|
9267 |
|
9268 | if ( intro ) { magicString.prepend( intro ); }
|
9269 |
|
9270 | var exportBlock = getExportBlock( bundle, exportMode );
|
9271 | if ( exportBlock ) { magicString.append( '\n\n' + exportBlock ); }
|
9272 | if ( exportMode === 'named' && options.legacy !== true ) { magicString.append( ("\n\n" + esModuleExport) ); }
|
9273 | if ( outro ) { magicString.append( outro ); }
|
9274 |
|
9275 | return magicString
|
9276 | .trim()
|
9277 | .indent( indentString )
|
9278 | .append( wrapperOutro )
|
9279 | .prepend( wrapperIntro );
|
9280 | }
|
9281 |
|
9282 | var finalisers = { amd: amd, cjs: cjs, es: es, iife: iife, umd: umd };
|
9283 |
|
9284 | function ensureArray ( thing ) {
|
9285 | if ( Array.isArray( thing ) ) { return thing; }
|
9286 | if ( thing == undefined ) { return []; }
|
9287 | return [ thing ];
|
9288 | }
|
9289 |
|
9290 | function load ( id ) {
|
9291 | return readFileSync( id, 'utf-8' );
|
9292 | }
|
9293 |
|
9294 | function findFile ( file ) {
|
9295 | try {
|
9296 | var stats = lstatSync( file );
|
9297 | if ( stats.isSymbolicLink() ) { return findFile( realpathSync( file ) ); }
|
9298 | if ( stats.isFile() ) {
|
9299 |
|
9300 | var name = basename( file );
|
9301 | var files = readdirSync( dirname( file ) );
|
9302 |
|
9303 | if ( ~files.indexOf( name ) ) { return file; }
|
9304 | }
|
9305 | } catch ( err ) {
|
9306 |
|
9307 | }
|
9308 | }
|
9309 |
|
9310 | function addJsExtensionIfNecessary ( file ) {
|
9311 | return findFile( file ) || findFile( file + '.js' );
|
9312 | }
|
9313 |
|
9314 | function resolveId ( importee, importer ) {
|
9315 | if ( typeof process === 'undefined' ) {
|
9316 | error({
|
9317 | code: 'MISSING_PROCESS',
|
9318 | message: "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",
|
9319 | url: 'https://github.com/rollup/rollup/wiki/Plugins'
|
9320 | });
|
9321 | }
|
9322 |
|
9323 |
|
9324 |
|
9325 | if ( importer !== undefined && !isAbsolute( importee ) && importee[0] !== '.' ) { return null; }
|
9326 |
|
9327 |
|
9328 |
|
9329 |
|
9330 |
|
9331 | return addJsExtensionIfNecessary(
|
9332 | resolve( importer ? dirname( importer ) : resolve(), importee ) );
|
9333 | }
|
9334 |
|
9335 |
|
9336 | function makeOnwarn () {
|
9337 | var warned = blank();
|
9338 |
|
9339 | return function (warning) {
|
9340 | var str = warning.toString();
|
9341 | if ( str in warned ) { return; }
|
9342 | console.error( str );
|
9343 | warned[ str ] = true;
|
9344 | };
|
9345 | }
|
9346 |
|
9347 | function badExports ( option, keys$$1 ) {
|
9348 | error({
|
9349 | code: 'INVALID_EXPORT_OPTION',
|
9350 | message: ("'" + option + "' was specified for options.exports, but entry module has following exports: " + (keys$$1.join(', ')))
|
9351 | });
|
9352 | }
|
9353 |
|
9354 | function getExportMode ( bundle, ref ) {
|
9355 | var exportMode = ref.exports;
|
9356 | var moduleName = ref.moduleName;
|
9357 | var format = ref.format;
|
9358 |
|
9359 | var exportKeys = keys( bundle.entryModule.exports )
|
9360 | .concat( keys( bundle.entryModule.reexports ) )
|
9361 | .concat( bundle.entryModule.exportAllSources );
|
9362 |
|
9363 | if ( exportMode === 'default' ) {
|
9364 | if ( exportKeys.length !== 1 || exportKeys[0] !== 'default' ) {
|
9365 | badExports( 'default', exportKeys );
|
9366 | }
|
9367 | } else if ( exportMode === 'none' && exportKeys.length ) {
|
9368 | badExports( 'none', exportKeys );
|
9369 | }
|
9370 |
|
9371 | if ( !exportMode || exportMode === 'auto' ) {
|
9372 | if ( exportKeys.length === 0 ) {
|
9373 | exportMode = 'none';
|
9374 | } else if ( exportKeys.length === 1 && exportKeys[0] === 'default' ) {
|
9375 | exportMode = 'default';
|
9376 | } else {
|
9377 | if ( bundle.entryModule.exports.default && format !== 'es') {
|
9378 | bundle.warn({
|
9379 | code: 'MIXED_EXPORTS',
|
9380 | message: ("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"),
|
9381 | url: "https://github.com/rollup/rollup/wiki/JavaScript-API#exports"
|
9382 | });
|
9383 | }
|
9384 | exportMode = 'named';
|
9385 | }
|
9386 | }
|
9387 |
|
9388 | if ( !/(?:default|named|none)/.test( exportMode ) ) {
|
9389 | error({
|
9390 | code: 'INVALID_EXPORT_OPTION',
|
9391 | message: "options.exports must be 'default', 'named', 'none', 'auto', or left unspecified (defaults to 'auto')"
|
9392 | });
|
9393 | }
|
9394 |
|
9395 | return exportMode;
|
9396 | }
|
9397 |
|
9398 | function getIndentString ( magicString, options ) {
|
9399 | if ( options.indent === true ) {
|
9400 | return magicString.getIndentString();
|
9401 | }
|
9402 |
|
9403 | return options.indent || '';
|
9404 | }
|
9405 |
|
9406 | function transform ( bundle, source, id, plugins ) {
|
9407 | var sourceMapChain = [];
|
9408 |
|
9409 | var originalSourceMap = typeof source.map === 'string' ? JSON.parse( source.map ) : source.map;
|
9410 |
|
9411 | if ( originalSourceMap && typeof originalSourceMap.mappings === 'string' ) {
|
9412 | originalSourceMap.mappings = decode$$1( originalSourceMap.mappings );
|
9413 | }
|
9414 |
|
9415 | var originalCode = source.code;
|
9416 | var ast = source.ast;
|
9417 |
|
9418 | var promise = Promise.resolve( source.code );
|
9419 |
|
9420 | plugins.forEach( function (plugin) {
|
9421 | if ( !plugin.transform ) { return; }
|
9422 |
|
9423 | promise = promise.then( function (previous) {
|
9424 | function augment ( object, pos, code ) {
|
9425 | if ( typeof object === 'string' ) {
|
9426 | object = { message: object };
|
9427 | }
|
9428 |
|
9429 | if ( object.code ) { object.pluginCode = object.code; }
|
9430 | object.code = code;
|
9431 |
|
9432 | if ( pos !== undefined ) {
|
9433 | if ( pos.line !== undefined && pos.column !== undefined ) {
|
9434 | var line = pos.line;
|
9435 | var column = pos.column;
|
9436 | object.loc = { file: id, line: line, column: column };
|
9437 | object.frame = getCodeFrame( previous, line, column );
|
9438 | }
|
9439 | else {
|
9440 | object.pos = pos;
|
9441 | var ref = locate( previous, pos, { offsetLine: 1 });
|
9442 | var line$1 = ref.line;
|
9443 | var column$1 = ref.column;
|
9444 | object.loc = { file: id, line: line$1, column: column$1 };
|
9445 | object.frame = getCodeFrame( previous, line$1, column$1 );
|
9446 | }
|
9447 | }
|
9448 |
|
9449 | object.plugin = plugin.name;
|
9450 | object.id = id;
|
9451 |
|
9452 | return object;
|
9453 | }
|
9454 |
|
9455 | var throwing;
|
9456 |
|
9457 | var context = {
|
9458 | warn: function ( warning, pos ) {
|
9459 | warning = augment( warning, pos, 'PLUGIN_WARNING' );
|
9460 | bundle.warn( warning );
|
9461 | },
|
9462 |
|
9463 | error: function error$1 ( err, pos ) {
|
9464 | err = augment( err, pos, 'PLUGIN_ERROR' );
|
9465 | throwing = true;
|
9466 | error( err );
|
9467 | }
|
9468 | };
|
9469 |
|
9470 | var transformed;
|
9471 |
|
9472 | try {
|
9473 | transformed = plugin.transform.call( context, previous, id );
|
9474 | } catch ( err ) {
|
9475 | if ( !throwing ) { context.error( err ); }
|
9476 | error( err );
|
9477 | }
|
9478 |
|
9479 | return Promise.resolve( transformed )
|
9480 | .then( function (result) {
|
9481 | if ( result == null ) { return previous; }
|
9482 |
|
9483 | if ( typeof result === 'string' ) {
|
9484 | result = {
|
9485 | code: result,
|
9486 | ast: null,
|
9487 | map: null
|
9488 | };
|
9489 | }
|
9490 |
|
9491 |
|
9492 | else if ( typeof result.map === 'string' ) {
|
9493 | result.map = JSON.parse( result.map );
|
9494 | }
|
9495 |
|
9496 | if ( result.map && typeof result.map.mappings === 'string' ) {
|
9497 | result.map.mappings = decode$$1( result.map.mappings );
|
9498 | }
|
9499 |
|
9500 | sourceMapChain.push( result.map || { missing: true, plugin: plugin.name });
|
9501 | ast = result.ast;
|
9502 |
|
9503 | return result.code;
|
9504 | })
|
9505 | .catch( function (err) {
|
9506 | err = augment( err, undefined, 'PLUGIN_ERROR' );
|
9507 | error( err );
|
9508 | });
|
9509 | });
|
9510 | });
|
9511 |
|
9512 | return promise.then( function (code) { return ({ code: code, originalCode: originalCode, originalSourceMap: originalSourceMap, ast: ast, sourceMapChain: sourceMapChain }); } );
|
9513 | }
|
9514 |
|
9515 | function transformBundle ( code, plugins, sourceMapChain, options ) {
|
9516 | return plugins.reduce( function ( promise, plugin ) {
|
9517 | if ( !plugin.transformBundle ) { return promise; }
|
9518 |
|
9519 | return promise.then( function (code) {
|
9520 | return Promise.resolve().then( function () {
|
9521 | return plugin.transformBundle( code, { format : options.format } );
|
9522 | }).then( function (result) {
|
9523 | if ( result == null ) { return code; }
|
9524 |
|
9525 | if ( typeof result === 'string' ) {
|
9526 | result = {
|
9527 | code: result,
|
9528 | map: null
|
9529 | };
|
9530 | }
|
9531 |
|
9532 | var map = typeof result.map === 'string' ? JSON.parse( result.map ) : result.map;
|
9533 | if ( map && typeof map.mappings === 'string' ) {
|
9534 | map.mappings = decode$$1( map.mappings );
|
9535 | }
|
9536 |
|
9537 | sourceMapChain.push( map );
|
9538 |
|
9539 | return result.code;
|
9540 | }).catch( function (err) {
|
9541 | error({
|
9542 | code: 'BAD_BUNDLE_TRANSFORMER',
|
9543 | message: ("Error transforming bundle" + (plugin.name ? (" with '" + (plugin.name) + "' plugin") : '') + ": " + (err.message)),
|
9544 | plugin: plugin.name
|
9545 | });
|
9546 | });
|
9547 | });
|
9548 |
|
9549 | }, Promise.resolve( code ) );
|
9550 | }
|
9551 |
|
9552 | var Source = function Source ( filename, content ) {
|
9553 | this.isOriginal = true;
|
9554 | this.filename = filename;
|
9555 | this.content = content;
|
9556 | };
|
9557 |
|
9558 | Source.prototype.traceSegment = function traceSegment ( line, column, name ) {
|
9559 | return { line: line, column: column, name: name, source: this };
|
9560 | };
|
9561 |
|
9562 | var Link = function Link ( map, sources ) {
|
9563 | this.sources = sources;
|
9564 | this.names = map.names;
|
9565 | this.mappings = map.mappings;
|
9566 | };
|
9567 |
|
9568 | Link.prototype.traceMappings = function traceMappings () {
|
9569 | var this$1 = this;
|
9570 |
|
9571 | var sources = [];
|
9572 | var sourcesContent = [];
|
9573 | var names = [];
|
9574 |
|
9575 | var mappings = this.mappings.map( function (line) {
|
9576 | var tracedLine = [];
|
9577 |
|
9578 | line.forEach( function (segment) {
|
9579 | var source = this$1.sources[ segment[1] ];
|
9580 |
|
9581 | if ( !source ) { return; }
|
9582 |
|
9583 | var traced = source.traceSegment( segment[2], segment[3], this$1.names[ segment[4] ] );
|
9584 |
|
9585 | if ( traced ) {
|
9586 | var sourceIndex = null;
|
9587 | var nameIndex = null;
|
9588 | segment = [
|
9589 | segment[0],
|
9590 | null,
|
9591 | traced.line,
|
9592 | traced.column
|
9593 | ];
|
9594 |
|
9595 |
|
9596 | sourceIndex = sources.lastIndexOf( traced.source.filename );
|
9597 | if ( sourceIndex === -1 ) {
|
9598 | sourceIndex = sources.length;
|
9599 | sources.push( traced.source.filename );
|
9600 | sourcesContent[ sourceIndex ] = traced.source.content;
|
9601 | } else if ( sourcesContent[ sourceIndex ] == null ) {
|
9602 | sourcesContent[ sourceIndex ] = traced.source.content;
|
9603 | } else if ( traced.source.content != null && sourcesContent[ sourceIndex ] !== traced.source.content ) {
|
9604 | error({
|
9605 | message: ("Multiple conflicting contents for sourcemap source " + (source.filename))
|
9606 | });
|
9607 | }
|
9608 |
|
9609 | segment[1] = sourceIndex;
|
9610 |
|
9611 | if ( traced.name ) {
|
9612 | nameIndex = names.indexOf( traced.name );
|
9613 | if ( nameIndex === -1 ) {
|
9614 | nameIndex = names.length;
|
9615 | names.push( traced.name );
|
9616 | }
|
9617 |
|
9618 | segment[4] = nameIndex;
|
9619 | }
|
9620 |
|
9621 | tracedLine.push( segment );
|
9622 | }
|
9623 | });
|
9624 |
|
9625 | return tracedLine;
|
9626 | });
|
9627 |
|
9628 | return { sources: sources, sourcesContent: sourcesContent, names: names, mappings: mappings };
|
9629 | };
|
9630 |
|
9631 | Link.prototype.traceSegment = function traceSegment ( line, column, name ) {
|
9632 | var this$1 = this;
|
9633 |
|
9634 | var segments = this.mappings[ line ];
|
9635 |
|
9636 | if ( !segments ) { return null; }
|
9637 |
|
9638 | for ( var i = 0; i < segments.length; i += 1 ) {
|
9639 | var segment = segments[i];
|
9640 |
|
9641 | if ( segment[0] > column ) { return null; }
|
9642 |
|
9643 | if ( segment[0] === column ) {
|
9644 | var source = this$1.sources[ segment[1] ];
|
9645 | if ( !source ) { return null; }
|
9646 |
|
9647 | return source.traceSegment( segment[2], segment[3], this$1.names[ segment[4] ] || name );
|
9648 | }
|
9649 | }
|
9650 |
|
9651 | return null;
|
9652 | };
|
9653 |
|
9654 | function collapseSourcemaps ( bundle, file, map, modules, bundleSourcemapChain ) {
|
9655 | var moduleSources = modules.filter( function (module) { return !module.excludeFromSourcemap; } ).map( function (module) {
|
9656 | var sourceMapChain = module.sourceMapChain;
|
9657 |
|
9658 | var source;
|
9659 | if ( module.originalSourceMap == null ) {
|
9660 | source = new Source( module.id, module.originalCode );
|
9661 | } else {
|
9662 | var sources = module.originalSourceMap.sources;
|
9663 | var sourcesContent = module.originalSourceMap.sourcesContent || [];
|
9664 |
|
9665 | if ( sources == null || ( sources.length <= 1 && sources[0] == null ) ) {
|
9666 | source = new Source( module.id, sourcesContent[0] );
|
9667 | sourceMapChain = [ module.originalSourceMap ].concat( sourceMapChain );
|
9668 | } else {
|
9669 |
|
9670 | var directory = dirname( module.id ) || '.';
|
9671 | var sourceRoot = module.originalSourceMap.sourceRoot || '.';
|
9672 |
|
9673 | var baseSources = sources.map( function (source, i) {
|
9674 | return new Source( resolve( directory, sourceRoot, source ), sourcesContent[i] );
|
9675 | });
|
9676 |
|
9677 | source = new Link( module.originalSourceMap, baseSources );
|
9678 | }
|
9679 | }
|
9680 |
|
9681 | sourceMapChain.forEach( function (map) {
|
9682 | if ( map.missing ) {
|
9683 | bundle.warn({
|
9684 | code: 'SOURCEMAP_BROKEN',
|
9685 | plugin: map.plugin,
|
9686 | message: ("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 the plugin documentation for help"),
|
9687 | url: "https://github.com/rollup/rollup/wiki/Troubleshooting#sourcemap-is-likely-to-be-incorrect"
|
9688 | });
|
9689 |
|
9690 | map = {
|
9691 | names: [],
|
9692 | mappings: ''
|
9693 | };
|
9694 | }
|
9695 |
|
9696 | source = new Link( map, [ source ]);
|
9697 | });
|
9698 |
|
9699 | return source;
|
9700 | });
|
9701 |
|
9702 | var source = new Link( map, moduleSources );
|
9703 |
|
9704 | bundleSourcemapChain.forEach( function (map) {
|
9705 | source = new Link( map, [ source ] );
|
9706 | });
|
9707 |
|
9708 | var ref = source.traceMappings();
|
9709 | var sources = ref.sources;
|
9710 | var sourcesContent = ref.sourcesContent;
|
9711 | var names = ref.names;
|
9712 | var mappings = ref.mappings;
|
9713 |
|
9714 | if ( file ) {
|
9715 | var directory = dirname( file );
|
9716 | sources = sources.map( function (source) { return relative( directory, source ); } );
|
9717 |
|
9718 | map.file = basename( file );
|
9719 | }
|
9720 |
|
9721 |
|
9722 | map.sources = sources;
|
9723 | map.sourcesContent = sourcesContent;
|
9724 | map.names = names;
|
9725 | map.mappings = encode$$1( mappings );
|
9726 |
|
9727 | return map;
|
9728 | }
|
9729 |
|
9730 | function callIfFunction ( thing ) {
|
9731 | return typeof thing === 'function' ? thing() : thing;
|
9732 | }
|
9733 |
|
9734 | var SyntheticGlobalDeclaration = function SyntheticGlobalDeclaration ( name ) {
|
9735 | this.name = name;
|
9736 | this.isExternal = true;
|
9737 | this.isGlobal = true;
|
9738 | this.isReassigned = false;
|
9739 |
|
9740 | this.activated = true;
|
9741 | };
|
9742 |
|
9743 | SyntheticGlobalDeclaration.prototype.activate = function activate () {
|
9744 |
|
9745 | };
|
9746 |
|
9747 | SyntheticGlobalDeclaration.prototype.addReference = function addReference ( reference ) {
|
9748 | reference.declaration = this;
|
9749 | if ( reference.isReassignment ) { this.isReassigned = true; }
|
9750 | };
|
9751 |
|
9752 | SyntheticGlobalDeclaration.prototype.gatherPossibleValues = function gatherPossibleValues ( values ) {
|
9753 | values.add( UNKNOWN );
|
9754 | };
|
9755 |
|
9756 | SyntheticGlobalDeclaration.prototype.getName = function getName () {
|
9757 | return this.name;
|
9758 | };
|
9759 |
|
9760 | var BundleScope = (function (Scope$$1) {
|
9761 | function BundleScope () {
|
9762 | Scope$$1.apply(this, arguments);
|
9763 | }
|
9764 |
|
9765 | if ( Scope$$1 ) BundleScope.__proto__ = Scope$$1;
|
9766 | BundleScope.prototype = Object.create( Scope$$1 && Scope$$1.prototype );
|
9767 | BundleScope.prototype.constructor = BundleScope;
|
9768 |
|
9769 | BundleScope.prototype.findDeclaration = function findDeclaration ( name ) {
|
9770 | if ( !this.declarations[ name ] ) {
|
9771 | this.declarations[ name ] = new SyntheticGlobalDeclaration( name );
|
9772 | }
|
9773 |
|
9774 | return this.declarations[ name ];
|
9775 | };
|
9776 |
|
9777 | return BundleScope;
|
9778 | }(Scope));
|
9779 |
|
9780 | var Bundle = function Bundle ( options ) {
|
9781 | var this$1 = this;
|
9782 |
|
9783 | this.cachedModules = new Map();
|
9784 | if ( options.cache ) {
|
9785 | options.cache.modules.forEach( function (module) {
|
9786 | this$1.cachedModules.set( module.id, module );
|
9787 | } );
|
9788 | }
|
9789 |
|
9790 | this.plugins = ensureArray( options.plugins );
|
9791 |
|
9792 | options = this.plugins.reduce( function ( acc, plugin ) {
|
9793 | if ( plugin.options ) { return plugin.options( acc ) || acc; }
|
9794 | return acc;
|
9795 | }, options );
|
9796 |
|
9797 | if ( !options.entry ) {
|
9798 | throw new Error( 'You must supply options.entry to rollup' );
|
9799 | }
|
9800 |
|
9801 | this.entry = options.entry;
|
9802 | this.entryId = null;
|
9803 | this.entryModule = null;
|
9804 |
|
9805 | this.treeshake = options.treeshake !== false;
|
9806 |
|
9807 | if ( options.pureExternalModules === true ) {
|
9808 | this.isPureExternalModule = function () { return true; };
|
9809 | } else if ( typeof options.pureExternalModules === 'function' ) {
|
9810 | this.isPureExternalModule = options.pureExternalModules;
|
9811 | } else if ( Array.isArray( options.pureExternalModules ) ) {
|
9812 | var pureExternalModules = new Set( options.pureExternalModules );
|
9813 | this.isPureExternalModule = function (id) { return pureExternalModules.has( id ); };
|
9814 | } else {
|
9815 | this.isPureExternalModule = function () { return false; };
|
9816 | }
|
9817 |
|
9818 | this.resolveId = first(
|
9819 | [ function (id) { return this$1.isExternal( id ) ? false : null; } ]
|
9820 | .concat( this.plugins.map( function (plugin) { return plugin.resolveId; } ).filter( Boolean ) )
|
9821 | .concat( resolveId )
|
9822 | );
|
9823 |
|
9824 | var loaders = this.plugins
|
9825 | .map( function (plugin) { return plugin.load; } )
|
9826 | .filter( Boolean );
|
9827 | this.hasLoaders = loaders.length !== 0;
|
9828 | this.load = first( loaders.concat( load ) );
|
9829 |
|
9830 | var optionsPaths = options.paths;
|
9831 | this.getPath = typeof optionsPaths === 'function' ?
|
9832 | ( function (id) { return optionsPaths( id ) || this$1.getPathRelativeToEntryDirname( id ); } ) :
|
9833 | optionsPaths ?
|
9834 | ( function (id) { return optionsPaths.hasOwnProperty( id ) ? optionsPaths[ id ] : this$1.getPathRelativeToEntryDirname( id ); } ) :
|
9835 | function (id) { return this$1.getPathRelativeToEntryDirname( id ); };
|
9836 |
|
9837 | this.scope = new BundleScope();
|
9838 |
|
9839 | [ 'module', 'exports', '_interopDefault' ].forEach( function (name) {
|
9840 | this$1.scope.findDeclaration( name );
|
9841 | } );
|
9842 |
|
9843 | this.moduleById = new Map();
|
9844 | this.modules = [];
|
9845 | this.externalModules = [];
|
9846 |
|
9847 | this.context = String( options.context );
|
9848 |
|
9849 | var optionsModuleContext = options.moduleContext;
|
9850 | if ( typeof optionsModuleContext === 'function' ) {
|
9851 | this.getModuleContext = function (id) { return optionsModuleContext( id ) || this$1.context; };
|
9852 | } else if ( typeof optionsModuleContext === 'object' ) {
|
9853 | var moduleContext = new Map();
|
9854 | Object.keys( optionsModuleContext ).forEach( function (key) {
|
9855 | moduleContext.set( resolve( key ), optionsModuleContext[ key ] );
|
9856 | } );
|
9857 | this.getModuleContext = function (id) { return moduleContext.get( id ) || this$1.context; };
|
9858 | } else {
|
9859 | this.getModuleContext = function () { return this$1.context; };
|
9860 | }
|
9861 |
|
9862 | if ( typeof options.external === 'function' ) {
|
9863 | this.isExternal = options.external;
|
9864 | } else {
|
9865 | var ids = ensureArray( options.external );
|
9866 | this.isExternal = function (id) { return ids.indexOf( id ) !== -1; };
|
9867 | }
|
9868 |
|
9869 | this.onwarn = options.onwarn || makeOnwarn();
|
9870 |
|
9871 | this.varOrConst = options.preferConst ? 'const' : 'var';
|
9872 | this.legacy = options.legacy;
|
9873 | this.acornOptions = options.acorn || {};
|
9874 |
|
9875 | this.dependentExpressions = [];
|
9876 | };
|
9877 |
|
9878 | Bundle.prototype.build = function build () {
|
9879 | var this$1 = this;
|
9880 |
|
9881 |
|
9882 |
|
9883 |
|
9884 | return this.resolveId( this.entry, undefined )
|
9885 | .then( function (id) {
|
9886 | if ( id === false ) {
|
9887 | error( {
|
9888 | code: 'UNRESOLVED_ENTRY',
|
9889 | message: "Entry module cannot be external"
|
9890 | } );
|
9891 | }
|
9892 |
|
9893 | if ( id == null ) {
|
9894 | error( {
|
9895 | code: 'UNRESOLVED_ENTRY',
|
9896 | message: ("Could not resolve entry (" + (this$1.entry) + ")")
|
9897 | } );
|
9898 | }
|
9899 |
|
9900 | this$1.entryId = id;
|
9901 | return this$1.fetchModule( id, undefined );
|
9902 | } )
|
9903 | .then( function (entryModule) {
|
9904 | this$1.entryModule = entryModule;
|
9905 |
|
9906 |
|
9907 |
|
9908 |
|
9909 | timeStart( 'phase 2' );
|
9910 |
|
9911 | this$1.modules.forEach( function (module) { return module.bindImportSpecifiers(); } );
|
9912 | this$1.modules.forEach( function (module) { return module.bindReferences(); } );
|
9913 |
|
9914 | timeEnd( 'phase 2' );
|
9915 |
|
9916 |
|
9917 |
|
9918 |
|
9919 | timeStart( 'phase 3' );
|
9920 |
|
9921 |
|
9922 | entryModule.getExports().forEach( function (name) {
|
9923 | var declaration = entryModule.traceExport( name );
|
9924 |
|
9925 | declaration.exportName = name;
|
9926 | declaration.activate();
|
9927 |
|
9928 | if ( declaration.isNamespace ) {
|
9929 | declaration.needsNamespaceBlock = true;
|
9930 | }
|
9931 | });
|
9932 |
|
9933 | entryModule.getReexports().forEach( function (name) {
|
9934 | var declaration = entryModule.traceExport( name );
|
9935 |
|
9936 | if ( declaration.isExternal ) {
|
9937 | declaration.reexported = declaration.module.reexported = true;
|
9938 | } else {
|
9939 | declaration.exportName = name;
|
9940 | declaration.activate();
|
9941 | }
|
9942 | });
|
9943 |
|
9944 |
|
9945 | if ( this$1.treeshake ) {
|
9946 | this$1.modules.forEach( function (module) {
|
9947 | module.run();
|
9948 | } );
|
9949 |
|
9950 | var settled = false;
|
9951 | while ( !settled ) {
|
9952 | settled = true;
|
9953 |
|
9954 | var i = this$1.dependentExpressions.length;
|
9955 | while ( i-- ) {
|
9956 | var expression = this$1.dependentExpressions[ i ];
|
9957 |
|
9958 | var statement = expression;
|
9959 | while ( statement.parent && !/Function/.test( statement.parent.type ) ) { statement = statement.parent; }
|
9960 |
|
9961 | if ( !statement || statement.ran ) {
|
9962 | this$1.dependentExpressions.splice( i, 1 );
|
9963 | } else if ( expression.isUsedByBundle() ) {
|
9964 | settled = false;
|
9965 | statement.run();
|
9966 | this$1.dependentExpressions.splice( i, 1 );
|
9967 | }
|
9968 | }
|
9969 | }
|
9970 | }
|
9971 |
|
9972 | timeEnd( 'phase 3' );
|
9973 |
|
9974 |
|
9975 |
|
9976 |
|
9977 |
|
9978 | timeStart( 'phase 4' );
|
9979 |
|
9980 |
|
9981 | this$1.externalModules.forEach( function (module) {
|
9982 | var unused = Object.keys( module.declarations )
|
9983 | .filter( function (name) { return name !== '*'; } )
|
9984 | .filter( function (name) { return !module.declarations[ name ].activated && !module.declarations[ name ].reexported; } );
|
9985 |
|
9986 | if ( unused.length === 0 ) { return; }
|
9987 |
|
9988 | var names = unused.length === 1 ?
|
9989 | ("'" + (unused[0]) + "' is") :
|
9990 | ((unused.slice( 0, -1 ).map( function (name) { return ("'" + name + "'"); } ).join( ', ' )) + " and '" + (unused.slice( -1 )) + "' are");
|
9991 |
|
9992 | this$1.warn( {
|
9993 | code: 'UNUSED_EXTERNAL_IMPORT',
|
9994 | source: module.id,
|
9995 | names: unused,
|
9996 | message: (names + " imported from external module '" + (module.id) + "' but never used")
|
9997 | } );
|
9998 | } );
|
9999 |
|
10000 |
|
10001 | this$1.externalModules = this$1.externalModules.filter( function (module) {
|
10002 | return module.used || !this$1.isPureExternalModule( module.id );
|
10003 | } );
|
10004 |
|
10005 | this$1.orderedModules = this$1.sort();
|
10006 | this$1.deconflict();
|
10007 |
|
10008 | timeEnd( 'phase 4' );
|
10009 | } );
|
10010 | };
|
10011 |
|
10012 | Bundle.prototype.deconflict = function deconflict () {
|
10013 | var used = blank();
|
10014 |
|
10015 |
|
10016 | keys( this.scope.declarations ).forEach( function (name) { return used[ name ] = 1; } );
|
10017 |
|
10018 | function getSafeName ( name ) {
|
10019 | while ( used[ name ] ) {
|
10020 | name += "$" + (used[ name ]++);
|
10021 | }
|
10022 |
|
10023 | used[ name ] = 1;
|
10024 | return name;
|
10025 | }
|
10026 |
|
10027 | var toDeshadow = new Set();
|
10028 |
|
10029 | this.externalModules.forEach( function (module) {
|
10030 | var safeName = getSafeName( module.name );
|
10031 | toDeshadow.add( safeName );
|
10032 | module.name = safeName;
|
10033 |
|
10034 |
|
10035 |
|
10036 | forOwn( module.declarations, function ( declaration, name ) {
|
10037 | var safeName = getSafeName( name );
|
10038 | toDeshadow.add( safeName );
|
10039 | declaration.setSafeName( safeName );
|
10040 | } );
|
10041 | } );
|
10042 |
|
10043 | this.modules.forEach( function (module) {
|
10044 | forOwn( module.scope.declarations, function ( declaration ) {
|
10045 | if ( declaration.isDefault && declaration.declaration.id ) {
|
10046 | return;
|
10047 | }
|
10048 |
|
10049 | declaration.name = getSafeName( declaration.name );
|
10050 | } );
|
10051 |
|
10052 |
|
10053 | var namespace = module.namespace();
|
10054 | if ( namespace.needsNamespaceBlock ) {
|
10055 | namespace.name = getSafeName( namespace.name );
|
10056 | }
|
10057 | } );
|
10058 |
|
10059 | this.scope.deshadow( toDeshadow );
|
10060 | };
|
10061 |
|
10062 | Bundle.prototype.fetchModule = function fetchModule ( id, importer ) {
|
10063 | var this$1 = this;
|
10064 |
|
10065 |
|
10066 | if ( this.moduleById.has( id ) ) { return null; }
|
10067 | this.moduleById.set( id, null );
|
10068 |
|
10069 | return this.load( id )
|
10070 | .catch( function (err) {
|
10071 | var msg = "Could not load " + id;
|
10072 | if ( importer ) { msg += " (imported by " + importer + ")"; }
|
10073 |
|
10074 | msg += ": " + (err.message);
|
10075 | throw new Error( msg );
|
10076 | } )
|
10077 | .then( function (source) {
|
10078 | if ( typeof source === 'string' ) { return source; }
|
10079 | if ( source && typeof source === 'object' && source.code ) { return source; }
|
10080 |
|
10081 |
|
10082 | error( {
|
10083 | code: 'BAD_LOADER',
|
10084 | message: ("Error loading " + (relativeId( id )) + ": plugin load hook should return a string, a { code, map } object, or nothing/null")
|
10085 | } );
|
10086 | } )
|
10087 | .then( function (source) {
|
10088 | if ( typeof source === 'string' ) {
|
10089 | source = {
|
10090 | code: source,
|
10091 | ast: null
|
10092 | };
|
10093 | }
|
10094 |
|
10095 | if ( this$1.cachedModules.has( id ) && this$1.cachedModules.get( id ).originalCode === source.code ) {
|
10096 | return this$1.cachedModules.get( id );
|
10097 | }
|
10098 |
|
10099 | return transform( this$1, source, id, this$1.plugins );
|
10100 | } )
|
10101 | .then( function (source) {
|
10102 | var code = source.code;
|
10103 | var originalCode = source.originalCode;
|
10104 | var originalSourceMap = source.originalSourceMap;
|
10105 | var ast = source.ast;
|
10106 | var sourceMapChain = source.sourceMapChain;
|
10107 | var resolvedIds = source.resolvedIds;
|
10108 |
|
10109 | var module = new Module( {
|
10110 | id: id,
|
10111 | code: code,
|
10112 | originalCode: originalCode,
|
10113 | originalSourceMap: originalSourceMap,
|
10114 | ast: ast,
|
10115 | sourceMapChain: sourceMapChain,
|
10116 | resolvedIds: resolvedIds,
|
10117 | bundle: this$1
|
10118 | } );
|
10119 |
|
10120 | this$1.modules.push( module );
|
10121 | this$1.moduleById.set( id, module );
|
10122 |
|
10123 | return this$1.fetchAllDependencies( module ).then( function () {
|
10124 | keys( module.exports ).forEach( function (name) {
|
10125 | if ( name !== 'default' ) {
|
10126 | module.exportsAll[ name ] = module.id;
|
10127 | }
|
10128 | } );
|
10129 | module.exportAllSources.forEach( function (source) {
|
10130 | var id = module.resolvedIds[ source ] || module.resolvedExternalIds[ source ];
|
10131 | var exportAllModule = this$1.moduleById.get( id );
|
10132 | if ( exportAllModule.isExternal ) { return; }
|
10133 |
|
10134 | keys( exportAllModule.exportsAll ).forEach( function (name) {
|
10135 | if ( name in module.exportsAll ) {
|
10136 | this$1.warn( {
|
10137 | code: 'NAMESPACE_CONFLICT',
|
10138 | reexporter: module.id,
|
10139 | name: name,
|
10140 | sources: [ module.exportsAll[ name ], exportAllModule.exportsAll[ name ] ],
|
10141 | message: ("Conflicting namespaces: " + (relativeId( module.id )) + " re-exports '" + name + "' from both " + (relativeId( module.exportsAll[ name ] )) + " and " + (relativeId( exportAllModule.exportsAll[ name ] )) + " (will be ignored)")
|
10142 | } );
|
10143 | } else {
|
10144 | module.exportsAll[ name ] = exportAllModule.exportsAll[ name ];
|
10145 | }
|
10146 | } );
|
10147 | } );
|
10148 | return module;
|
10149 | } );
|
10150 | } );
|
10151 | };
|
10152 |
|
10153 | Bundle.prototype.fetchAllDependencies = function fetchAllDependencies ( module ) {
|
10154 | var this$1 = this;
|
10155 |
|
10156 | return mapSequence( module.sources, function (source) {
|
10157 | var resolvedId = module.resolvedIds[ source ];
|
10158 | return ( resolvedId ? Promise.resolve( resolvedId ) : this$1.resolveId( source, module.id ) )
|
10159 | .then( function (resolvedId) {
|
10160 | var externalId = resolvedId || (
|
10161 | isRelative( source ) ? resolve( module.id, '..', source ) : source
|
10162 | );
|
10163 |
|
10164 | var isExternal = this$1.isExternal( externalId );
|
10165 |
|
10166 | if ( !resolvedId && !isExternal ) {
|
10167 | if ( isRelative( source ) ) {
|
10168 | error( {
|
10169 | code: 'UNRESOLVED_IMPORT',
|
10170 | message: ("Could not resolve '" + source + "' from " + (relativeId( module.id )))
|
10171 | } );
|
10172 | }
|
10173 |
|
10174 | this$1.warn( {
|
10175 | code: 'UNRESOLVED_IMPORT',
|
10176 | source: source,
|
10177 | importer: relativeId( module.id ),
|
10178 | message: ("'" + source + "' is imported by " + (relativeId( module.id )) + ", but could not be resolved – treating it as an external dependency"),
|
10179 | url: 'https://github.com/rollup/rollup/wiki/Troubleshooting#treating-module-as-external-dependency'
|
10180 | } );
|
10181 | isExternal = true;
|
10182 | }
|
10183 |
|
10184 | if ( isExternal ) {
|
10185 | module.resolvedExternalIds[ source ] = externalId;
|
10186 |
|
10187 | if ( !this$1.moduleById.has( externalId ) ) {
|
10188 | var module$1 = new ExternalModule( externalId, this$1.getPath( externalId ) );
|
10189 | this$1.externalModules.push( module$1 );
|
10190 | this$1.moduleById.set( externalId, module$1 );
|
10191 | }
|
10192 |
|
10193 | var externalModule = this$1.moduleById.get( externalId );
|
10194 |
|
10195 |
|
10196 | Object.keys( module.imports ).forEach( function (name) {
|
10197 | var importDeclaration = module.imports[ name ];
|
10198 | if ( importDeclaration.source !== source ) { return; }
|
10199 |
|
10200 | externalModule.traceExport( importDeclaration.name );
|
10201 | } );
|
10202 | } else {
|
10203 | if ( resolvedId === module.id ) {
|
10204 |
|
10205 |
|
10206 | var declaration = module.ast.body.find( function (node) {
|
10207 | return node.isImportDeclaration && node.source.value === source;
|
10208 | } );
|
10209 |
|
10210 | module.error( {
|
10211 | code: 'CANNOT_IMPORT_SELF',
|
10212 | message: "A module cannot import itself"
|
10213 | }, declaration.start );
|
10214 | }
|
10215 |
|
10216 | module.resolvedIds[ source ] = resolvedId;
|
10217 | return this$1.fetchModule( resolvedId, module.id );
|
10218 | }
|
10219 | } );
|
10220 | } );
|
10221 | };
|
10222 |
|
10223 | Bundle.prototype.getPathRelativeToEntryDirname = function getPathRelativeToEntryDirname ( resolvedId ) {
|
10224 | if ( isRelative( resolvedId ) || isAbsolute( resolvedId ) ) {
|
10225 | var entryDirname = dirname( this.entryId );
|
10226 | var relativeToEntry = normalize( relative( entryDirname, resolvedId ) );
|
10227 |
|
10228 | return isRelative( relativeToEntry ) ? relativeToEntry : ("./" + relativeToEntry);
|
10229 | }
|
10230 |
|
10231 | return resolvedId;
|
10232 | };
|
10233 |
|
10234 | Bundle.prototype.render = function render ( options ) {
|
10235 | var this$1 = this;
|
10236 | if ( options === void 0 ) options = {};
|
10237 |
|
10238 | return Promise.resolve().then( function () {
|
10239 |
|
10240 | var exportMode = getExportMode( this$1, options );
|
10241 |
|
10242 | var magicString = new Bundle$2( { separator: '\n\n' } );
|
10243 | var usedModules = [];
|
10244 |
|
10245 | timeStart( 'render modules' );
|
10246 |
|
10247 | this$1.orderedModules.forEach( function (module) {
|
10248 | var source = module.render( options.format === 'es', this$1.legacy );
|
10249 |
|
10250 | if ( source.toString().length ) {
|
10251 | magicString.addSource( source );
|
10252 | usedModules.push( module );
|
10253 | }
|
10254 | } );
|
10255 |
|
10256 | if ( !magicString.toString().trim() && this$1.entryModule.getExports().length === 0 && this$1.entryModule.getReexports().length === 0 ) {
|
10257 | this$1.warn( {
|
10258 | code: 'EMPTY_BUNDLE',
|
10259 | message: 'Generated an empty bundle'
|
10260 | } );
|
10261 | }
|
10262 |
|
10263 | timeEnd( 'render modules' );
|
10264 |
|
10265 | var intro = [ options.intro ]
|
10266 | .concat(
|
10267 | this$1.plugins.map( function (plugin) { return plugin.intro && plugin.intro(); } )
|
10268 | )
|
10269 | .filter( Boolean )
|
10270 | .join( '\n\n' );
|
10271 |
|
10272 | if ( intro ) { intro += '\n\n'; }
|
10273 |
|
10274 | var outro = [ options.outro ]
|
10275 | .concat(
|
10276 | this$1.plugins.map( function (plugin) { return plugin.outro && plugin.outro(); } )
|
10277 | )
|
10278 | .filter( Boolean )
|
10279 | .join( '\n\n' );
|
10280 |
|
10281 | if ( outro ) { outro = "\n\n" + outro; }
|
10282 |
|
10283 | var indentString = getIndentString( magicString, options );
|
10284 |
|
10285 | var finalise = finalisers[ options.format ];
|
10286 | if ( !finalise ) {
|
10287 | error({
|
10288 | code: 'INVALID_OPTION',
|
10289 | message: ("Invalid format: " + (options.format) + " - valid options are " + (keys( finalisers ).join( ', ' )))
|
10290 | });
|
10291 | }
|
10292 |
|
10293 | timeStart( 'render format' );
|
10294 |
|
10295 | magicString = finalise( this$1, magicString.trim(), { exportMode: exportMode, indentString: indentString, intro: intro, outro: outro }, options );
|
10296 |
|
10297 | timeEnd( 'render format' );
|
10298 |
|
10299 | var banner = [ options.banner ]
|
10300 | .concat( this$1.plugins.map( function (plugin) { return plugin.banner; } ) )
|
10301 | .map( callIfFunction )
|
10302 | .filter( Boolean )
|
10303 | .join( '\n' );
|
10304 |
|
10305 | var footer = [ options.footer ]
|
10306 | .concat( this$1.plugins.map( function (plugin) { return plugin.footer; } ) )
|
10307 | .map( callIfFunction )
|
10308 | .filter( Boolean )
|
10309 | .join( '\n' );
|
10310 |
|
10311 | if ( banner ) { magicString.prepend( banner + '\n' ); }
|
10312 | if ( footer ) { magicString.append( '\n' + footer ); }
|
10313 |
|
10314 | var prevCode = magicString.toString();
|
10315 | var map = null;
|
10316 | var bundleSourcemapChain = [];
|
10317 |
|
10318 | return transformBundle( prevCode, this$1.plugins, bundleSourcemapChain, options ).then( function (code) {
|
10319 | if ( options.sourceMap ) {
|
10320 | timeStart( 'sourceMap' );
|
10321 |
|
10322 | var file = options.sourceMapFile || options.dest;
|
10323 | if ( file ) { file = resolve( typeof process !== 'undefined' ? process.cwd() : '', file ); }
|
10324 |
|
10325 | if ( this$1.hasLoaders || find( this$1.plugins, function (plugin) { return plugin.transform || plugin.transformBundle; } ) ) {
|
10326 | map = magicString.generateMap( {} );
|
10327 | if ( typeof map.mappings === 'string' ) {
|
10328 | map.mappings = decode$$1( map.mappings );
|
10329 | }
|
10330 | map = collapseSourcemaps( this$1, file, map, usedModules, bundleSourcemapChain );
|
10331 | } else {
|
10332 | map = magicString.generateMap( { file: file, includeContent: true } );
|
10333 | }
|
10334 |
|
10335 | map.sources = map.sources.map( normalize );
|
10336 |
|
10337 | timeEnd( 'sourceMap' );
|
10338 | }
|
10339 |
|
10340 | if ( code[ code.length - 1 ] !== '\n' ) { code += '\n'; }
|
10341 | return { code: code, map: map };
|
10342 | } );
|
10343 | } );
|
10344 | };
|
10345 |
|
10346 | Bundle.prototype.sort = function sort () {
|
10347 | var this$1 = this;
|
10348 |
|
10349 | var hasCycles;
|
10350 | var seen = {};
|
10351 | var ordered = [];
|
10352 |
|
10353 | var stronglyDependsOn = blank();
|
10354 | var dependsOn = blank();
|
10355 |
|
10356 | this.modules.forEach( function (module) {
|
10357 | stronglyDependsOn[ module.id ] = blank();
|
10358 | dependsOn[ module.id ] = blank();
|
10359 | } );
|
10360 |
|
10361 | this.modules.forEach( function (module) {
|
10362 | function processStrongDependency ( dependency ) {
|
10363 | if ( dependency === module || stronglyDependsOn[ module.id ][ dependency.id ] ) { return; }
|
10364 |
|
10365 | stronglyDependsOn[ module.id ][ dependency.id ] = true;
|
10366 | dependency.strongDependencies.forEach( processStrongDependency );
|
10367 | }
|
10368 |
|
10369 | function processDependency ( dependency ) {
|
10370 | if ( dependency === module || dependsOn[ module.id ][ dependency.id ] ) { return; }
|
10371 |
|
10372 | dependsOn[ module.id ][ dependency.id ] = true;
|
10373 | dependency.dependencies.forEach( processDependency );
|
10374 | }
|
10375 |
|
10376 | module.strongDependencies.forEach( processStrongDependency );
|
10377 | module.dependencies.forEach( processDependency );
|
10378 | } );
|
10379 |
|
10380 | var visit = function (module) {
|
10381 | if ( seen[ module.id ] ) {
|
10382 | hasCycles = true;
|
10383 | return;
|
10384 | }
|
10385 |
|
10386 | seen[ module.id ] = true;
|
10387 |
|
10388 | module.dependencies.forEach( visit );
|
10389 | ordered.push( module );
|
10390 | };
|
10391 |
|
10392 | visit( this.entryModule );
|
10393 |
|
10394 | if ( hasCycles ) {
|
10395 | ordered.forEach( function ( a, i ) {
|
10396 | var loop = function ( ) {
|
10397 | var b = ordered[ i ];
|
10398 |
|
10399 |
|
10400 | if ( stronglyDependsOn[ a.id ][ b.id ] ) {
|
10401 |
|
10402 |
|
10403 |
|
10404 | var parent = '[[unknown]]';
|
10405 | var visited = {};
|
10406 |
|
10407 | var findParent = function (module) {
|
10408 | if ( dependsOn[ module.id ][ a.id ] && dependsOn[ module.id ][ b.id ] ) {
|
10409 | parent = module.id;
|
10410 | return true;
|
10411 | }
|
10412 | visited[ module.id ] = true;
|
10413 | for ( var i = 0; i < module.dependencies.length; i += 1 ) {
|
10414 | var dependency = module.dependencies[ i ];
|
10415 | if ( !visited[ dependency.id ] && findParent( dependency ) ) { return true; }
|
10416 | }
|
10417 | };
|
10418 |
|
10419 | findParent( this$1.entryModule );
|
10420 |
|
10421 | this$1.onwarn(
|
10422 | ("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")
|
10423 | );
|
10424 | }
|
10425 | };
|
10426 |
|
10427 | for ( i += 1; i < ordered.length; i += 1 ) loop( );
|
10428 | } );
|
10429 | }
|
10430 |
|
10431 | return ordered;
|
10432 | };
|
10433 |
|
10434 | Bundle.prototype.warn = function warn ( warning ) {
|
10435 | warning.toString = function () {
|
10436 | var str = '';
|
10437 |
|
10438 | if ( warning.plugin ) { str += "(" + (warning.plugin) + " plugin) "; }
|
10439 | if ( warning.loc ) { str += (relativeId( warning.loc.file )) + " (" + (warning.loc.line) + ":" + (warning.loc.column) + ") "; }
|
10440 | str += warning.message;
|
10441 |
|
10442 | return str;
|
10443 | };
|
10444 |
|
10445 | this.onwarn( warning );
|
10446 | };
|
10447 |
|
10448 | var ALLOWED_KEYS = [
|
10449 | 'acorn',
|
10450 | 'amd',
|
10451 | 'banner',
|
10452 | 'cache',
|
10453 | 'context',
|
10454 | 'dest',
|
10455 | 'entry',
|
10456 | 'exports',
|
10457 | 'extend',
|
10458 | 'external',
|
10459 | 'footer',
|
10460 | 'format',
|
10461 | 'globals',
|
10462 | 'indent',
|
10463 | 'interop',
|
10464 | 'intro',
|
10465 | 'legacy',
|
10466 | 'moduleContext',
|
10467 | 'moduleName',
|
10468 | 'noConflict',
|
10469 | 'onwarn',
|
10470 | 'outro',
|
10471 | 'paths',
|
10472 | 'plugins',
|
10473 | 'preferConst',
|
10474 | 'pureExternalModules',
|
10475 | 'sourceMap',
|
10476 | 'sourceMapFile',
|
10477 | 'targets',
|
10478 | 'treeshake',
|
10479 | 'useStrict',
|
10480 | 'watch'
|
10481 | ];
|
10482 |
|
10483 | function checkAmd ( options ) {
|
10484 | if ( options.moduleId ) {
|
10485 | if ( options.amd ) { throw new Error( 'Cannot have both options.amd and options.moduleId' ); }
|
10486 |
|
10487 | options.amd = { id: options.moduleId };
|
10488 | delete options.moduleId;
|
10489 |
|
10490 | var msg = "options.moduleId is deprecated in favour of options.amd = { id: moduleId }";
|
10491 | if ( options.onwarn ) {
|
10492 | options.onwarn( msg );
|
10493 | } else {
|
10494 | console.warn( msg );
|
10495 | }
|
10496 | }
|
10497 | }
|
10498 |
|
10499 | function checkOptions ( options ) {
|
10500 | if ( !options ) {
|
10501 | throw new Error( 'You must supply an options object to rollup' );
|
10502 | }
|
10503 |
|
10504 | if ( options.transform || options.load || options.resolveId || options.resolveExternal ) {
|
10505 | throw 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' );
|
10506 | }
|
10507 |
|
10508 | checkAmd (options);
|
10509 |
|
10510 | var err = validateKeys( keys(options), ALLOWED_KEYS );
|
10511 | if ( err ) { throw err; }
|
10512 | }
|
10513 |
|
10514 | var throwAsyncGenerateError = {
|
10515 | get: function get () {
|
10516 | throw new Error( "bundle.generate(...) now returns a Promise instead of a { code, map } object" );
|
10517 | }
|
10518 | };
|
10519 |
|
10520 | function rollup ( options ) {
|
10521 | try {
|
10522 | checkOptions( options );
|
10523 | var bundle = new Bundle( options );
|
10524 |
|
10525 | timeStart( '--BUILD--' );
|
10526 |
|
10527 | return bundle.build().then( function () {
|
10528 | timeEnd( '--BUILD--' );
|
10529 |
|
10530 | function generate ( options ) {
|
10531 | if ( options === void 0 ) options = {};
|
10532 |
|
10533 | if ( options.format === 'es6' ) {
|
10534 | throw new Error( 'The `es6` output format is deprecated – use `es` instead' );
|
10535 | }
|
10536 |
|
10537 | if ( !options.format ) {
|
10538 | error({
|
10539 | code: 'MISSING_FORMAT',
|
10540 | message: "You must supply an output format",
|
10541 | url: "https://github.com/rollup/rollup/wiki/JavaScript-API#format"
|
10542 | });
|
10543 | }
|
10544 |
|
10545 | checkAmd( options );
|
10546 |
|
10547 | timeStart( '--GENERATE--' );
|
10548 |
|
10549 | var promise = Promise.resolve()
|
10550 | .then( function () { return bundle.render( options ); } )
|
10551 | .then( function (rendered) {
|
10552 | timeEnd( '--GENERATE--' );
|
10553 |
|
10554 | bundle.plugins.forEach( function (plugin) {
|
10555 | if ( plugin.ongenerate ) {
|
10556 | plugin.ongenerate( assign({
|
10557 | bundle: result
|
10558 | }, options ), rendered);
|
10559 | }
|
10560 | });
|
10561 |
|
10562 | flushTime();
|
10563 |
|
10564 | return rendered;
|
10565 | });
|
10566 |
|
10567 | Object.defineProperty( promise, 'code', throwAsyncGenerateError );
|
10568 | Object.defineProperty( promise, 'map', throwAsyncGenerateError );
|
10569 |
|
10570 | return promise;
|
10571 | }
|
10572 |
|
10573 | var result = {
|
10574 | imports: bundle.externalModules.map( function (module) { return module.id; } ),
|
10575 | exports: keys( bundle.entryModule.exports ),
|
10576 | modules: bundle.orderedModules.map( function (module) { return module.toJSON(); } ),
|
10577 |
|
10578 | generate: generate,
|
10579 | write: function (options) {
|
10580 | if ( !options || !options.dest ) {
|
10581 | error({
|
10582 | code: 'MISSING_OPTION',
|
10583 | message: 'You must supply options.dest to bundle.write'
|
10584 | });
|
10585 | }
|
10586 |
|
10587 | var dest = options.dest;
|
10588 | return generate( options ).then( function (output) {
|
10589 | var code = output.code;
|
10590 | var map = output.map;
|
10591 |
|
10592 | var promises = [];
|
10593 |
|
10594 | if ( options.sourceMap ) {
|
10595 | var url;
|
10596 |
|
10597 | if ( options.sourceMap === 'inline' ) {
|
10598 | url = map.toUrl();
|
10599 | } else {
|
10600 | url = (basename( dest )) + ".map";
|
10601 | promises.push( writeFile( dest + '.map', map.toString() ) );
|
10602 | }
|
10603 |
|
10604 | code += "//# " + SOURCEMAPPING_URL + "=" + url + "\n";
|
10605 | }
|
10606 |
|
10607 | promises.push( writeFile( dest, code ) );
|
10608 | return Promise.all( promises ).then( function () {
|
10609 | return mapSequence( bundle.plugins.filter( function (plugin) { return plugin.onwrite; } ), function (plugin) {
|
10610 | return Promise.resolve( plugin.onwrite( assign({
|
10611 | bundle: result
|
10612 | }, options ), output));
|
10613 | });
|
10614 | });
|
10615 | });
|
10616 | }
|
10617 | };
|
10618 |
|
10619 | return result;
|
10620 | });
|
10621 | } catch ( err ) {
|
10622 | return Promise.reject( err );
|
10623 | }
|
10624 | }
|
10625 |
|
10626 | var version$1 = "0.47.4";
|
10627 |
|
10628 | exports.rollup = rollup;
|
10629 | exports.VERSION = version$1;
|
10630 |
|
10631 | Object.defineProperty(exports, '__esModule', { value: true });
|
10632 |
|
10633 | })));
|
10634 |
|