addStmtsIfFirstCheck method

void addStmtsIfFirstCheck(
  1. List<Statement> stmts
)

If the last added statement is an if (firstCheck), re-use that if-block.

Otherwise, creates a new if-block and inserts it.

Implementation

void addStmtsIfFirstCheck(List<o.Statement> stmts) {
  // This is not the cleanest solution (i.e. it pollutes this class), but
  // otherwise you would need similar code in 10+ places.
  //
  // https://github.com/angulardart/angular/issues/712#issuecomment-403189258
  final lastStmt = _bodyStatements.isNotEmpty ? _bodyStatements.last : null;
  if (lastStmt is o.IfStmt && _isFirstCheckIfBlock[lastStmt] == true) {
    lastStmt.trueCase.addAll(stmts);
  } else {
    final ifStmt = o.IfStmt(DetectChangesVars.firstCheck, stmts);
    _isFirstCheckIfBlock[ifStmt] = true;
    addStmt(ifStmt);
  }
}