diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index ca3f0c25e4d..3641912e76e 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -3677,17 +3677,25 @@ namespace ts { // CallExpression Arguments // CallExpression[Expression] // CallExpression.IdentifierName - // super ( ArgumentListopt ) + // import (AssignmentExpression) + // super Arguments // super.IdentifierName // - // Because of the recursion in these calls, we need to bottom out first. There are two - // bottom out states we can run into. Either we see 'super' which must start either of - // the last two CallExpression productions. Or we have a MemberExpression which either - // completes the LeftHandSideExpression, or starts the beginning of the first four - // CallExpression productions. - const expression = token() === SyntaxKind.SuperKeyword - ? parseSuperExpression() - : parseMemberExpressionOrHigher(); + // Because of the recursion in these calls, we need to bottom out first. There are three + // bottom out states we can run into: 1) We see 'super' which must start either of + // the last two CallExpression productions. 2) We see 'import' which must start import call. + // 3)we have a MemberExpression which either completes the LeftHandSideExpression, + // or starts the beginning of the first four CallExpression productions. + let expression: MemberExpression; + if (token() === SyntaxKind.SuperKeyword) { + expression = parseSuperExpression(); + } + else if (token() === SyntaxKind.ImportKeyword) { + expression = parseImportExpression(); + } + else { + expression = parseMemberExpressionOrHigher(); + } // Now, we *may* be complete. However, we might have consumed the start of a // CallExpression. As such, we need to consume the rest of it here to be complete. @@ -3695,7 +3703,7 @@ namespace ts { } function parseMemberExpressionOrHigher(): MemberExpression { - // Note: to make our lives simpler, we decompose the the NewExpression productions and + // Note: to make our lives simpler, we decompose the NewExpression productions and // place ObjectCreationExpression and FunctionExpression into PrimaryExpression. // like so: // @@ -3761,6 +3769,14 @@ namespace ts { return finishNode(node); } + function parseImportExpression(): MemberExpression { + const expression = parseTokenNode(); + if (token() === SyntaxKind.OpenParenToken) { + return expression; + } + // (TODO(yuisu): Error Handling here + } + function tagNamesAreEquivalent(lhs: JsxTagNameExpression, rhs: JsxTagNameExpression): boolean { if (lhs.kind !== rhs.kind) { return false; diff --git a/src/compiler/types.ts b/src/compiler/types.ts index f0a26fbf996..335ff99453e 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -1043,6 +1043,10 @@ namespace ts { kind: SyntaxKind.SuperKeyword; } + export interface ImportExpression extends PrimaryExpression { + kind: SyntaxKind.ImportKeyword + } + export interface DeleteExpression extends UnaryExpression { kind: SyntaxKind.DeleteExpression; expression: UnaryExpression; @@ -1425,10 +1429,7 @@ namespace ts { } // see: https://tc39.github.io/ecma262/#prod-SuperProperty - export type SuperProperty - = SuperPropertyAccessExpression - | SuperElementAccessExpression - ; + export type SuperProperty = SuperPropertyAccessExpression | SuperElementAccessExpression; export interface CallExpression extends LeftHandSideExpression, Declaration { kind: SyntaxKind.CallExpression; @@ -1442,6 +1443,10 @@ namespace ts { expression: SuperExpression; } + export interface ImportCall extends CallExpression { + expression: ImportExpression; + } + export interface ExpressionWithTypeArguments extends TypeNode { kind: SyntaxKind.ExpressionWithTypeArguments; parent?: HeritageClause;