@@ -1414,11 +1414,11 @@ namespace ts {
14141414 case SyntaxKind . ExportKeyword :
14151415 nextToken ( ) ;
14161416 if ( token ( ) === SyntaxKind . DefaultKeyword ) {
1417- return lookAhead ( nextTokenCanFollowDefaultKeyword ) ;
1417+ return lookAhead ( nextTokenCanFollowDefaultModifier ) ;
14181418 }
14191419 return token ( ) !== SyntaxKind . AsteriskToken && token ( ) !== SyntaxKind . AsKeyword && token ( ) !== SyntaxKind . OpenBraceToken && canFollowModifier ( ) ;
14201420 case SyntaxKind . DefaultKeyword :
1421- return nextTokenCanFollowDefaultKeyword ( ) ;
1421+ return nextTokenCanFollowDefaultModifier ( ) ;
14221422 case SyntaxKind . StaticKeyword :
14231423 case SyntaxKind . GetKeyword :
14241424 case SyntaxKind . SetKeyword :
@@ -1441,12 +1441,37 @@ namespace ts {
14411441 || isLiteralPropertyName ( ) ;
14421442 }
14431443
1444- function nextTokenCanFollowDefaultKeyword ( ) : boolean {
1444+ /**
1445+ * For export default assignments like
1446+ * "export default foo"
1447+ * "export default async"
1448+ * no modifiers should be parsed.
1449+ */
1450+ function nextTokenCanFollowDefaultModifier ( ) : boolean {
14451451 nextToken ( ) ;
1446- return token ( ) === SyntaxKind . ClassKeyword || token ( ) === SyntaxKind . FunctionKeyword ||
1447- token ( ) === SyntaxKind . InterfaceKeyword ||
1448- ( token ( ) === SyntaxKind . AbstractKeyword && lookAhead ( nextTokenIsClassKeywordOnSameLine ) ) ||
1449- ( token ( ) === SyntaxKind . AsyncKeyword && lookAhead ( nextTokenIsFunctionKeywordOnSameLine ) ) ;
1452+ switch ( token ( ) ) {
1453+ case SyntaxKind . ClassKeyword :
1454+ case SyntaxKind . FunctionKeyword :
1455+ case SyntaxKind . EnumKeyword :
1456+ case SyntaxKind . NamespaceKeyword :
1457+ case SyntaxKind . ModuleKeyword :
1458+ case SyntaxKind . ConstKeyword :
1459+ return true ;
1460+
1461+ // The following keywords aren't reserved keywords and could be identifiers.
1462+ // We need to look at the next token to make sure these should be parsed as a modifier keyword,
1463+ // and not as an identifier. If they are followed by an identifier or a keyword on the same line,
1464+ // the current statement is not an export default assignment.
1465+ // See https://github.com/Microsoft/TypeScript/blob/master/doc/spec.md#221-reserved-words
1466+ case SyntaxKind . InterfaceKeyword :
1467+ case SyntaxKind . AbstractKeyword :
1468+ case SyntaxKind . DeclareKeyword :
1469+ case SyntaxKind . AsyncKeyword :
1470+ case SyntaxKind . TypeKeyword :
1471+ return lookAhead ( nextTokenIsIdentifierOrKeywordOnSameLine ) ;
1472+ default :
1473+ return false ;
1474+ }
14501475 }
14511476
14521477 // True if positioned at the start of a list element
@@ -4081,14 +4106,14 @@ namespace ts {
40814106 let expression : MemberExpression ;
40824107 if ( token ( ) === SyntaxKind . ImportKeyword ) {
40834108 if ( lookAhead ( nextTokenIsOpenParenOrLessThan ) ) {
4084- // We don't want to eagerly consume all import keyword as import call expression so we look ahead to find "("
4085- // For example:
4086- // var foo3 = require("subfolder
4087- // import * as foo1 from "module-from-node
4088- // We want this import to be a statement rather than import call expression
4089- sourceFile . flags |= NodeFlags . PossiblyContainsDynamicImport ;
4090- expression = parseTokenNode < PrimaryExpression > ( ) ;
4091- }
4109+ // We don't want to eagerly consume all import keyword as import call expression so we look a head to find "("
4110+ // For example:
4111+ // var foo3 = require("subfolder
4112+ // import * as foo1 from "module-from-node
4113+ // We want this import to be a statement rather than import call expression
4114+ sourceFile . flags |= NodeFlags . PossiblyContainsDynamicImport ;
4115+ expression = parseTokenNode < PrimaryExpression > ( ) ;
4116+ }
40924117 else if ( lookAhead ( nextTokenIsDot ) ) {
40934118 // This is an 'import.*' metaproperty (i.e. 'import.meta')
40944119 const fullStart = scanner . getStartPos ( ) ;
@@ -4101,7 +4126,7 @@ namespace ts {
41014126
41024127 sourceFile . flags |= NodeFlags . PossiblyContainsImportMeta ;
41034128 }
4104- else {
4129+ else {
41054130 expression = parseMemberExpressionOrHigher ( ) ;
41064131 }
41074132 }
@@ -5118,11 +5143,6 @@ namespace ts {
51185143 return tokenIsIdentifierOrKeyword ( token ( ) ) && ! scanner . hasPrecedingLineBreak ( ) ;
51195144 }
51205145
5121- function nextTokenIsClassKeywordOnSameLine ( ) {
5122- nextToken ( ) ;
5123- return token ( ) === SyntaxKind . ClassKeyword && ! scanner . hasPrecedingLineBreak ( ) ;
5124- }
5125-
51265146 function nextTokenIsFunctionKeywordOnSameLine ( ) {
51275147 nextToken ( ) ;
51285148 return token ( ) === SyntaxKind . FunctionKeyword && ! scanner . hasPrecedingLineBreak ( ) ;
@@ -6233,7 +6253,7 @@ namespace ts {
62336253 sourceFile . externalModuleIndicator =
62346254 forEach ( sourceFile . statements , isAnExternalModuleIndicatorNode ) ||
62356255 getImportMetaIfNecessary ( sourceFile ) ;
6236- }
6256+ }
62376257
62386258 function isAnExternalModuleIndicatorNode ( node : Node ) {
62396259 return hasModifier ( node , ModifierFlags . Export )
@@ -6243,17 +6263,17 @@ namespace ts {
62436263 || node . kind === SyntaxKind . ExportDeclaration
62446264 ? node
62456265 : undefined ;
6246- }
6266+ }
62476267
62486268 function getImportMetaIfNecessary ( sourceFile : SourceFile ) {
62496269 return sourceFile . flags & NodeFlags . PossiblyContainsImportMeta ?
62506270 walkTreeForExternalModuleIndicators ( sourceFile ) :
62516271 undefined ;
6252- }
6272+ }
62536273
62546274 function walkTreeForExternalModuleIndicators ( node : Node ) : Node | undefined {
62556275 return isImportMeta ( node ) ? node : forEachChild ( node , walkTreeForExternalModuleIndicators ) ;
6256- }
6276+ }
62576277
62586278 function isImportMeta ( node : Node ) : boolean {
62596279 return isMetaProperty ( node ) && node . keywordToken === SyntaxKind . ImportKeyword && node . name . escapedText === "meta" ;
@@ -6468,7 +6488,7 @@ namespace ts {
64686488 break ;
64696489 }
64706490 nextJSDocToken ( ) ;
6471- }
6491+ }
64726492 removeLeadingNewlines ( comments ) ;
64736493 removeTrailingWhitespace ( comments ) ;
64746494 return createJSDocComment ( ) ;
0 commit comments