@@ -427,10 +427,18 @@ pp.parseExprAtom = function(refDestructuringErrors) {
427
427
428
428
pp . parseExprImport = function ( ) {
429
429
const node = this . startNode ( )
430
- this . next ( ) // skip `import`
430
+
431
+ // Consume `import` as an identifier for `import.meta`.
432
+ // Because `this.parseIdent(true)` doesn't check escape sequences, it needs the check of `this.containsEsc`.
433
+ if ( this . containsEsc ) this . raiseRecoverable ( this . start , "Escape sequence in keyword import" )
434
+ const meta = this . parseIdent ( true )
435
+
431
436
switch ( this . type ) {
432
437
case tt . parenL :
433
438
return this . parseDynamicImport ( node )
439
+ case tt . dot :
440
+ node . meta = meta
441
+ return this . parseImportMeta ( node )
434
442
default :
435
443
this . unexpected ( )
436
444
}
@@ -455,6 +463,22 @@ pp.parseDynamicImport = function(node) {
455
463
return this . finishNode ( node , "ImportExpression" )
456
464
}
457
465
466
+ pp . parseImportMeta = function ( node ) {
467
+ this . next ( ) // skip `.`
468
+
469
+ const containsEsc = this . containsEsc
470
+ node . property = this . parseIdent ( true )
471
+
472
+ if ( node . property . name !== "meta" )
473
+ this . raiseRecoverable ( node . property . start , "The only valid meta property for import is 'import.meta'" )
474
+ if ( containsEsc )
475
+ this . raiseRecoverable ( node . start , "'import.meta' must not contain escaped characters" )
476
+ if ( this . options . sourceType !== "module" )
477
+ this . raiseRecoverable ( node . start , "Cannot use 'import.meta' outside a module" )
478
+
479
+ return this . finishNode ( node , "MetaProperty" )
480
+ }
481
+
458
482
pp . parseLiteral = function ( value ) {
459
483
let node = this . startNode ( )
460
484
node . value = value
@@ -557,10 +581,12 @@ pp.parseNew = function() {
557
581
node . meta = meta
558
582
let containsEsc = this . containsEsc
559
583
node . property = this . parseIdent ( true )
560
- if ( node . property . name !== "target" || containsEsc )
561
- this . raiseRecoverable ( node . property . start , "The only valid meta property for new is new.target" )
584
+ if ( node . property . name !== "target" )
585
+ this . raiseRecoverable ( node . property . start , "The only valid meta property for new is 'new.target'" )
586
+ if ( containsEsc )
587
+ this . raiseRecoverable ( node . start , "'new.target' must not contain escaped characters" )
562
588
if ( ! this . inNonArrowFunction ( ) )
563
- this . raiseRecoverable ( node . start , "new.target can only be used in functions" )
589
+ this . raiseRecoverable ( node . start , "' new.target' can only be used in functions" )
564
590
return this . finishNode ( node , "MetaProperty" )
565
591
}
566
592
let startPos = this . start , startLoc = this . startLoc , isImport = this . type === tt . _import
0 commit comments