@@ -6856,21 +6856,58 @@ namespace ts {
6856
6856
}
6857
6857
}
6858
6858
6859
- function classifyTokenOrJsxText ( token : Node ) : void {
6860
- if ( nodeIsMissing ( token ) ) {
6861
- return ;
6859
+ /**
6860
+ * Returns true if node should be treated as classified and no further processing is required.
6861
+ * False will mean that node is not classified and traverse routine should recurse into node contents.
6862
+ */
6863
+ function tryClassifyNode ( node : Node ) : boolean {
6864
+ if ( nodeIsMissing ( node ) ) {
6865
+ return true ;
6862
6866
}
6863
6867
6864
- const tokenStart = token . kind === SyntaxKind . JsxText ? token . pos : classifyLeadingTriviaAndGetTokenStart ( token ) ;
6868
+ const classifiedElementName = tryClassifyJsxElementName ( node ) ;
6869
+ if ( ! isToken ( node ) && node . kind !== SyntaxKind . JsxText && classifiedElementName === undefined ) {
6870
+ return false ;
6871
+ }
6872
+
6873
+ const tokenStart = node . kind === SyntaxKind . JsxText ? node . pos : classifyLeadingTriviaAndGetTokenStart ( node ) ;
6865
6874
6866
- const tokenWidth = token . end - tokenStart ;
6875
+ const tokenWidth = node . end - tokenStart ;
6867
6876
Debug . assert ( tokenWidth >= 0 ) ;
6868
6877
if ( tokenWidth > 0 ) {
6869
- const type = classifyTokenType ( token . kind , token ) ;
6878
+ const type = classifiedElementName || classifyTokenType ( node . kind , node ) ;
6870
6879
if ( type ) {
6871
6880
pushClassification ( tokenStart , tokenWidth , type ) ;
6872
6881
}
6873
6882
}
6883
+
6884
+ return true ;
6885
+ }
6886
+
6887
+ function tryClassifyJsxElementName ( token : Node ) : ClassificationType {
6888
+ switch ( token . parent && token . parent . kind ) {
6889
+ case SyntaxKind . JsxOpeningElement :
6890
+ if ( ( < JsxOpeningElement > token . parent ) . tagName === token ) {
6891
+ return ClassificationType . jsxOpenTagName ;
6892
+ }
6893
+ break ;
6894
+ case SyntaxKind . JsxClosingElement :
6895
+ if ( ( < JsxClosingElement > token . parent ) . tagName === token ) {
6896
+ return ClassificationType . jsxCloseTagName ;
6897
+ }
6898
+ break ;
6899
+ case SyntaxKind . JsxSelfClosingElement :
6900
+ if ( ( < JsxSelfClosingElement > token . parent ) . tagName === token ) {
6901
+ return ClassificationType . jsxSelfClosingTagName ;
6902
+ }
6903
+ break ;
6904
+ case SyntaxKind . JsxAttribute :
6905
+ if ( ( < JsxAttribute > token . parent ) . name === token ) {
6906
+ return ClassificationType . jsxAttribute ;
6907
+ }
6908
+ break ;
6909
+ }
6910
+ return undefined ;
6874
6911
}
6875
6912
6876
6913
// for accurate classification, the actual token should be passed in. however, for
@@ -6963,28 +7000,6 @@ namespace ts {
6963
7000
return ClassificationType . parameterName ;
6964
7001
}
6965
7002
return ;
6966
-
6967
- case SyntaxKind . JsxOpeningElement :
6968
- if ( ( < JsxOpeningElement > token . parent ) . tagName === token ) {
6969
- return ClassificationType . jsxOpenTagName ;
6970
- }
6971
- return ;
6972
-
6973
- case SyntaxKind . JsxClosingElement :
6974
- if ( ( < JsxClosingElement > token . parent ) . tagName === token ) {
6975
- return ClassificationType . jsxCloseTagName ;
6976
- }
6977
- return ;
6978
-
6979
- case SyntaxKind . JsxSelfClosingElement :
6980
- if ( ( < JsxSelfClosingElement > token . parent ) . tagName === token ) {
6981
- return ClassificationType . jsxSelfClosingTagName ;
6982
- }
6983
- return ;
6984
- case SyntaxKind . JsxAttribute :
6985
- if ( ( < JsxAttribute > token . parent ) . name === token ) {
6986
- return ClassificationType . jsxAttribute ;
6987
- }
6988
7003
}
6989
7004
}
6990
7005
return ClassificationType . identifier ;
@@ -7003,10 +7018,7 @@ namespace ts {
7003
7018
const children = element . getChildren ( sourceFile ) ;
7004
7019
for ( let i = 0 , n = children . length ; i < n ; i ++ ) {
7005
7020
const child = children [ i ] ;
7006
- if ( isToken ( child ) || child . kind === SyntaxKind . JsxText ) {
7007
- classifyTokenOrJsxText ( child ) ;
7008
- }
7009
- else {
7021
+ if ( ! tryClassifyNode ( child ) ) {
7010
7022
// Recurse into our child nodes.
7011
7023
processElement ( child ) ;
7012
7024
}
0 commit comments