@@ -97,7 +97,18 @@ function parseSource (cjsSource) {
97
97
lastTokenPos = pos ;
98
98
continue ;
99
99
case 95 /*_*/ :
100
- if ( source . startsWith ( '_export' , pos + 1 ) && ( keywordStart ( pos ) || source . charCodeAt ( pos - 1 ) === 46 /*.*/ ) ) {
100
+ if ( source . startsWith ( 'interopRequireWildcard' , pos + 1 ) && ( keywordStart ( pos ) || source . charCodeAt ( pos - 1 ) === 46 /*.*/ ) ) {
101
+ const startPos = pos ;
102
+ pos += 23 ;
103
+ if ( source . charCodeAt ( pos ) === 40 /*(*/ ) {
104
+ pos ++ ;
105
+ openTokenPosStack [ openTokenDepth ++ ] = lastTokenPos ;
106
+ if ( tryParseRequire ( Import ) && keywordStart ( startPos ) ) {
107
+ tryBacktrackAddStarExportBinding ( startPos - 1 ) ;
108
+ }
109
+ }
110
+ }
111
+ else if ( source . startsWith ( '_export' , pos + 1 ) && ( keywordStart ( pos ) || source . charCodeAt ( pos - 1 ) === 46 /*.*/ ) ) {
101
112
pos += 8 ;
102
113
if ( source . startsWith ( 'Star' , pos ) )
103
114
pos += 4 ;
@@ -254,6 +265,48 @@ function tryBacktrackAddStarExportBinding (bPos) {
254
265
}
255
266
}
256
267
268
+ // `Object.` `prototype.`? hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)`
269
+ function tryParseObjectHasOwnProperty ( it_id ) {
270
+ ch = commentWhitespace ( ) ;
271
+ if ( ch !== 79 /*O*/ || ! source . startsWith ( 'bject' , pos + 1 ) ) return false ;
272
+ pos += 6 ;
273
+ ch = commentWhitespace ( ) ;
274
+ if ( ch !== 46 /*.*/ ) return false ;
275
+ pos ++ ;
276
+ ch = commentWhitespace ( ) ;
277
+ if ( ch === 112 /*p*/ ) {
278
+ if ( ! source . startsWith ( 'rototype' , pos + 1 ) ) return false ;
279
+ pos += 9 ;
280
+ ch = commentWhitespace ( ) ;
281
+ if ( ch !== 46 /*.*/ ) return false ;
282
+ pos ++ ;
283
+ ch = commentWhitespace ( ) ;
284
+ }
285
+ if ( ch !== 104 /*h*/ || ! source . startsWith ( 'asOwnProperty' , pos + 1 ) ) return false ;
286
+ pos += 14 ;
287
+ ch = commentWhitespace ( ) ;
288
+ if ( ch !== 46 /*.*/ ) return false ;
289
+ pos ++ ;
290
+ ch = commentWhitespace ( ) ;
291
+ if ( ch !== 99 /*c*/ || ! source . startsWith ( 'all' , pos + 1 ) ) return false ;
292
+ pos += 4 ;
293
+ ch = commentWhitespace ( ) ;
294
+ if ( ch !== 40 /*(*/ ) return false ;
295
+ pos ++ ;
296
+ ch = commentWhitespace ( ) ;
297
+ if ( ! identifier ( ) ) return false ;
298
+ ch = commentWhitespace ( ) ;
299
+ if ( ch !== 44 /*,*/ ) return false ;
300
+ pos ++ ;
301
+ ch = commentWhitespace ( ) ;
302
+ if ( ! source . startsWith ( it_id , pos ) ) return false ;
303
+ pos += it_id . length ;
304
+ ch = commentWhitespace ( ) ;
305
+ if ( ch !== 41 /*)*/ ) return false ;
306
+ pos ++ ;
307
+ return true ;
308
+ }
309
+
257
310
function tryParseObjectDefineOrKeys ( keys ) {
258
311
pos += 6 ;
259
312
let revertPos = pos - 1 ;
@@ -366,6 +419,10 @@ function tryParseObjectDefineOrKeys (keys) {
366
419
if ( ch !== 125 /*}*/ ) break ;
367
420
pos ++ ;
368
421
ch = commentWhitespace ( ) ;
422
+ if ( ch === 44 /*,*/ ) {
423
+ pos ++ ;
424
+ ch = commentWhitespace ( ) ;
425
+ }
369
426
if ( ch !== 125 /*}*/ ) break ;
370
427
pos ++ ;
371
428
ch = commentWhitespace ( ) ;
@@ -469,8 +526,94 @@ function tryParseObjectDefineOrKeys (keys) {
469
526
if ( ch === 59 /*;*/ )
470
527
pos ++ ;
471
528
ch = commentWhitespace ( ) ;
529
+
530
+ // `if (`
531
+ if ( ch === 105 /*i*/ && source . charCodeAt ( pos + 1 ) === 102 /*f*/ ) {
532
+ let inIf = true ;
533
+ pos += 2 ;
534
+ ch = commentWhitespace ( ) ;
535
+ if ( ch !== 40 /*(*/ ) break ;
536
+ pos ++ ;
537
+ const ifInnerPos = pos ;
538
+ // `Object.prototype.hasOwnProperty.call(` IDENTIFIER `, ` IDENTIFIER$2 `)) return` `;`?
539
+ if ( tryParseObjectHasOwnProperty ( it_id ) ) {
540
+ ch = commentWhitespace ( ) ;
541
+ if ( ch !== 41 /*)*/ ) break ;
542
+ pos ++ ;
543
+ ch = commentWhitespace ( ) ;
544
+ if ( ch !== 114 /*r*/ || ! source . startsWith ( 'eturn' , pos + 1 ) ) break ;
545
+ pos += 6 ;
546
+ ch = commentWhitespace ( ) ;
547
+ if ( ch === 59 /*;*/ )
548
+ pos ++ ;
549
+ ch = commentWhitespace ( ) ;
550
+ // match next if
551
+ if ( ch === 105 /*i*/ && source . charCodeAt ( pos + 1 ) === 102 /*f*/ ) {
552
+ pos += 2 ;
553
+ ch = commentWhitespace ( ) ;
554
+ if ( ch !== 40 /*(*/ ) break ;
555
+ pos ++ ;
556
+ }
557
+ else {
558
+ inIf = false ;
559
+ }
560
+ }
561
+ else {
562
+ pos = ifInnerPos ;
563
+ }
564
+
565
+ // IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
566
+ if ( inIf ) {
567
+ if ( ! source . startsWith ( it_id , pos ) ) break ;
568
+ pos += it_id . length ;
569
+ ch = commentWhitespace ( ) ;
570
+ if ( ch !== 105 /*i*/ || ! source . startsWith ( 'n ' , pos + 1 ) ) break ;
571
+ pos += 3 ;
572
+ ch = commentWhitespace ( ) ;
573
+ if ( ! readExportsOrModuleDotExports ( ch ) ) break ;
574
+ ch = commentWhitespace ( ) ;
575
+ if ( ch !== 38 /*&*/ || source . charCodeAt ( pos + 1 ) !== 38 /*&*/ ) break ;
576
+ pos += 2 ;
577
+ ch = commentWhitespace ( ) ;
578
+ if ( ! readExportsOrModuleDotExports ( ch ) ) break ;
579
+ ch = commentWhitespace ( ) ;
580
+ if ( ch !== 91 /*[*/ ) break ;
581
+ pos ++ ;
582
+ ch = commentWhitespace ( ) ;
583
+ if ( ! source . startsWith ( it_id , pos ) ) break ;
584
+ pos += it_id . length ;
585
+ ch = commentWhitespace ( ) ;
586
+ if ( ch !== 93 /*]*/ ) break ;
587
+ pos ++ ;
588
+ ch = commentWhitespace ( ) ;
589
+ if ( ch !== 61 /*=*/ || ! source . startsWith ( '==' , pos + 1 ) ) break ;
590
+ pos += 3 ;
591
+ ch = commentWhitespace ( ) ;
592
+ if ( ! source . startsWith ( id , pos ) ) break ;
593
+ pos += id . length ;
594
+ ch = commentWhitespace ( ) ;
595
+ if ( ch !== 91 /*[*/ ) break ;
596
+ pos ++ ;
597
+ ch = commentWhitespace ( ) ;
598
+ if ( ! source . startsWith ( it_id , pos ) ) break ;
599
+ pos += it_id . length ;
600
+ ch = commentWhitespace ( ) ;
601
+ if ( ch !== 93 /*]*/ ) break ;
602
+ pos ++ ;
603
+ ch = commentWhitespace ( ) ;
604
+ if ( ch !== 41 /*)*/ ) break ;
605
+ pos ++ ;
606
+ ch = commentWhitespace ( ) ;
607
+ if ( ch !== 114 /*r*/ || ! source . startsWith ( 'eturn' , pos + 1 ) ) break ;
608
+ pos += 6 ;
609
+ ch = commentWhitespace ( ) ;
610
+ if ( ch === 59 /*;*/ )
611
+ pos ++ ;
612
+ ch = commentWhitespace ( ) ;
613
+ }
614
+ }
472
615
}
473
- // `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) `)`
616
+ // `if (` IDENTIFIER$2 `!==` ( `'default'` | `"default"` ) (`&& !` IDENTIFIER `.hasOwnProperty(` IDENTIFIER$2 `)` )? `)`
474
617
else if ( ch === 33 /*!*/ ) {
475
618
if ( ! source . startsWith ( '==' , pos + 1 ) ) break ;
476
619
pos += 3 ;
@@ -483,67 +626,40 @@ function tryParseObjectDefineOrKeys (keys) {
483
626
if ( ch !== quot ) break ;
484
627
pos += 1 ;
485
628
ch = commentWhitespace ( ) ;
629
+ if ( ch === 38 /*&*/ ) {
630
+ if ( source . charCodeAt ( pos + 1 ) !== 38 /*&*/ ) break ;
631
+ pos += 2 ;
632
+ ch = commentWhitespace ( ) ;
633
+ if ( ch !== 33 /*!*/ ) break ;
634
+ pos += 1 ;
635
+ ch = commentWhitespace ( ) ;
636
+ if ( source . startsWith ( id , pos ) ) {
637
+ pos += id . length ;
638
+ ch = commentWhitespace ( ) ;
639
+ if ( ch !== 46 /*.*/ ) break ;
640
+ pos ++ ;
641
+ ch = commentWhitespace ( ) ;
642
+ if ( ch !== 104 /*h*/ || ! source . startsWith ( 'asOwnProperty' , pos + 1 ) ) break ;
643
+ pos += 14 ;
644
+ ch = commentWhitespace ( ) ;
645
+ if ( ch !== 40 /*(*/ ) break ;
646
+ pos += 1 ;
647
+ ch = commentWhitespace ( ) ;
648
+ if ( ! source . startsWith ( it_id , pos ) ) break ;
649
+ pos += it_id . length ;
650
+ ch = commentWhitespace ( ) ;
651
+ if ( ch !== 41 /*)*/ ) break ;
652
+ pos += 1 ;
653
+ }
654
+ else if ( ! tryParseObjectHasOwnProperty ( it_id ) ) break ;
655
+ ch = commentWhitespace ( ) ;
656
+ }
486
657
if ( ch !== 41 /*)*/ ) break ;
487
658
pos += 1 ;
488
659
ch = commentWhitespace ( ) ;
489
660
}
490
661
else break ;
491
662
492
- // `if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
493
- if ( ch === 105 /*i*/ && source . charCodeAt ( pos + 1 ) === 102 /*f*/ ) {
494
- pos += 2 ;
495
- ch = commentWhitespace ( ) ;
496
- if ( ch !== 40 /*(*/ ) break ;
497
- pos ++ ;
498
- ch = commentWhitespace ( ) ;
499
- if ( ! source . startsWith ( it_id , pos ) ) break ;
500
- pos += it_id . length ;
501
- ch = commentWhitespace ( ) ;
502
- if ( ch !== 105 /*i*/ || ! source . startsWith ( 'n ' , pos + 1 ) ) break ;
503
- pos += 3 ;
504
- ch = commentWhitespace ( ) ;
505
- if ( ! readExportsOrModuleDotExports ( ch ) ) break ;
506
- ch = commentWhitespace ( ) ;
507
- if ( ch !== 38 /*&*/ || source . charCodeAt ( pos + 1 ) !== 38 /*&*/ ) break ;
508
- pos += 2 ;
509
- ch = commentWhitespace ( ) ;
510
- if ( ! readExportsOrModuleDotExports ( ch ) ) break ;
511
- ch = commentWhitespace ( ) ;
512
- if ( ch !== 91 /*[*/ ) break ;
513
- pos ++ ;
514
- ch = commentWhitespace ( ) ;
515
- if ( ! source . startsWith ( it_id , pos ) ) break ;
516
- pos += it_id . length ;
517
- ch = commentWhitespace ( ) ;
518
- if ( ch !== 93 /*]*/ ) break ;
519
- pos ++ ;
520
- ch = commentWhitespace ( ) ;
521
- if ( ch !== 61 /*=*/ || ! source . startsWith ( '==' , pos + 1 ) ) break ;
522
- pos += 3 ;
523
- ch = commentWhitespace ( ) ;
524
- if ( ! source . startsWith ( id , pos ) ) break ;
525
- pos += id . length ;
526
- ch = commentWhitespace ( ) ;
527
- if ( ch !== 91 /*[*/ ) break ;
528
- pos ++ ;
529
- ch = commentWhitespace ( ) ;
530
- if ( ! source . startsWith ( it_id , pos ) ) break ;
531
- pos += it_id . length ;
532
- ch = commentWhitespace ( ) ;
533
- if ( ch !== 93 /*]*/ ) break ;
534
- pos ++ ;
535
- ch = commentWhitespace ( ) ;
536
- if ( ch !== 41 /*)*/ ) break ;
537
- pos ++ ;
538
- ch = commentWhitespace ( ) ;
539
- if ( ch !== 114 /*r*/ || ! source . startsWith ( 'eturn' , pos + 1 ) ) break ;
540
- pos += 6 ;
541
- ch = commentWhitespace ( ) ;
542
- if ( ch === 59 /*;*/ )
543
- pos ++ ;
544
- ch = commentWhitespace ( ) ;
545
- }
546
-
547
663
// EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]`
548
664
if ( readExportsOrModuleDotExports ( ch ) ) {
549
665
ch = commentWhitespace ( ) ;
@@ -619,12 +735,17 @@ function tryParseObjectDefineOrKeys (keys) {
619
735
if ( ch !== 103 /*g*/ || ! source . startsWith ( 'et' , pos + 1 ) ) break ;
620
736
pos += 3 ;
621
737
ch = commentWhitespace ( ) ;
622
- if ( ch !== 58 /*:*/ ) break ;
623
- pos ++ ;
624
- ch = commentWhitespace ( ) ;
625
- if ( ch !== 102 /*f*/ || ! source . startsWith ( 'unction' , pos + 1 ) ) break ;
626
- pos += 8 ;
627
- ch = commentWhitespace ( ) ;
738
+ if ( ch === 58 /*:*/ ) {
739
+ pos ++ ;
740
+ ch = commentWhitespace ( ) ;
741
+ if ( ch !== 102 /*f*/ ) break ;
742
+ if ( ! source . startsWith ( 'unction' , pos + 1 ) ) break ;
743
+ pos += 8 ;
744
+ let lastPos = pos ;
745
+ ch = commentWhitespace ( ) ;
746
+ if ( ch !== 40 && ( lastPos === pos || ! identifier ( ) ) ) break ;
747
+ ch = commentWhitespace ( ) ;
748
+ }
628
749
if ( ch !== 40 /*(*/ ) break ;
629
750
pos ++ ;
630
751
ch = commentWhitespace ( ) ;
@@ -656,6 +777,10 @@ function tryParseObjectDefineOrKeys (keys) {
656
777
if ( ch !== 125 /*}*/ ) break ;
657
778
pos ++ ;
658
779
ch = commentWhitespace ( ) ;
780
+ if ( ch === 44 /*,*/ ) {
781
+ pos ++ ;
782
+ ch = commentWhitespace ( ) ;
783
+ }
659
784
if ( ch !== 125 /*}*/ ) break ;
660
785
pos ++ ;
661
786
ch = commentWhitespace ( ) ;
@@ -1039,7 +1164,6 @@ function throwIfImportStatement () {
1039
1164
// import.meta
1040
1165
case 46 /*.*/ :
1041
1166
throw new Error ( 'Unexpected import.meta in CJS module.' ) ;
1042
- return ;
1043
1167
1044
1168
default :
1045
1169
// no space after "import" -> not an import keyword
0 commit comments