@@ -694,6 +694,11 @@ export class Parser {
694694 expr = this . parseClassExpression ( ) ;
695695 } else if ( this . matchImportCall ( ) ) {
696696 expr = this . parseImportCall ( ) ;
697+ } else if ( this . matchImportMeta ( ) ) {
698+ if ( ! this . context . isModule ) {
699+ this . tolerateUnexpectedToken ( this . lookahead , Messages . CannotUseImportMetaOutsideAModule ) ;
700+ }
701+ expr = this . parseImportMeta ( ) ;
697702 } else {
698703 expr = this . throwUnexpectedToken ( this . nextToken ( ) ) ;
699704 }
@@ -1285,6 +1290,39 @@ export class Parser {
12851290 return this . finalize ( node , new Node . Import ( ) ) ;
12861291 }
12871292
1293+ matchImportMeta ( ) : boolean {
1294+ let match = this . matchKeyword ( 'import' ) ;
1295+ if ( match ) {
1296+ const state = this . scanner . saveState ( ) ;
1297+ this . scanner . scanComments ( ) ;
1298+ const dot = this . scanner . lex ( ) ;
1299+ if ( ( dot . type === Token . Punctuator ) && ( dot . value === '.' ) ) {
1300+ this . scanner . scanComments ( ) ;
1301+ const meta = this . scanner . lex ( ) ;
1302+ match = ( meta . type === Token . Identifier ) && ( meta . value === 'meta' ) ;
1303+ if ( match ) {
1304+ if ( meta . end - meta . start !== 'meta' . length ) {
1305+ this . tolerateUnexpectedToken ( meta , Messages . InvalidEscapedReservedWord ) ;
1306+ }
1307+ }
1308+ } else {
1309+ match = false ;
1310+ }
1311+ this . scanner . restoreState ( state ) ;
1312+ }
1313+
1314+ return match ;
1315+ }
1316+
1317+ parseImportMeta ( ) : Node . MetaProperty {
1318+ const node = this . createNode ( ) ;
1319+ const id = this . parseIdentifierName ( ) ; // 'import', already ensured by matchImportMeta
1320+ this . expect ( '.' ) ;
1321+ const property = this . parseIdentifierName ( ) ; // 'meta', already ensured by matchImportMeta
1322+ this . context . isAssignmentTarget = false ;
1323+ return this . finalize ( node , new Node . MetaProperty ( id , property ) ) ;
1324+ }
1325+
12881326 parseLeftHandSideExpressionAllowCall ( ) : Node . Expression {
12891327 const startToken = this . lookahead ;
12901328 const maybeAsync = this . matchContextualKeyword ( 'async' ) ;
@@ -1897,6 +1935,8 @@ export class Parser {
18971935 case 'import' :
18981936 if ( this . matchImportCall ( ) ) {
18991937 statement = this . parseExpressionStatement ( ) ;
1938+ } else if ( this . matchImportMeta ( ) ) {
1939+ statement = this . parseStatement ( ) ;
19001940 } else {
19011941 if ( ! this . context . isModule ) {
19021942 this . tolerateUnexpectedToken ( this . lookahead , Messages . IllegalImportDeclaration ) ;
0 commit comments