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

Expected '(' or 'function' token

Error message

Expected '(' or 'function' token

What it means

Fired while parsing a @supports feature: after failing to match a declaration or the `selector(...)` function form, the parser expected either a '(' (parenthesized condition or declaration) or a function token, and found neither. This is a generic grammar guard; input at fault is a malformed feature inside @supports such as `@supports foo { }`.

Source

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

                Ok(SupportsFeature::Declaration(Box::new(declaration)))
            }
            Token::Function { value, .. }
                if matches_eq_ignore_ascii_case!(&**value, "selector") =>
            {
                // TODO improve me
                let ctx = Ctx {
                    in_supports_at_rule: true,
                    ..self.ctx
                };
                let function = self.with_ctx(ctx).parse_as::<Function>()?;

                Ok(SupportsFeature::Function(function))
            }
            _ => {
                let span = self.input.cur_span();

                Err(Error::new(
                    span,
                    ErrorKind::Expected("'(' or 'function' token"),
                ))
            }
        }
    }
}

impl<I> Parse<GeneralEnclosed> for Parser<I>
where
    I: ParserInput,
{
    fn parse(&mut self) -> PResult<GeneralEnclosed> {
        match cur!(self) {
            tok!("function") => {
                let ctx = Ctx {
                    need_canonicalize: false,
                    ..self.ctx

View on GitHub (pinned to 5176682b65)

Solutions

  1. Start the feature with `(` or a function like selector()
  2. Collect parser errors for diagnostics
  3. Fix the @supports syntax
Defensive patterns

Strategy: validation

When it happens

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