@@ -6856,21 +6856,58 @@ namespace ts {
68566856 }
68576857 }
68586858
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 ;
68626866 }
68636867
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 ) ;
68656874
6866- const tokenWidth = token . end - tokenStart ;
6875+ const tokenWidth = node . end - tokenStart ;
68676876 Debug . assert ( tokenWidth >= 0 ) ;
68686877 if ( tokenWidth > 0 ) {
6869- const type = classifyTokenType ( token . kind , token ) ;
6878+ const type = classifiedElementName || classifyTokenType ( node . kind , node ) ;
68706879 if ( type ) {
68716880 pushClassification ( tokenStart , tokenWidth , type ) ;
68726881 }
68736882 }
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 ;
68746911 }
68756912
68766913 // for accurate classification, the actual token should be passed in. however, for
@@ -6963,28 +7000,6 @@ namespace ts {
69637000 return ClassificationType . parameterName ;
69647001 }
69657002 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- }
69887003 }
69897004 }
69907005 return ClassificationType . identifier ;
@@ -7003,10 +7018,7 @@ namespace ts {
70037018 const children = element . getChildren ( sourceFile ) ;
70047019 for ( let i = 0 , n = children . length ; i < n ; i ++ ) {
70057020 const child = children [ i ] ;
7006- if ( isToken ( child ) || child . kind === SyntaxKind . JsxText ) {
7007- classifyTokenOrJsxText ( child ) ;
7008- }
7009- else {
7021+ if ( ! tryClassifyNode ( child ) ) {
70107022 // Recurse into our child nodes.
70117023 processElement ( child ) ;
70127024 }
0 commit comments