swc-project/swc · error · Error

Expected '{', '(' or '[' token

Error message

Expected '{', '(' or '[' token

What it means

Fired by the <simple-block> parser: a simple block must begin with one of '{', '(' or '[' (its associated token), but the current token is something else. The parser cannot open any block at this position and returns an error to the caller for recovery.

Source

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

            }
        }
    }
}

impl<I> Parse<SimpleBlock> for Parser<I>
where
    I: ParserInput,
{
    fn parse(&mut self) -> PResult<SimpleBlock> {
        // To consume a simple block:

        // Create a simple block with its associated token set to the current input
        // token and with its value initially set to an empty list.
        let span = self.input.cur_span();
        let name = match cur!(self) {
            tok!("{") | tok!("(") | tok!("[") => self.input.bump().unwrap(),
            _ => {
                return Err(Error::new(
                    span,
                    ErrorKind::Expected("'{', '(' or '[' token"),
                ));
            }
        };
        let mut simple_block = SimpleBlock {
            span: Default::default(),
            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 => "']'",

View on GitHub (pinned to 5176682b65)

Solutions

  1. Open the block with '{', '(' or '[' as required by the grammar
  2. Fix the preceding syntax so the parser reaches the block-opening token
Defensive patterns

Strategy: validation

When it happens

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