stmtsErrCount()

in lib/generator.js [857:897]


  stmtsErrCount(stmts) {
    let errNum = 0;
    for (var i = 0; i < stmts.length; i++) {
      const ast = stmts[i];
      if (ast.type === 'return') {
        errNum += this.checkExpr(ast.expr);
      } else if (ast.type === 'if') {
        errNum += this.checkExpr(ast.condition);
        errNum += this.stmtsErrCount(ast.stmts.stmts);
        if(ast.elseIfs && ast.elseIfs.length > 0) {
          ast.elseIfs.map(elseIf => {
            errNum += this.checkExpr(elseIf.condition);
            errNum += this.stmtsErrCount(elseIf.stmts.stmts);
          });
        }
        if(ast.elseStmts) {
          errNum += this.stmtsErrCount(ast.elseStmts.stmts);
        }
      } else if (ast.type === 'throw') {
        errNum += 1;
      } else if (ast.type === 'assign') {
        errNum += this.checkExpr(ast.expr);
      } else if (ast.type === 'declare') {
        errNum += this.checkExpr(ast.expr);
      } else if (ast.type === 'while') {
        errNum += this.checkExpr(ast.condition);
        errNum += this.stmtsErrCount(ast.stmts.stmts);
      } else if (ast.type === 'for') {
        errNum += this.checkExpr(ast.list);
        errNum += this.stmtsErrCount(ast.stmts.stmts);
      } else if (ast.type === 'try') {
        errNum += 1;
      } else if (ast.type === 'call' && ast.hasThrow) {
        const name = _format(_name(ast.left.id));
        if (!name.startsWith('$') || !this.builtin[name]) {
          errNum += 1;
        }
      }
    }
    return errNum;
  }