@@ -2783,7 +2783,7 @@ protected Statement parseBreakContinueStatement(Position startLoc, String keywor
2783
2783
boolean isBreak = keyword .equals ("break" );
2784
2784
this .next ();
2785
2785
Identifier label = null ;
2786
- if (this .eat ( TokenType . semi ) || this . insertSemicolon ()) {
2786
+ if (this .eagerlyTrySemicolon ()) {
2787
2787
label = null ;
2788
2788
} else if (this .type != TokenType .name ) {
2789
2789
this .unexpected ();
@@ -2893,6 +2893,15 @@ protected Statement parseIfStatement(Position startLoc) {
2893
2893
new IfStatement (new SourceLocation (startLoc ), test , consequent , alternate ));
2894
2894
}
2895
2895
2896
+ /**
2897
+ * Consumes or inserts a semicolon if possible, and returns true if a semicolon was consumed or inserted.
2898
+ *
2899
+ * Returns false if there was no semicolon and insertion was not possible.
2900
+ */
2901
+ protected boolean eagerlyTrySemicolon () {
2902
+ return this .eat (TokenType .semi ) || this .insertSemicolon ();
2903
+ }
2904
+
2896
2905
protected ReturnStatement parseReturnStatement (Position startLoc ) {
2897
2906
if (!this .inFunction && !this .options .allowReturnOutsideFunction ())
2898
2907
this .raise (this .start , "'return' outside of function" );
@@ -2902,7 +2911,7 @@ protected ReturnStatement parseReturnStatement(Position startLoc) {
2902
2911
// optional arguments, we eagerly look for a semicolon or the
2903
2912
// possibility to insert one.
2904
2913
Expression argument ;
2905
- if (this .eat ( TokenType . semi ) || this . insertSemicolon ()) {
2914
+ if (this .eagerlyTrySemicolon ()) {
2906
2915
argument = null ;
2907
2916
} else {
2908
2917
argument = this .parseExpression (false , null );
@@ -3404,6 +3413,7 @@ protected ExportDeclaration parseExportRest(SourceLocation loc, Set<String> expo
3404
3413
Statement declaration ;
3405
3414
List <ExportSpecifier > specifiers ;
3406
3415
Expression source = null ;
3416
+ Expression assertion = null ;
3407
3417
if (this .shouldParseExportStatement ()) {
3408
3418
declaration = this .parseStatement (true , false );
3409
3419
if (declaration == null ) return null ;
@@ -3419,11 +3429,13 @@ protected ExportDeclaration parseExportRest(SourceLocation loc, Set<String> expo
3419
3429
declaration = null ;
3420
3430
specifiers = this .parseExportSpecifiers (exports );
3421
3431
source = parseExportFrom (specifiers , source , false );
3432
+ assertion = parseImportOrExportAssertionAndSemicolon (); // TODO: store in AST
3422
3433
}
3423
3434
return this .finishNode (
3424
3435
new ExportNamedDeclaration (loc , declaration , specifiers , (Literal ) source ));
3425
3436
}
3426
3437
3438
+ /** Parses the 'from' clause of an export, not including the assertion or semicolon. */
3427
3439
protected Expression parseExportFrom (
3428
3440
List <ExportSpecifier > specifiers , Expression source , boolean expectFrom ) {
3429
3441
if (this .eatContextual ("from" )) {
@@ -3442,13 +3454,13 @@ protected Expression parseExportFrom(
3442
3454
3443
3455
source = null ;
3444
3456
}
3445
- this .semicolon ();
3446
3457
return source ;
3447
3458
}
3448
3459
3449
3460
protected ExportDeclaration parseExportAll (
3450
3461
SourceLocation loc , Position starLoc , Set <String > exports ) {
3451
3462
Expression source = parseExportFrom (null , null , true );
3463
+ Expression assertion = parseImportOrExportAssertionAndSemicolon (); // TODO: store in AST
3452
3464
return this .finishNode (new ExportAllDeclaration (loc , (Literal ) source ));
3453
3465
}
3454
3466
@@ -3514,6 +3526,16 @@ protected Statement parseImport(Position startLoc) {
3514
3526
return parseImportRest (loc );
3515
3527
}
3516
3528
3529
+ protected Expression parseImportOrExportAssertionAndSemicolon () {
3530
+ Expression result = null ;
3531
+ if (!this .eagerlyTrySemicolon ()) {
3532
+ this .expectContextual ("assert" );
3533
+ result = this .parseObj (false , null );
3534
+ this .semicolon ();
3535
+ }
3536
+ return result ;
3537
+ }
3538
+
3517
3539
protected ImportDeclaration parseImportRest (SourceLocation loc ) {
3518
3540
List <ImportSpecifier > specifiers ;
3519
3541
Literal source ;
@@ -3527,7 +3549,7 @@ protected ImportDeclaration parseImportRest(SourceLocation loc) {
3527
3549
if (this .type != TokenType .string ) this .unexpected ();
3528
3550
source = (Literal ) this .parseExprAtom (null );
3529
3551
}
3530
- this .semicolon ();
3552
+ Expression assertion = this .parseImportOrExportAssertionAndSemicolon (); // TODO: store in AST
3531
3553
if (specifiers == null ) return null ;
3532
3554
return this .finishNode (new ImportDeclaration (loc , specifiers , source ));
3533
3555
}
0 commit comments