@@ -4599,26 +4599,58 @@ module ts {
4599
4599
/// If we consider every slash token to be a regex, we could be missing cases like "1/2/3", where
4600
4600
/// we have a series of divide operator. this list allows us to be more accurate by ruling out
4601
4601
/// locations where a regexp cannot exist.
4602
- var noRegexTable : boolean [ ] ;
4603
- if ( ! noRegexTable ) {
4604
- noRegexTable = [ ] ;
4605
- noRegexTable [ SyntaxKind . Identifier ] = true ;
4606
- noRegexTable [ SyntaxKind . StringLiteral ] = true ;
4607
- noRegexTable [ SyntaxKind . NumericLiteral ] = true ;
4608
- noRegexTable [ SyntaxKind . RegularExpressionLiteral ] = true ;
4609
- noRegexTable [ SyntaxKind . ThisKeyword ] = true ;
4610
- noRegexTable [ SyntaxKind . PlusPlusToken ] = true ;
4611
- noRegexTable [ SyntaxKind . MinusMinusToken ] = true ;
4612
- noRegexTable [ SyntaxKind . CloseParenToken ] = true ;
4613
- noRegexTable [ SyntaxKind . CloseBracketToken ] = true ;
4614
- noRegexTable [ SyntaxKind . CloseBraceToken ] = true ;
4615
- noRegexTable [ SyntaxKind . TrueKeyword ] = true ;
4616
- noRegexTable [ SyntaxKind . FalseKeyword ] = true ;
4602
+ var noRegexTable : boolean [ ] = [ ] ;
4603
+ noRegexTable [ SyntaxKind . Identifier ] = true ;
4604
+ noRegexTable [ SyntaxKind . StringLiteral ] = true ;
4605
+ noRegexTable [ SyntaxKind . NumericLiteral ] = true ;
4606
+ noRegexTable [ SyntaxKind . RegularExpressionLiteral ] = true ;
4607
+ noRegexTable [ SyntaxKind . ThisKeyword ] = true ;
4608
+ noRegexTable [ SyntaxKind . PlusPlusToken ] = true ;
4609
+ noRegexTable [ SyntaxKind . MinusMinusToken ] = true ;
4610
+ noRegexTable [ SyntaxKind . CloseParenToken ] = true ;
4611
+ noRegexTable [ SyntaxKind . CloseBracketToken ] = true ;
4612
+ noRegexTable [ SyntaxKind . CloseBraceToken ] = true ;
4613
+ noRegexTable [ SyntaxKind . TrueKeyword ] = true ;
4614
+ noRegexTable [ SyntaxKind . FalseKeyword ] = true ;
4615
+
4616
+ function isAccessibilityModifier ( kind : SyntaxKind ) {
4617
+ switch ( kind ) {
4618
+ case SyntaxKind . PublicKeyword :
4619
+ case SyntaxKind . PrivateKeyword :
4620
+ case SyntaxKind . ProtectedKeyword :
4621
+ return true ;
4622
+ }
4623
+
4624
+ return false ;
4625
+ }
4626
+
4627
+ /** Returns true if 'keyword2' can legally follow 'keyword1' in any language construct. */
4628
+ function canFollow ( keyword1 : SyntaxKind , keyword2 : SyntaxKind ) {
4629
+ if ( isAccessibilityModifier ( keyword1 ) ) {
4630
+ if ( keyword2 === SyntaxKind . GetKeyword ||
4631
+ keyword2 === SyntaxKind . SetKeyword ||
4632
+ keyword2 === SyntaxKind . ConstructorKeyword ||
4633
+ keyword2 === SyntaxKind . StaticKeyword ) {
4634
+
4635
+ // Allow things like "public get", "public constructor" and "public static".
4636
+ // These are all legal.
4637
+ return true ;
4638
+ }
4639
+
4640
+ // Any other keyword following "public" is actually an identifier an not a real
4641
+ // keyword.
4642
+ return false ;
4643
+ }
4644
+
4645
+ // Assume any other keyword combination is legal. This can be refined in the future
4646
+ // if there are more cases we want the classifier to be better at.
4647
+ return true ;
4617
4648
}
4618
4649
4619
4650
function getClassificationsForLine ( text : string , lexState : EndOfLineState ) : ClassificationResult {
4620
4651
var offset = 0 ;
4621
4652
var lastTokenOrCommentEnd = 0 ;
4653
+ var token = SyntaxKind . Unknown ;
4622
4654
var lastNonTriviaToken = SyntaxKind . Unknown ;
4623
4655
4624
4656
// If we're in a string literal, then prepend: "\
@@ -4648,8 +4680,6 @@ module ts {
4648
4680
entries : [ ]
4649
4681
} ;
4650
4682
4651
-
4652
- var token = SyntaxKind . Unknown ;
4653
4683
do {
4654
4684
token = scanner . scan ( ) ;
4655
4685
@@ -4662,6 +4692,13 @@ module ts {
4662
4692
else if ( lastNonTriviaToken === SyntaxKind . DotToken && isKeyword ( token ) ) {
4663
4693
token = SyntaxKind . Identifier ;
4664
4694
}
4695
+ else if ( isKeyword ( lastNonTriviaToken ) && isKeyword ( token ) && ! canFollow ( lastNonTriviaToken , token ) ) {
4696
+ // We have two keywords in a row. Only treat the second as a keyword if
4697
+ // it's a sequence that could legally occur in the language. Otherwise
4698
+ // treat it as an identifier. This way, if someone writes "private var"
4699
+ // we recognize that 'var' is actually an identifier here.
4700
+ token = SyntaxKind . Identifier ;
4701
+ }
4665
4702
4666
4703
lastNonTriviaToken = token ;
4667
4704
}
0 commit comments