swc-project/swc · error

Expected 'number', 'dimension', 'percentage', 'ident', '(' o

Error message

Expected 'number', 'dimension', 'percentage', 'ident', '(' or 'function' tokens

What it means

Fired while parsing a CalcValue inside math functions: a calc value must be a number, dimension, percentage, ident (constants like `pi`/`e`/`infinity`/`NaN`), a parenthesized sum, or a nested function, and the current token matched none of these. Input at fault is a calc() expression containing an unexpected token, e.g. `calc("a" + 1)`.

Source

Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:3296

                expect!(self, "(");

                self.input.skip_ws();

                let mut calc_sum_in_parens: CalcSum = self.parse()?;

                self.input.skip_ws();

                expect!(self, ")");

                calc_sum_in_parens.span = span!(self, span.lo);

                Ok(CalcValue::Sum(calc_sum_in_parens))
            }
            tok!("function") => Ok(CalcValue::Function(self.parse()?)),
            _ => {
                let span = self.input.cur_span();

                return Err(Error::new(
                    span,
                    ErrorKind::Expected(
                        "'number', 'dimension', 'percentage', 'ident', '(' or 'function' tokens",
                    ),
                ));
            }
        }
    }
}

impl<I> Parse<FamilyName> for Parser<I>
where
    I: ParserInput,
{
    fn parse(&mut self) -> PResult<FamilyName> {
        match cur!(self) {
            tok!("string") => Ok(FamilyName::Str(self.parse()?)),
            tok!("ident") => {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Use a number, dimension, percentage, math constant, parenthesized sum, or math function as the operand
  2. Remove the invalid token from the calc expression
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:3296 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/9fb22c63acee2e71. Report an issue: GitHub.