swc-project/swc · error · Error

Unexpected end of file, but expected ']'

Error message

Unexpected end of file, but expected ']'

What it means

Fired while consuming a simple block opened with '[': EOF was reached before the matching ']' mirror token. Per CSS Syntax 5.4.7 this is a parse error; the parser returns the partially-consumed block and records this error instead of failing the whole parse.

Source

Thrown at crates/swc_css_parser/src/parser/syntax/mod.rs:872

            name,
            value: Vec::new(),
        };

        // Repeatedly consume the next input token and process it as follows:
        loop {
            // <EOF-token>
            // This is a parse error. Return the block.
            if is!(self, EOF) {
                let mirror = match &simple_block.name.token {
                    Token::LBracket => "']'",
                    Token::LParen => "')'",
                    Token::LBrace => "'}'",
                    _ => {
                        unreachable!();
                    }
                };

                self.errors.push(Error::new(
                    span!(self, span.lo),
                    ErrorKind::EofButExpected(mirror),
                ));

                break;
            }

            match cur!(self) {
                // ending token
                // Return the block.
                tok!("]") if simple_block.name.token == Token::LBracket => {
                    bump!(self);

                    break;
                }
                tok!(")") if simple_block.name.token == Token::LParen => {
                    bump!(self);

View on GitHub (pinned to 5176682b65)

Solutions

  1. Close the '[' block with a matching ']'
  2. Check for unclosed brackets earlier in the stylesheet that swallow the intended closer
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at crates/swc_css_parser/src/parser/syntax/mod.rs:872 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/968abbc3bc55f260. Report an issue: GitHub.