mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-15 03:23:08 -06:00
Added an explanation for the lookahead.
This commit is contained in:
parent
3cd480ddb6
commit
3fe308d2a6
@ -3973,7 +3973,7 @@ module ts {
|
||||
case SyntaxKind.ThrowKeyword:
|
||||
return parseThrowStatement();
|
||||
case SyntaxKind.TryKeyword:
|
||||
// Include the next two for error recovery.
|
||||
// Include 'catch' and 'finally' for error recovery.
|
||||
case SyntaxKind.CatchKeyword:
|
||||
case SyntaxKind.FinallyKeyword:
|
||||
return parseTryStatement();
|
||||
@ -3981,6 +3981,33 @@ module ts {
|
||||
return parseDebuggerStatement();
|
||||
case SyntaxKind.AtToken:
|
||||
return parseDeclaration();
|
||||
|
||||
case SyntaxKind.ConstKeyword:
|
||||
case SyntaxKind.EnumKeyword:
|
||||
case SyntaxKind.ExportKeyword:
|
||||
case SyntaxKind.ImportKeyword:
|
||||
case SyntaxKind.InterfaceKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.StaticKeyword:
|
||||
if (getDeclarationFlags() & flags) {
|
||||
return parseDeclaration();
|
||||
}
|
||||
break;
|
||||
|
||||
// 'declare', 'module', 'namespace', and 'type' are all legal JavaScript identifiers when ASI
|
||||
// takes effect. In such cases, we cannot parse out the "expected" declarations. For instance, while
|
||||
//
|
||||
// namespace n
|
||||
//
|
||||
// can be none other than the beginning of a namespace declaration, JavaScript sees
|
||||
//
|
||||
// namespace
|
||||
// n
|
||||
//
|
||||
// as the identifier 'namespace' on one line followed by the identifier 'n' on another.
|
||||
// We need to look one token ahead to see if it permissible to try parsing a declaration.
|
||||
case SyntaxKind.DeclareKeyword:
|
||||
if (lookAhead(isFollowedByIdentifierOrKeywordOnSameLine) && getDeclarationFlags() & flags) {
|
||||
return parseDeclaration();
|
||||
@ -3997,19 +4024,6 @@ module ts {
|
||||
return parseDeclaration();
|
||||
}
|
||||
break;
|
||||
case SyntaxKind.ConstKeyword:
|
||||
case SyntaxKind.EnumKeyword:
|
||||
case SyntaxKind.ExportKeyword:
|
||||
case SyntaxKind.ImportKeyword:
|
||||
case SyntaxKind.InterfaceKeyword:
|
||||
case SyntaxKind.PrivateKeyword:
|
||||
case SyntaxKind.ProtectedKeyword:
|
||||
case SyntaxKind.PublicKeyword:
|
||||
case SyntaxKind.StaticKeyword:
|
||||
if (getDeclarationFlags() & flags) {
|
||||
return parseDeclaration();
|
||||
}
|
||||
break;
|
||||
}
|
||||
return parseExpressionOrLabeledStatement();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user