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"