@@ -3811,14 +3811,42 @@ module ts {
3811
3811
case SyntaxKind . ClassKeyword :
3812
3812
case SyntaxKind . EnumKeyword :
3813
3813
return StatementFlags . Statement ;
3814
+
3815
+ // 'declare', 'module', 'namespace', 'interface'* and 'type' are all legal JavaScript identifiers;
3816
+ // however, an identifier cannot be followed by another identifier on the same line. This is what we
3817
+ // count on to parse out the respective declarations. For instance, we exploit this to say that
3818
+ //
3819
+ // namespace n
3820
+ //
3821
+ // can be none other than the beginning of a namespace declaration, but need to respect that JavaScript sees
3822
+ //
3823
+ // namespace
3824
+ // n
3825
+ //
3826
+ // as the identifier 'namespace' on one line followed by the identifier 'n' on another.
3827
+ // We need to look one token ahead to see if it permissible to try parsing a declaration.
3828
+ //
3829
+ // *Note*: 'interface' is actually a strict mode reserved word. So while
3830
+ //
3831
+ // "use strict"
3832
+ // interface
3833
+ // I {}
3834
+ //
3835
+ // could be legal, it would add complexity for very little gain.
3814
3836
case SyntaxKind . InterfaceKeyword :
3815
3837
case SyntaxKind . TypeKeyword :
3816
- nextToken ( ) ;
3817
- return isIdentifierOrKeyword ( ) ? StatementFlags . Statement : StatementFlags . None ;
3838
+ return nextTokenIsIdentifierOnSameLine ( ) ? StatementFlags . Statement : StatementFlags . None ;
3818
3839
case SyntaxKind . ModuleKeyword :
3819
3840
case SyntaxKind . NamespaceKeyword :
3841
+ return nextTokenIsIdentifierOrStringLiteralOnSameLine ( ) ? StatementFlags . ModuleElement : StatementFlags . None ;
3842
+ case SyntaxKind . DeclareKeyword :
3820
3843
nextToken ( ) ;
3821
- return isIdentifierOrKeyword ( ) || token === SyntaxKind . StringLiteral ? StatementFlags . ModuleElement : StatementFlags . None ;
3844
+ // ASI takes effect for this modifier.
3845
+ if ( scanner . hasPrecedingLineBreak ( ) ) {
3846
+ return StatementFlags . None ;
3847
+ }
3848
+ continue ;
3849
+
3822
3850
case SyntaxKind . ImportKeyword :
3823
3851
nextToken ( ) ;
3824
3852
return token === SyntaxKind . StringLiteral || token === SyntaxKind . AsteriskToken ||
@@ -3831,7 +3859,6 @@ module ts {
3831
3859
return StatementFlags . ModuleElement ;
3832
3860
}
3833
3861
continue ;
3834
- case SyntaxKind . DeclareKeyword :
3835
3862
case SyntaxKind . PublicKeyword :
3836
3863
case SyntaxKind . PrivateKeyword :
3837
3864
case SyntaxKind . ProtectedKeyword :
@@ -3982,6 +4009,11 @@ module ts {
3982
4009
case SyntaxKind . AtToken :
3983
4010
return parseDeclaration ( ) ;
3984
4011
4012
+ case SyntaxKind . InterfaceKeyword :
4013
+ case SyntaxKind . TypeKeyword :
4014
+ case SyntaxKind . ModuleKeyword :
4015
+ case SyntaxKind . NamespaceKeyword :
4016
+ case SyntaxKind . DeclareKeyword :
3985
4017
case SyntaxKind . ConstKeyword :
3986
4018
case SyntaxKind . EnumKeyword :
3987
4019
case SyntaxKind . ExportKeyword :
@@ -3994,45 +4026,6 @@ module ts {
3994
4026
return parseDeclaration ( ) ;
3995
4027
}
3996
4028
break ;
3997
-
3998
- // 'declare', 'module', 'namespace', 'interface'* and 'type' are all legal JavaScript identifiers;
3999
- // however, an identifier cannot be followed by another identifier on the same line. This is what we
4000
- // count on to parse out the respective declarations. For instance, we exploit this to say that
4001
- //
4002
- // namespace n
4003
- //
4004
- // can be none other than the beginning of a namespace declaration, but need to respect that JavaScript sees
4005
- //
4006
- // namespace
4007
- // n
4008
- //
4009
- // as the identifier 'namespace' on one line followed by the identifier 'n' on another.
4010
- // We need to look one token ahead to see if it permissible to try parsing a declaration.
4011
- //
4012
- // *Note*: 'interface' is actually a strict mode reserved word. So while
4013
- //
4014
- // "use strict"
4015
- // interface
4016
- // I {}
4017
- //
4018
- // could be legal, it would add complexity for very little gain.
4019
- case SyntaxKind . DeclareKeyword :
4020
- if ( lookAhead ( nextTokenIsIdentifierOrKeywordOnSameLine ) && getDeclarationFlags ( ) & flags ) {
4021
- return parseDeclaration ( ) ;
4022
- }
4023
- break ;
4024
- case SyntaxKind . ModuleKeyword :
4025
- if ( lookAhead ( nextTokenIsIdentifierOrStringLiteralOnSameLine ) && getDeclarationFlags ( ) & flags ) {
4026
- return parseDeclaration ( ) ;
4027
- }
4028
- break ;
4029
- case SyntaxKind . InterfaceKeyword :
4030
- case SyntaxKind . NamespaceKeyword :
4031
- case SyntaxKind . TypeKeyword :
4032
- if ( lookAhead ( nextTokenIsIdentifierOnSameLine ) && getDeclarationFlags ( ) & flags ) {
4033
- return parseDeclaration ( ) ;
4034
- }
4035
- break ;
4036
4029
}
4037
4030
return parseExpressionOrLabeledStatement ( ) ;
4038
4031
}
0 commit comments