andygeiss/esp32-transpiler

View on GitHub
transpile/handlers/handleIfStmt.go

Summary

Maintainability
A
0 mins
Test Coverage
package handlers

import (
    "fmt"
    "go/ast"
)

func handleIfStmt(stmt *ast.IfStmt) string {
    cond := HandleExpr(stmt.Cond)
    body := handleBlockStmt(stmt.Body)
    code := fmt.Sprintf(`if (%s) { %s }`, cond, body)
    if stmt.Else != nil {
        tail := handleBlockStmt(stmt.Else.(*ast.BlockStmt))
        code += fmt.Sprintf(" else { %s }", tail)
    }
    return code
}