From c93627c44d46ed893150b3234c57eadb2a12ee4f Mon Sep 17 00:00:00 2001 From: Egor Aristov Date: Fri, 5 Dec 2025 14:18:56 +0300 Subject: [PATCH] refactor --- kitcom/internal/ts/tsparser.go | 57 ++++++++++++++++------------------ 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/kitcom/internal/ts/tsparser.go b/kitcom/internal/ts/tsparser.go index 334e62b..0400d6f 100644 --- a/kitcom/internal/ts/tsparser.go +++ b/kitcom/internal/ts/tsparser.go @@ -14,9 +14,6 @@ import ( "efprojects.com/kitten-ipc/kitcom/internal/tsgo/tspath" ) -const TagName = "kittenipc" -const TagComment = "api" - type TypescriptApiParser struct { *common.Parser } @@ -54,37 +51,11 @@ func (p *TypescriptApiParser) parseFile(sourceFilePath string) ([]api.Endpoint, } cls := node.AsClassDeclaration() - jsDocNodes := cls.JSDoc(nil) - 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 { + if !p.isApiNode(cls) { return false } var endpoint api.Endpoint - endpoint.Name = cls.Name().Text() for _, member := range cls.MemberList().Nodes { @@ -145,3 +116,29 @@ func (p *TypescriptApiParser) parseFile(sourceFilePath string) ([]api.Endpoint, 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 +}