swc-project/swc · error · SyntaxError

Unexpected eof

Error message

Unexpected eof

What it means

Eof sentinel built by the shared eof_error helper when the parser, at a point where a token is required (literal, JSX element, export, for-head, TS modifier/decl), sees the EOF token. The span is a zero-width Span at the end position, pointing just past the last character.

Source

Thrown at crates/swc_ecma_lexer/src/common/parser/mod.rs:517

    let cur = p.input().cur();
    Ok(if cur.is_shebang() {
        let ret = p.input_mut().expect_shebang_token_and_bump();
        Some(ret)
    } else {
        None
    })
}

#[cold]
#[inline(never)]
pub fn eof_error<'a, P: Parser<'a>>(p: &mut P) -> crate::error::Error {
    debug_assert!(
        p.input().cur().is_eof(),
        "Parser should not call throw_eof_error() without knowing current token"
    );
    let pos = p.input().end_pos();
    let last = Span { lo: pos, hi: pos };
    crate::error::Error::new(last, crate::error::SyntaxError::Eof)
}

View on GitHub (pinned to 5176682b65)

Solutions

  1. Complete the truncated construct the parser was in the middle of (check the reported call path for which production needed a token)
  2. Check for unbalanced braces/brackets that swallowed the rest of the file
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_ecma_lexer/src/common/parser/mod.rs:517 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/250d3cfef2e3c131. Report an issue: GitHub.