@@ -973,6 +973,33 @@ func getPossibleSymbolReferencePositions(sourceFile *ast.SourceFile, symbolName
973
973
return positions
974
974
}
975
975
976
+ // findFirstJsxNode recursively searches for the first JSX element, self-closing element, or fragment
977
+ func findFirstJsxNode (root * ast.Node ) * ast.Node {
978
+ var visit func (* ast.Node ) * ast.Node
979
+ visit = func (node * ast.Node ) * ast.Node {
980
+ // Check if this is a JSX node we're looking for
981
+ switch node .Kind {
982
+ case ast .KindJsxElement , ast .KindJsxSelfClosingElement , ast .KindJsxFragment :
983
+ return node
984
+ }
985
+
986
+ // Skip subtree if it doesn't contain JSX
987
+ if node .SubtreeFacts ()& ast .SubtreeContainsJsx == 0 {
988
+ return nil
989
+ }
990
+
991
+ // Traverse children to find JSX node
992
+ var result * ast.Node
993
+ node .ForEachChild (func (child * ast.Node ) bool {
994
+ result = visit (child )
995
+ return result != nil // Stop if found
996
+ })
997
+ return result
998
+ }
999
+
1000
+ return visit (root )
1001
+ }
1002
+
976
1003
func getReferencesForNonModule (referencedFile * ast.SourceFile , program * compiler.Program ) []* referenceEntry {
977
1004
// !!! not implemented
978
1005
return []* referenceEntry {}
@@ -1013,13 +1040,21 @@ func getReferencedSymbolsForModule(ctx context.Context, program *compiler.Progra
1013
1040
// import("foo") with no qualifier will reference the `export =` of the module, which may be referenced anyway.
1014
1041
return newNodeEntry (reference .literal )
1015
1042
case ModuleReferenceKindImplicit :
1016
- // For implicit references (e.g., JSX runtime imports), return the first statement or the whole file.
1017
- // We skip the complex JSX detection for now and just use the first statement or the file itself.
1043
+ // For implicit references (e.g., JSX runtime imports), return the first JSX node,
1044
+ // the first statement, or the whole file
1018
1045
var rangeNode * ast.Node
1019
- if reference .referencingFile .Statements != nil && len (reference .referencingFile .Statements .Nodes ) > 0 {
1020
- rangeNode = reference .referencingFile .Statements .Nodes [0 ]
1021
- } else {
1022
- rangeNode = reference .referencingFile .AsNode ()
1046
+
1047
+ // Skip the JSX search for tslib imports
1048
+ if reference .literal .Text () != "tslib" {
1049
+ rangeNode = findFirstJsxNode (reference .referencingFile .AsNode ())
1050
+ }
1051
+
1052
+ if rangeNode == nil {
1053
+ if reference .referencingFile .Statements != nil && len (reference .referencingFile .Statements .Nodes ) > 0 {
1054
+ rangeNode = reference .referencingFile .Statements .Nodes [0 ]
1055
+ } else {
1056
+ rangeNode = reference .referencingFile .AsNode ()
1057
+ }
1023
1058
}
1024
1059
return newNodeEntry (rangeNode )
1025
1060
case ModuleReferenceKindReference :
@@ -1060,8 +1095,9 @@ func getReferencedSymbolsForModule(ctx context.Context, program *compiler.Progra
1060
1095
if ast .IsBinaryExpression (decl ) && ast .IsPropertyAccessExpression (decl .AsBinaryExpression ().Left ) {
1061
1096
node = decl .AsBinaryExpression ().Left .AsPropertyAccessExpression ().Expression
1062
1097
} else if ast .IsExportAssignment (decl ) {
1063
- // Find the export keyword - for now, just use the declaration itself
1064
- node = decl
1098
+ // Find the export keyword
1099
+ node = findChildOfKind (decl , ast .KindExportKeyword , sourceFile )
1100
+ debug .Assert (node != nil , "Expected to find export keyword" )
1065
1101
} else {
1066
1102
node = ast .GetNameOfDeclaration (decl )
1067
1103
if node == nil {
0 commit comments