@@ -749,8 +749,12 @@ func (tx *DeclarationTransformer) transformPropertyDeclaration(input *ast.Proper
749
749
tx .ensureType (input .AsNode (), false ),
750
750
tx .ensureNoInitializer (input .AsNode ()),
751
751
)
752
- tx .preserveJsDoc (result , input .AsNode ())
753
- tx .removeAllComments (result )
752
+ // Only remove all comments if there's no JSDoc to preserve
753
+ if input .AsNode ().Flags & ast .NodeFlagsHasJSDoc == 0 {
754
+ tx .removeAllComments (result )
755
+ } else {
756
+ tx .preserveJsDoc (result , input .AsNode ())
757
+ }
754
758
return result
755
759
}
756
760
@@ -898,8 +902,12 @@ func (tx *DeclarationTransformer) transformMethodDeclaration(input *ast.MethodDe
898
902
nil ,
899
903
nil ,
900
904
)
901
- tx .preserveJsDoc (result , input .AsNode ())
902
- tx .removeAllComments (result )
905
+ // Only remove all comments if there's no JSDoc to preserve
906
+ if input .AsNode ().Flags & ast .NodeFlagsHasJSDoc == 0 {
907
+ tx .removeAllComments (result )
908
+ } else {
909
+ tx .preserveJsDoc (result , input .AsNode ())
910
+ }
903
911
return result
904
912
}
905
913
}
@@ -990,11 +998,38 @@ func (tx *DeclarationTransformer) tryGetResolutionModeOverride(node *ast.Node) *
990
998
}
991
999
992
1000
func (tx * DeclarationTransformer ) preserveJsDoc (updated * ast.Node , original * ast.Node ) {
993
- // !!! TODO: JSDoc comment support
994
- // if (hasJSDocNodes(updated) && hasJSDocNodes(original)) {
995
- // updated.jsDoc = original.jsDoc;
996
- // }
997
- // return setCommentRange(updated, getCommentRange(original));
1001
+ // Get the source file to access JSDoc cache
1002
+ sourceFile := tx .state .currentSourceFile
1003
+ if sourceFile == nil {
1004
+ return
1005
+ }
1006
+
1007
+ // Check if original node has JSDoc comments
1008
+ if original .Flags & ast .NodeFlagsHasJSDoc == 0 {
1009
+ return
1010
+ }
1011
+
1012
+ // Get JSDoc from original node
1013
+ jsdoc := original .JSDoc (sourceFile )
1014
+ if len (jsdoc ) == 0 {
1015
+ return
1016
+ }
1017
+
1018
+ // Copy JSDoc to the updated node
1019
+ cache := sourceFile .JSDocCache ()
1020
+ if cache == nil {
1021
+ cache = make (map [* ast.Node ][]* ast.Node )
1022
+ sourceFile .SetJSDocCache (cache )
1023
+ }
1024
+
1025
+ // Set JSDoc on the updated node
1026
+ cache [updated ] = jsdoc
1027
+ updated .Flags |= ast .NodeFlagsHasJSDoc
1028
+
1029
+ // If there was a deprecated tag, preserve that too
1030
+ if original .Flags & ast .NodeFlagsDeprecated != 0 {
1031
+ updated .Flags |= ast .NodeFlagsDeprecated
1032
+ }
998
1033
}
999
1034
1000
1035
func (tx * DeclarationTransformer ) removeAllComments (node * ast.Node ) {
@@ -1397,8 +1432,12 @@ func (tx *DeclarationTransformer) transformClassDeclaration(input *ast.ClassDecl
1397
1432
heritageClauses ,
1398
1433
members ,
1399
1434
)
1400
- tx .preserveJsDoc (classDecl , input .AsNode ())
1401
- tx .removeAllComments (classDecl )
1435
+ // Only remove all comments if there's no JSDoc to preserve
1436
+ if input .AsNode ().Flags & ast .NodeFlagsHasJSDoc == 0 {
1437
+ tx .removeAllComments (classDecl )
1438
+ } else {
1439
+ tx .preserveJsDoc (classDecl , input .AsNode ())
1440
+ }
1402
1441
1403
1442
return tx .Factory ().NewSyntaxList ([]* ast.Node {
1404
1443
statement ,
@@ -1414,8 +1453,12 @@ func (tx *DeclarationTransformer) transformClassDeclaration(input *ast.ClassDecl
1414
1453
tx .Visitor ().VisitNodes (input .HeritageClauses ),
1415
1454
members ,
1416
1455
)
1417
- tx .preserveJsDoc (result , input .AsNode ())
1418
- tx .removeAllComments (result )
1456
+ // Only remove all comments if there's no JSDoc to preserve
1457
+ if input .AsNode ().Flags & ast .NodeFlagsHasJSDoc == 0 {
1458
+ tx .removeAllComments (result )
1459
+ } else {
1460
+ tx .preserveJsDoc (result , input .AsNode ())
1461
+ }
1419
1462
return result
1420
1463
}
1421
1464
0 commit comments