From 026751665a39a98e981d3f1da55447886668b965 Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Fri, 10 Jan 2020 16:43:11 +0800 Subject: [PATCH] feat: [ts] add extend support --- trial/pkg/application/ts/ts_ident_app_test.go | 14 ++++++++++++++ trial/pkg/ast/typescript_ident_listener.go | 9 +++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/trial/pkg/application/ts/ts_ident_app_test.go b/trial/pkg/application/ts/ts_ident_app_test.go index dee099b..679246a 100644 --- a/trial/pkg/application/ts/ts_ident_app_test.go +++ b/trial/pkg/application/ts/ts_ident_app_test.go @@ -57,6 +57,20 @@ func Test_TypeScriptMultipleClass(t *testing.T) { g.Expect(results[3].Class).To(Equal("default")) } +func Test_TypeScriptAbstractClass(t *testing.T) { + g := NewGomegaWithT(t) + + app := new(TypeScriptApiApp) + code, _ := ioutil.ReadFile("../../../../_fixtures/ts/AbstractClass.ts") + + results := app.Analysis(string(code)) + + g.Expect(len(results)).To(Equal(3)) + g.Expect(results[0].Type).To(Equal("Class")) + g.Expect(results[1].Class).To(Equal("Employee")) + g.Expect(results[1].Extend).To(Equal("Person")) +} + func Test_ShouldGetClassFromModule(t *testing.T) { g := NewGomegaWithT(t) diff --git a/trial/pkg/ast/typescript_ident_listener.go b/trial/pkg/ast/typescript_ident_listener.go index 678e2e4..f7d75f5 100644 --- a/trial/pkg/ast/typescript_ident_listener.go +++ b/trial/pkg/ast/typescript_ident_listener.go @@ -71,10 +71,6 @@ func BuildInterfaceTypeBody(ctx *parser.TypeMemberListContext, classNode *domain methodSignature := memberChild.(*parser.MethodSignatureContext) method := domain.NewJMethod() method.Name = methodSignature.PropertyName().GetText() - if typeMemberCtx.Type_() != nil { - // todo need a case ? - method.Type = typeMemberCtx.Type_().GetText() - } FillMethodFromCallSignature(methodSignature.CallSignature().(*parser.CallSignatureContext), &method) classNode.Methods = append(classNode.Methods, method) @@ -124,6 +120,11 @@ func (s *TypeScriptIdentListener) EnterClassDeclaration(ctx *parser.ClassDeclara currentNode.Implements = append(currentNode.Implements, BuildImplements(typeList)...) } + if heritageContext.ClassExtendsClause() != nil { + referenceContext := heritageContext.ClassExtendsClause().(*parser.ClassExtendsClauseContext).TypeReference().(*parser.TypeReferenceContext) + currentNode.Extend = referenceContext.TypeName().GetText() + } + for _, classElement := range ctx.ClassTail().(*parser.ClassTailContext).AllClassElement() { elementChild := classElement.GetChild(0) if reflect.TypeOf(elementChild).String() == "*parser.ConstructorDeclarationContext" { -- GitLab