refactor
This commit is contained in:
parent
48dfe992cc
commit
c93627c44d
@ -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
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user