@@ -10,7 +10,6 @@ let openTokenDepth,
10
10
nextBraceIsClass ,
11
11
starExportMap ,
12
12
lastStarExportSpecifier ,
13
- lastExportsAssignSpecifier ,
14
13
_exports ,
15
14
reexports ;
16
15
@@ -26,7 +25,6 @@ function resetState () {
26
25
nextBraceIsClass = false ;
27
26
starExportMap = Object . create ( null ) ;
28
27
lastStarExportSpecifier = null ;
29
- lastExportsAssignSpecifier = null ;
30
28
31
29
_exports = new Set ( ) ;
32
30
reexports = new Set ( ) ;
@@ -49,8 +47,6 @@ module.exports = function parseCJS (source, name = '@') {
49
47
e . loc = pos ;
50
48
throw e ;
51
49
}
52
- if ( lastExportsAssignSpecifier )
53
- reexports . add ( lastExportsAssignSpecifier ) ;
54
50
const result = { exports : [ ..._exports ] , reexports : [ ...reexports ] } ;
55
51
resetState ( ) ;
56
52
return result ;
@@ -330,8 +326,8 @@ function tryParseObjectDefineOrKeys (keys) {
330
326
if ( ch !== 123 /*{*/ ) break ;
331
327
pos ++ ;
332
328
ch = commentWhitespace ( ) ;
333
- if ( ch !== 105 /*i*/ || ! source . startsWith ( 'f ' , pos + 1 ) ) break ;
334
- pos += 3 ;
329
+ if ( ch !== 105 /*i*/ || source . charCodeAt ( pos + 1 ) !== 102 /*f*/ ) break ;
330
+ pos += 2 ;
335
331
ch = commentWhitespace ( ) ;
336
332
if ( ch !== 40 /*(*/ ) break ;
337
333
pos ++ ;
@@ -398,6 +394,61 @@ function tryParseObjectDefineOrKeys (keys) {
398
394
}
399
395
else break ;
400
396
397
+ // `if (` IDENTIFIER$2 `in` EXPORTS_IDENTIFIER `&&` EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] ===` IDENTIFIER$1 `[` IDENTIFIER$2 `]) return` `;`?
398
+ if ( ch === 105 /*i*/ && source . charCodeAt ( pos + 1 ) === 102 /*f*/ ) {
399
+ pos += 2 ;
400
+ ch = commentWhitespace ( ) ;
401
+ if ( ch !== 40 /*(*/ ) break ;
402
+ pos ++ ;
403
+ ch = commentWhitespace ( ) ;
404
+ if ( ! source . startsWith ( it_id , pos ) ) break ;
405
+ pos += it_id . length ;
406
+ ch = commentWhitespace ( ) ;
407
+ if ( ch !== 105 /*i*/ || ! source . startsWith ( 'n ' , pos + 1 ) ) break ;
408
+ pos += 3 ;
409
+ ch = commentWhitespace ( ) ;
410
+ if ( ! readExportsOrModuleDotExports ( ch ) ) break ;
411
+ ch = commentWhitespace ( ) ;
412
+ if ( ch !== 38 /*&*/ || source . charCodeAt ( pos + 1 ) !== 38 /*&*/ ) break ;
413
+ pos += 2 ;
414
+ ch = commentWhitespace ( ) ;
415
+ if ( ! readExportsOrModuleDotExports ( ch ) ) break ;
416
+ ch = commentWhitespace ( ) ;
417
+ if ( ch !== 91 /*[*/ ) break ;
418
+ pos ++ ;
419
+ ch = commentWhitespace ( ) ;
420
+ if ( ! source . startsWith ( it_id , pos ) ) break ;
421
+ pos += it_id . length ;
422
+ ch = commentWhitespace ( ) ;
423
+ if ( ch !== 93 /*]*/ ) break ;
424
+ pos ++ ;
425
+ ch = commentWhitespace ( ) ;
426
+ if ( ch !== 61 /*=*/ || ! source . startsWith ( '==' , pos + 1 ) ) break ;
427
+ pos += 3 ;
428
+ ch = commentWhitespace ( ) ;
429
+ if ( ! source . startsWith ( id , pos ) ) break ;
430
+ pos += id . length ;
431
+ ch = commentWhitespace ( ) ;
432
+ if ( ch !== 91 /*[*/ ) break ;
433
+ pos ++ ;
434
+ ch = commentWhitespace ( ) ;
435
+ if ( ! source . startsWith ( it_id , pos ) ) break ;
436
+ pos += it_id . length ;
437
+ ch = commentWhitespace ( ) ;
438
+ if ( ch !== 93 /*]*/ ) break ;
439
+ pos ++ ;
440
+ ch = commentWhitespace ( ) ;
441
+ if ( ch !== 41 /*)*/ ) break ;
442
+ pos ++ ;
443
+ ch = commentWhitespace ( ) ;
444
+ if ( ch !== 114 /*r*/ || ! source . startsWith ( 'eturn' , pos + 1 ) ) break ;
445
+ pos += 6 ;
446
+ ch = commentWhitespace ( ) ;
447
+ if ( ch === 59 /*;*/ )
448
+ pos ++ ;
449
+ ch = commentWhitespace ( ) ;
450
+ }
451
+
401
452
// EXPORTS_IDENTIFIER `[` IDENTIFIER$2 `] =` IDENTIFIER$1 `[` IDENTIFIER$2 `]`
402
453
if ( readExportsOrModuleDotExports ( ch ) ) {
403
454
ch = commentWhitespace ( ) ;
@@ -622,6 +673,8 @@ function tryParseExportsDotAssign (assign) {
622
673
// module.exports =
623
674
case 61 /*=*/ : {
624
675
if ( assign ) {
676
+ if ( reexports . size )
677
+ reexports = new Set ( ) ;
625
678
pos ++ ;
626
679
ch = commentWhitespace ( ) ;
627
680
// { ... }
@@ -641,9 +694,9 @@ function tryParseExportsDotAssign (assign) {
641
694
642
695
function tryParseRequire ( requireType ) {
643
696
// require('...')
697
+ const revertPos = pos ;
644
698
if ( source . startsWith ( 'equire' , pos + 1 ) ) {
645
699
pos += 7 ;
646
- const revertPos = pos - 1 ;
647
700
let ch = commentWhitespace ( ) ;
648
701
if ( ch === 40 /*(*/ ) {
649
702
pos ++ ;
@@ -656,7 +709,7 @@ function tryParseRequire (requireType) {
656
709
if ( ch === 41 /*)*/ ) {
657
710
switch ( requireType ) {
658
711
case ExportAssign :
659
- lastExportsAssignSpecifier = source . slice ( reexportStart , reexportEnd ) ;
712
+ reexports . add ( source . slice ( reexportStart , reexportEnd ) ) ;
660
713
return true ;
661
714
case ExportStar :
662
715
reexports . add ( source . slice ( reexportStart , reexportEnd ) ) ;
@@ -674,7 +727,7 @@ function tryParseRequire (requireType) {
674
727
if ( ch === 41 /*)*/ ) {
675
728
switch ( requireType ) {
676
729
case ExportAssign :
677
- lastExportsAssignSpecifier = source . slice ( reexportStart , reexportEnd ) ;
730
+ reexports . add ( source . slice ( reexportStart , reexportEnd ) ) ;
678
731
return true ;
679
732
case ExportStar :
680
733
reexports . add ( source . slice ( reexportStart , reexportEnd ) ) ;
@@ -711,6 +764,17 @@ function tryParseLiteralExports () {
711
764
}
712
765
addExport ( source . slice ( startPos , endPos ) ) ;
713
766
}
767
+ else if ( ch === 46 /*.*/ && source . startsWith ( '..' , pos + 1 ) ) {
768
+ pos += 3 ;
769
+ if ( source . charCodeAt ( pos ) === 114 /*r*/ && tryParseRequire ( ExportAssign ) ) {
770
+ pos ++ ;
771
+ }
772
+ else if ( ! identifier ( ) ) {
773
+ pos = revertPos ;
774
+ return ;
775
+ }
776
+ ch = commentWhitespace ( ) ;
777
+ }
714
778
else if ( ch === 39 /*'*/ || ch === 34 /*"*/ ) {
715
779
const startPos = ++ pos ;
716
780
if ( identifier ( ) && source . charCodeAt ( pos ) === ch ) {
0 commit comments