visitIfStmt method

  1. @override
Object? visitIfStmt(
  1. IfStmt stmt
)
override

Implementation

@override
Object? visitIfStmt(IfStmt stmt) {
  // Set to true in order to handle `else` branch.
  bool visitBody = true;

  if (!stmt.isTerminalElse) {
    visitBody = stmt.expr!.accept(this)?.toLua('ctrl').isTruthy ?? false;
  }

  if (visitBody) {
    Object? res;
    pushScope();
    for (Stmt stmt in stmt.body) {
      final out = stmt.accept(this);

      // One of these code paths must be non-null
      // unless all paths are null.
      // TODO: better value inference.
      if (out != null) {
        res = out;
      }
    }
    popScope();
    return res?.toLua('ret');
  }

  return stmt.nextIfStmt?.accept(this);
}