{"record":{"id":"f13e3635ca14528c","repo":"mozilla/pdf.js","slug":"invalid-token-in-var-declaration","errorCode":null,"errorMessage":"Invalid token in var declaration.","messagePattern":"Invalid token in var declaration\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/core/xfa/formcalc_parser.js","lineNumber":1065,"sourceCode":"    return parser.parse(tok);\n  }\n\n  parseBlock() {\n    const [tok1, body] = this.parseExprList();\n\n    const tok = tok1 || this.lexer.next();\n    if (tok.id !== TOKEN.end) {\n      throw new Error(Errors.block);\n    }\n\n    return [null, new BlockDecl(body)];\n  }\n\n  parseVarDecl() {\n    // 'var' Identifier ('=' SimpleExpression)?\n    let tok = this.lexer.next();\n    if (tok.id !== TOKEN.identifier) {\n      throw new Error(Errors.var);\n    }\n\n    const identifier = tok.value;\n\n    tok = this.lexer.next();\n    if (tok.id !== TOKEN.assign) {\n      return [tok, new VarDecl(identifier, null)];\n    }\n\n    const [tok1, expr] = this.parseSimpleExpr();\n    return [tok1, new VarDecl(identifier, expr)];\n  }\n\n  parseFuncDecl() {\n    // 'func' Identifier ParameterList 'do' ExpressionList 'endfunc'.\n    let tok = this.lexer.next();\n    if (tok.id !== TOKEN.identifier) {\n      throw new Error(Errors.func);","sourceCodeStart":1047,"sourceCodeEnd":1083,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/core/xfa/formcalc_parser.js#L1047-L1083","documentation":"Thrown by Parser.parseVarDecl() when, immediately after the 'var' keyword, the next token is not an identifier (TOKEN.identifier). FormCalc's var declaration grammar is 'var Identifier ('=' SimpleExpression)?', so 'var' must be directly followed by a variable name.","triggerScenarios":"A FormCalc statement like 'var = 5' or 'var 123' where 'var' is not followed by an identifier token. Reached during XFA form script parsing when a 'var' declaration is malformed.","commonSituations":"Typo omitting the variable name; using a reserved keyword where a name is expected; corrupted script bytes dropping the identifier; generator emitting 'var' then a non-name literal.","solutions":["Add a legal identifier name directly after 'var' (FormCalc identifiers are letter-led, alphanumeric/underscore).","Ensure the name is not a reserved FormCalc keyword that the lexer would tokenize differently.","Re-emit the script from the form design tool to fix the declaration.","Lint the script string for every 'var' occurrence before binding."],"exampleFix":"// before\nvar = 5\n// after\nvar x = 5","handlingStrategy":"validation","validationCode":"// Reject 'var' not followed by an identifier.\nfunction validVarDecls(src) {\n  return !/\\bvar\\b(?!\\s+[A-Za-z_][A-Za-z0-9_]*)/.test(src);\n}","typeGuard":null,"tryCatchPattern":"try {\n  bindFormCalcScript(xfaNode, src);\n} catch (e) {\n  if (e instanceof Error && /var declaration/.test(e.message)) {\n    console.warn(\"Malformed FormCalc var declaration; skipping\", e.message);\n    return;\n  }\n  throw e;\n}","preventionTips":["Always name a variable after 'var'.","Avoid reserved keywords as variable names.","Lint 'var' declarations before binding."],"tags":["xfa","formcalc","parser","syntax","var"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}