From df0a4527aaff32a7262e43d717e569293874f527 Mon Sep 17 00:00:00 2001 From: Softonik Date: Mon, 3 Jan 2022 03:04:41 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D1=84=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D1=8F=20?= =?UTF-8?q?=D1=81=20=D1=82=D0=B8=D0=BF=D0=BE=D0=BC=20ShouldBeSkipped?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- transpile/service.go | 34 ++++++++++++++++++++++++++++++++++ transpile/service_test.go | 10 ++++++++++ 2 files changed, 44 insertions(+) diff --git a/transpile/service.go b/transpile/service.go index ccbe9fc..f505a2a 100644 --- a/transpile/service.go +++ b/transpile/service.go @@ -184,6 +184,9 @@ func handleExprStmt(stmt *ast.ExprStmt) string { func handleFuncDecl(decl ast.Decl) string { fd := decl.(*ast.FuncDecl) + if shouldSkipFunction(fd.Type) { + return "" + } code := "" name := "" code += handleFuncDeclType(fd.Type) @@ -200,6 +203,37 @@ func handleFuncDecl(decl ast.Decl) string { code += "}" return code } +func shouldSkipFunction(t *ast.FuncType) (res bool) { + r := t.Results + if r == nil { + return + } + + l := r.List + if len(l) != 1 { + return + } + + p := l[0] + if p == nil { + return + } + + pt := p.Type + if pt == nil { + return + } + + i, ok := pt.(*ast.Ident) + if !ok { + return + } + + if i.Name == "ShouldBeSkipped" { + return true + } + return +} func handleFuncDeclParams(t *ast.FuncType) string { code := "" diff --git a/transpile/service_test.go b/transpile/service_test.go index f4bc71b..a0b2a65 100644 --- a/transpile/service_test.go +++ b/transpile/service_test.go @@ -225,6 +225,16 @@ var _ = Describe("Go Translator", func() { Compare(source, expected) }) + It("Function_Should_Be_Skipped", func() { + source := `package test + func foo() (s ShouldBeSkipped) { + return; + } + ` + expected := `` + Compare(source, expected) + }) + It("Package_Import", func() { source := `package test import "github.com/andygeiss/esp32-mqtt/api/controller"