@@ -1171,7 +1171,26 @@ module ts {
1171
1171
}
1172
1172
1173
1173
export interface Classifier {
1174
- getClassificationsForLine ( text : string , lexState : EndOfLineState , syntacticClassifierAbsent ?: boolean ) : ClassificationResult ;
1174
+ /**
1175
+ * Gives lexical classifications of tokens on a line without any syntactic context.
1176
+ * For instance, a token consisting of the text 'string' can be either an identifier
1177
+ * named 'string' or the keyword 'string', however, because this classifier is not aware,
1178
+ * it relies on certain heuristics to give acceptable results. For classifications where
1179
+ * speed trumps accuracy, this function is preferable; however, for true accuracy, the
1180
+ * syntactic classifier is ideal. In fact, in certain editing scenarios, combining the
1181
+ * lexical, syntactic, and semantic classifiers may issue the best user experience.
1182
+ *
1183
+ * @param text The text of a line to classify.
1184
+ * @param lexState The state of the lexical classifier at the end of the previous line.
1185
+ * @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier.
1186
+ * If there is no syntactic classifier (syntacticClassifierAbsent=true),
1187
+ * certain heuristics may be used in its place; however, if there is a
1188
+ * syntactic classifier (syntacticClassifierAbsent=false), certain
1189
+ * classifications which may be incorrectly categorized will be given
1190
+ * back as Identifiers in order to allow the syntactic classifier to
1191
+ * subsume the classification.
1192
+ */
1193
+ getClassificationsForLine ( text : string , lexState : EndOfLineState , syntacticClassifierAbsent : boolean ) : ClassificationResult ;
1175
1194
}
1176
1195
1177
1196
/**
@@ -5620,8 +5639,26 @@ module ts {
5620
5639
noRegexTable [ SyntaxKind . TrueKeyword ] = true ;
5621
5640
noRegexTable [ SyntaxKind . FalseKeyword ] = true ;
5622
5641
5623
- // Just a stack of TemplateHeads and OpenCurlyBraces, used
5624
- // to perform rudimentary classification on templates.
5642
+ // Just a stack of TemplateHeads and OpenCurlyBraces, used to perform rudimentary (inexact)
5643
+ // classification on template strings. Because of the context free nature of templates,
5644
+ // the only precise way to classify a template portion would be by propagating the stack across
5645
+ // lines, just as we do with the end-of-line state. However, this is a burden for implementers,
5646
+ // and the behavior is entirely subsumed by the syntactic classifier anyway, so we instead
5647
+ // flatten any nesting when the template stack is non-empty and encode it in the end-of-line state.
5648
+ // Situations in which this fails are
5649
+ // 1) When template strings are nested across different lines:
5650
+ // `hello ${ `world
5651
+ // ` }`
5652
+ //
5653
+ // Where on the second line, you will get the closing of a template,
5654
+ // a closing curly, and a new template.
5655
+ //
5656
+ // 2) When substitution expressions have curly braces and the curly brace falls on the next line:
5657
+ // `hello ${ () => {
5658
+ // return "world" } } `
5659
+ //
5660
+ // Where on the second line, you will get the 'return' keyword,
5661
+ // a string literal, and a template end consisting of ' } } `'.
5625
5662
var templateStack : SyntaxKind [ ] = [ ] ;
5626
5663
5627
5664
function isAccessibilityModifier ( kind : SyntaxKind ) {
@@ -5966,7 +6003,7 @@ module ts {
5966
6003
case SyntaxKind . Identifier :
5967
6004
default :
5968
6005
if ( isTemplateLiteralKind ( token ) ) {
5969
- return TokenClass . StringLiteral ; // maybe make a TemplateLiteral
6006
+ return TokenClass . StringLiteral ;
5970
6007
}
5971
6008
return TokenClass . Identifier ;
5972
6009
}
0 commit comments