{"record":{"id":"ae0b84144d8f4c51","repo":"mozilla/pdf.js","slug":"invalid-elseif-declaration","errorCode":null,"errorMessage":"Invalid elseif declaration.","messagePattern":"Invalid elseif declaration\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/xfa/formcalc_parser.js","lineNumber":1167,"sourceCode":"    const [tok1, condition] = this.parseSimpleExpr();\n\n    tok = tok1 || this.lexer.next();\n    if (tok.id !== TOKEN.rightParen) {\n      throw new Error(Errors.if);\n    }\n\n    tok = this.lexer.next();\n    if (tok.id !== TOKEN.then) {\n      throw new Error(Errors.if);\n    }\n\n    const [tok2, thenClause] = this.parseExprList();\n    tok = tok2 || this.lexer.next();\n\n    while (tok.id === TOKEN.elseif) {\n      tok = this.lexer.next();\n      if (tok.id !== TOKEN.leftParen) {\n        throw new Error(Errors.elseif);\n      }\n\n      const [tok3, elseIfCondition] = this.parseSimpleExpr();\n\n      tok = tok3 || this.lexer.next();\n      if (tok.id !== TOKEN.rightParen) {\n        throw new Error(Errors.elseif);\n      }\n\n      tok = this.lexer.next();\n      if (tok.id !== TOKEN.then) {\n        throw new Error(Errors.elseif);\n      }\n\n      const [tok4, elseIfThenClause] = this.parseExprList();\n      elseIfClause.push(new ElseIfDecl(elseIfCondition, elseIfThenClause));\n\n      tok = tok4 || this.lexer.next();","sourceCodeStart":1149,"sourceCodeEnd":1185,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/xfa/formcalc_parser.js#L1149-L1185","documentation":"Thrown by Parser.parseIf() inside an 'elseif' branch when, immediately after 'elseif', the next token is not '(' (TOKEN.leftParen). Each elseif clause repeats the 'elseif '(' SimpleExpression ')' then ExprList' shape, so the condition must be parenthesized.","triggerScenarios":"A FormCalc 'elseif x then ...' where the opening parenthesis after 'elseif' is missing. Reached while parsing the elseif chain of an XFA if-statement.","commonSituations":"Author forgot parens on an elseif condition; typo; generator emitting elseif without '('; corrupted script bytes.","solutions":["Parenthesize every elseif condition: 'elseif (cond) then ...'.","Treat elseif exactly like if syntactically.","Re-author the if/elseif chain in a FormCalc tool.","Lint elseif clauses for a following '('."],"exampleFix":"// before\nelseif x > 1 then 2\n// after\nelseif (x > 1) then 2","handlingStrategy":"validation","validationCode":"// Reuse the if-open-paren check; elseif must also be followed by '('.\nfunction elseifsOpenParen(src) {\n  return !/\\belseif\\b(?!\\s*\\()/.test(src);\n}","typeGuard":null,"tryCatchPattern":"try {\n  bindFormCalcScript(xfaNode, src);\n} catch (e) {\n  if (e instanceof Error && /elseif declaration/.test(e.message)) {\n    console.warn(\"FormCalc elseif missing '(' after keyword; skipping\", e.message);\n    return;\n  }\n  throw e;\n}","preventionTips":["Parenthesize every elseif condition exactly like if.","Lint elseif clauses for a following '('.","Treat elseif and if syntactically identically."],"tags":["xfa","formcalc","parser","syntax","elseif"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}