Skip to content

[WIP] Port TypeScript PR #59675: fix(59397): JsDoc is missing/duplicated in declarations for overloads declared in classes declared in functions #1144

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 67 additions & 2 deletions internal/checker/nodebuilderimpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,67 @@ func (b *nodeBuilderImpl) setCommentRange(node *ast.Node, range_ *ast.Node) {
}
}

func (b *nodeBuilderImpl) preserveCommentsOn(node *ast.Node, propertySymbol *ast.Symbol, range_ *ast.Node) {
// Find JSDoc property tag in the symbol's declarations
var jsdocPropertyTag *ast.Node
if propertySymbol.Declarations != nil {
for _, decl := range propertySymbol.Declarations {
if decl.Kind == ast.KindJSDocPropertyTag {
jsdocPropertyTag = decl
break
}
}
}

if jsdocPropertyTag != nil {
// Extract comment text from JSDoc property tag
commentText := b.getTextOfJSDocComment(jsdocPropertyTag.AsJSDocParameterOrPropertyTag().Comment)
if commentText != "" {
// Create synthetic leading comment
b.setSyntheticLeadingComment(node, commentText)
}
} else if range_ != nil {
// Copy comments to node for declaration emit (fallback to existing behavior)
b.setCommentRange(node, range_)
}
}

func (b *nodeBuilderImpl) getTextOfJSDocComment(comment *ast.NodeList) string {
if comment == nil || len(comment.Nodes) == 0 {
return ""
}

var textParts []string
for _, node := range comment.Nodes {
switch node.Kind {
case ast.KindJSDocText:
textParts = append(textParts, node.AsJSDocText().Text)
case ast.KindJSDocLink, ast.KindJSDocLinkCode, ast.KindJSDocLinkPlain:
textParts = append(textParts, node.Text())
}
}
return strings.Join(textParts, "")
}

func (b *nodeBuilderImpl) setSyntheticLeadingComment(node *ast.Node, commentText string) {
// This is where we would create synthetic leading comments.
// For now, this is a simplified implementation that just sets the comment range
// as the full JSDoc synthetic leading comment functionality appears to be incomplete in the Go port.
// TODO: Implement full synthetic leading comment support

// Format comment text as a JSDoc comment
lines := strings.Split(commentText, "\n")
var formattedLines []string
for _, line := range lines {
formattedLines = append(formattedLines, " * "+strings.TrimSpace(line))
}
formattedComment := "*\n" + strings.Join(formattedLines, "\n") + "\n "

// For now, we'll use a simple approach and rely on the existing comment range mechanism
// This is a placeholder until full synthetic comment support is implemented
_ = formattedComment // Suppress unused variable warning
}

func (b *nodeBuilderImpl) tryReuseExistingTypeNodeHelper(existing *ast.TypeNode) *ast.TypeNode {
return nil // !!!
}
Expand Down Expand Up @@ -2140,7 +2201,11 @@ func (b *nodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t
name: propertyName,
questionToken: optionalToken,
})
b.setCommentRange(methodDeclaration, propertySymbol.ValueDeclaration) // !!! missing JSDoc support formerly provided by preserveCommentsOn
range_ := signature.declaration
if range_ == nil {
range_ = propertySymbol.ValueDeclaration
}
b.preserveCommentsOn(methodDeclaration, propertySymbol, range_)
typeElements = append(typeElements, methodDeclaration)
}
if len(signatures) != 0 || optionalToken == nil {
Expand Down Expand Up @@ -2171,7 +2236,7 @@ func (b *nodeBuilderImpl) addPropertyToElementList(propertySymbol *ast.Symbol, t
}
propertySignature := b.f.NewPropertySignatureDeclaration(modifiers, propertyName, optionalToken, propertyTypeNode, nil)

b.setCommentRange(propertySignature, propertySymbol.ValueDeclaration) // !!! missing JSDoc support formerly provided by preserveCommentsOn
b.preserveCommentsOn(propertySignature, propertySymbol, propertySymbol.ValueDeclaration)
typeElements = append(typeElements, propertySignature)

return typeElements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ declare function Foo(): {
*/
foo(bar: string): void;
/**
* comment 1
* @deprecated This signature is deprecated
*
* comment 2
*/
foo(): string;
};
Expand Down

This file was deleted.