This commit is contained in:
Egor Aristov 2025-12-05 14:18:56 +03:00
parent 48dfe992cc
commit c93627c44d
Signed by: egor3f
GPG Key ID: 40482A264AAEC85F

View File

@ -14,9 +14,6 @@ import (
"efprojects.com/kitten-ipc/kitcom/internal/tsgo/tspath" "efprojects.com/kitten-ipc/kitcom/internal/tsgo/tspath"
) )
const TagName = "kittenipc"
const TagComment = "api"
type TypescriptApiParser struct { type TypescriptApiParser struct {
*common.Parser *common.Parser
} }
@ -54,37 +51,11 @@ func (p *TypescriptApiParser) parseFile(sourceFilePath string) ([]api.Endpoint,
} }
cls := node.AsClassDeclaration() cls := node.AsClassDeclaration()
jsDocNodes := cls.JSDoc(nil) if !p.isApiNode(cls) {
if len(jsDocNodes) == 0 {
return false
}
var isApi bool
outer:
for _, jsDocNode := range jsDocNodes {
jsDoc := jsDocNode.AsJSDoc()
if jsDoc.Tags == nil {
continue
}
for _, tag := range jsDoc.Tags.Nodes {
if tag.TagName().Text() == TagName {
for _, com := range tag.Comments() {
if strings.TrimSpace(com.Text()) == TagComment {
isApi = true
break outer
}
}
}
}
}
if !isApi {
return false return false
} }
var endpoint api.Endpoint var endpoint api.Endpoint
endpoint.Name = cls.Name().Text() endpoint.Name = cls.Name().Text()
for _, member := range cls.MemberList().Nodes { for _, member := range cls.MemberList().Nodes {
@ -145,3 +116,29 @@ func (p *TypescriptApiParser) parseFile(sourceFilePath string) ([]api.Endpoint,
return endpoints, nil return endpoints, nil
} }
const TagName = "kittenipc"
const TagComment = "api"
func (p *TypescriptApiParser) isApiNode(cls *ast.ClassDeclaration) bool {
jsDocNodes := cls.JSDoc(nil)
if len(jsDocNodes) == 0 {
return false
}
for _, jsDocNode := range jsDocNodes {
jsDoc := jsDocNode.AsJSDoc()
if jsDoc.Tags == nil {
continue
}
for _, tag := range jsDoc.Tags.Nodes {
if tag.TagName().Text() == TagName {
for _, com := range tag.Comments() {
if strings.TrimSpace(com.Text()) == TagComment {
return true
}
}
}
}
}
return false
}