mozilla/pdf.js · error · Error

Invalid token in FormCalc expression at position ${this.pos}

Error message

Invalid token in FormCalc expression at position ${this.pos}.

What it means

Error "Invalid token in FormCalc expression at position ${this.pos}." thrown in mozilla/pdf.js.

Source

Thrown at src/core/xfa/formcalc_lexer.js:174

    this.len = data.length;
    this.strBuf = [];
  }

  skipUntilEOL() {
    const match = this.data.slice(this.pos).match(eolPattern);
    if (match) {
      this.pos += match.index + match[0].length;
    } else {
      // No eol so consume all the chars.
      this.pos = this.len;
    }
  }

  getIdentifier() {
    this.pos--;
    const match = this.data.slice(this.pos).match(identifierPattern);
    if (!match) {
      throw new Error(
        `Invalid token in FormCalc expression at position ${this.pos}.`
      );
    }

    const identifier = this.data.slice(this.pos, this.pos + match[0].length);
    this.pos += match[0].length;

    const lower = identifier.toLowerCase();
    if (!KEYWORDS.has(lower)) {
      return new Token(TOKEN.identifier, identifier);
    }

    return Singletons[lower];
  }

  getString() {
    const str = this.strBuf;
    const data = this.data;

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Fix the FormCalc expression syntax at the reported position; the lexer encountered characters that do not form a valid FormCalc token.
  2. Check for unbalanced quotes, invalid identifiers, or unsupported characters in the calculate script.

When it happens

Trigger: Thrown at src/core/xfa/formcalc_lexer.js:174 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/36ddb94944393d57. Report an issue: GitHub.