swc-project/swc · error · swc_css_parser::Error

Unexpected tokens in at-rule prelude

Error message

Unexpected tokens in at-rule prelude

What it means

After a recognized at-rule prelude was parsed, tokens other than EOF or the block remain, so the prelude carries trailing content the grammar does not allow; the parser returns this error at the trailing token's span.

Source

Thrown at crates/swc_css_parser/src/parser/at_rules/mod.rs:443

                    let span = self.input.cur_span();
                    let _: ComponentValue = self.parse()?;

                    self.errors.push(Error::new(span, ErrorKind::ValueAtRule));

                    self.input.skip_ws();
                }

                return Err(Error::new(Default::default(), ErrorKind::Ignore));
            }
            _ => {
                return Err(Error::new(Default::default(), ErrorKind::Ignore));
            }
        };

        if !is!(self, EOF) {
            let span = self.input.cur_span();

            return Err(Error::new(
                span,
                ErrorKind::Unexpected("tokens in at-rule prelude"),
            ));
        }

        Ok(prelude)
    }

    pub(super) fn parse_at_rule_block(&mut self, name: &str) -> PResult<Vec<ComponentValue>> {
        let block_contents = match name {
            "charset" => {
                let span = self.input.cur_span();

                return Err(Error::new(span, ErrorKind::Unexpected("'{' token")));
            }
            "color-profile" => {
                let declaration_list: Vec<DeclarationOrAtRule> = self.parse()?;
                let declaration_list: Vec<ComponentValue> = declaration_list

View on GitHub (pinned to 5176682b65)

Solutions

  1. Remove the extra tokens after the at-rule prelude
  2. Report the returned error as a diagnostic
  3. Consume the trailing tokens deliberately if extending the grammar
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_css_parser/src/parser/at_rules/mod.rs:443 when the library encounters an invalid state.

Common situations: See trigger scenarios.

Understand the failure class


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