refactor: extact var fo ts

上级 02675166
interface IPerson {
name: string;
}
......
......@@ -182,3 +182,14 @@ function buildName(firstName: string, ...restOfName: string[]) {
g.Expect(parameters[0].Name).To(Equal("firstName"))
g.Expect(parameters[1].Name).To(Equal("restOfName"))
}
func Test_ShouldGetClassFields(t *testing.T) {
g := NewGomegaWithT(t)
app := new(TypeScriptApiApp)
code, _ := ioutil.ReadFile("../../../../_fixtures/ts/Class.ts")
results := app.Analysis(string(code))
g.Expect(len(results[1].Fields)).To(Equal(0))
}
......@@ -125,19 +125,26 @@ func (s *TypeScriptIdentListener) EnterClassDeclaration(ctx *parser.ClassDeclara
currentNode.Extend = referenceContext.TypeName().GetText()
}
for _, classElement := range ctx.ClassTail().(*parser.ClassTailContext).AllClassElement() {
classTailContext := ctx.ClassTail().(*parser.ClassTailContext)
handleClassBodyElements(classTailContext)
classNodeQueue = append(classNodeQueue, *currentNode)
}
func handleClassBodyElements(classTailContext *parser.ClassTailContext) {
for _, classElement := range classTailContext.AllClassElement() {
elementChild := classElement.GetChild(0)
if reflect.TypeOf(elementChild).String() == "*parser.ConstructorDeclarationContext" {
elementTypeStr := reflect.TypeOf(elementChild).String()
switch elementTypeStr {
case "*parser.ConstructorDeclarationContext":
constructorDeclCtx := elementChild.(*parser.ConstructorDeclarationContext)
currentNode.Methods = append(currentNode.Methods, BuildConstructorMethod(constructorDeclCtx))
} else if reflect.TypeOf(elementChild).String() == "*parser.PropertyMemberDeclarationContext" {
s.handlePropertyMember(elementChild)
case "*parser.PropertyMemberDeclarationContext":
handlePropertyMember(elementChild)
}
}
classNodeQueue = append(classNodeQueue, *currentNode)
}
func (s *TypeScriptIdentListener) handlePropertyMember(elementChild antlr.Tree) {
func handlePropertyMember(elementChild antlr.Tree) {
propertyMemberCtx := elementChild.(*parser.PropertyMemberDeclarationContext)
callSignaturePos := 3
if propertyMemberCtx.GetChildCount() >= callSignaturePos {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册