swc-project/swc · error

Expected math function token

Error message

Expected math function token

What it means

Fired by the CmykComponent parser: the current token must be a number, percentage, or function token for a CMYK color component, and when it is a function its name must be a math function; otherwise this error is reported.

Source

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

{
    fn parse(&mut self) -> PResult<CmykComponent> {
        if !is_one_of!(self, "number", "percentage", "function") {
            let span = self.input.cur_span();

            return Err(Error::new(
                span,
                ErrorKind::Expected("number, function or percentage token"),
            ));
        }

        match cur!(self) {
            tok!("number") => Ok(CmykComponent::Number(self.parse()?)),
            tok!("percentage") => Ok(CmykComponent::Percentage(self.parse()?)),
            Token::Function { value, .. } => {
                if !is_math_function(value) {
                    let span = self.input.cur_span();

                    return Err(Error::new(span, ErrorKind::Expected("math function token")));
                }

                Ok(CmykComponent::Function(self.parse()?))
            }
            _ => {
                unreachable!()
            }
        }
    }
}

impl<I> Parse<Percentage> for Parser<I>
where
    I: ParserInput,
{
    fn parse(&mut self) -> PResult<Percentage> {
        let span = self.input.cur_span();

View on GitHub (pinned to 5176682b65)

Solutions

  1. Use a number, percentage, or math function (calc, min, max, ...) for the CMYK component
  2. Fix typos in the component value
Defensive patterns

Strategy: validation

When it happens

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