mozilla/pdf.js · error · Error
Invalid elseif declaration.
Error message
Invalid elseif declaration.
What it means
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.
Source
Thrown at src/core/xfa/formcalc_parser.js:1167
const [tok1, condition] = this.parseSimpleExpr();
tok = tok1 || this.lexer.next();
if (tok.id !== TOKEN.rightParen) {
throw new Error(Errors.if);
}
tok = this.lexer.next();
if (tok.id !== TOKEN.then) {
throw new Error(Errors.if);
}
const [tok2, thenClause] = this.parseExprList();
tok = tok2 || this.lexer.next();
while (tok.id === TOKEN.elseif) {
tok = this.lexer.next();
if (tok.id !== TOKEN.leftParen) {
throw new Error(Errors.elseif);
}
const [tok3, elseIfCondition] = this.parseSimpleExpr();
tok = tok3 || this.lexer.next();
if (tok.id !== TOKEN.rightParen) {
throw new Error(Errors.elseif);
}
tok = this.lexer.next();
if (tok.id !== TOKEN.then) {
throw new Error(Errors.elseif);
}
const [tok4, elseIfThenClause] = this.parseExprList();
elseIfClause.push(new ElseIfDecl(elseIfCondition, elseIfThenClause));
tok = tok4 || this.lexer.next();View on GitHub (pinned to 5903d58d58)
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 '('.
Example fix
// before elseif x > 1 then 2 // after elseif (x > 1) then 2
Defensive patterns
Strategy: validation
Validate before calling
// Reuse the if-open-paren check; elseif must also be followed by '('.
function elseifsOpenParen(src) {
return !/\belseif\b(?!\s*\()/.test(src);
} Try / catch
try {
bindFormCalcScript(xfaNode, src);
} catch (e) {
if (e instanceof Error && /elseif declaration/.test(e.message)) {
console.warn("FormCalc elseif missing '(' after keyword; skipping", e.message);
return;
}
throw e;
} Prevention
- Parenthesize every elseif condition exactly like if.
- Lint elseif clauses for a following '('.
- Treat elseif and if syntactically identically.
When it happens
Trigger: A FormCalc 'elseif x then ...' where the opening parenthesis after 'elseif' is missing. Reached while parsing the elseif chain of an XFA if-statement.
Common situations: Author forgot parens on an elseif condition; typo; generator emitting elseif without '('; corrupted script bytes.
Related errors
- Invalid token in index.
- Invalid token in Form code
- Invalid token in do ... end declaration.
- Invalid token in var declaration.
- Invalid token in func declaration.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/ae0b84144d8f4c51.
Report an issue: GitHub.