swc-project/swc · error · Error

Expected a number

Error message

Expected a number

What it means

Fired while parsing an Integer node: the current token was not a Number token, which is required before an integer value can be produced. ErrorKind::ExpectedNumber is the sentinel for this validation guard; input at fault is any context expecting an integer that receives a different token, e.g. `z-index: auto 5x` style mismatches or a missing value.

Source

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

                    value: DelimiterValue::Semicolon,
                });
            }
            _ => {
                unreachable!();
            }
        }
    }
}

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

        if !is!(self, Number) {
            return Err(Error::new(span, ErrorKind::ExpectedNumber));
        }

        let value = bump!(self);

        match value {
            Token::Number {
                value,
                raw,
                type_flag,
                ..
            } => {
                if type_flag == NumberType::Number {
                    return Err(Error::new(span, ErrorKind::Expected("integer type")));
                }

                Ok(Integer {
                    span,
                    value: value.round() as i64,

View on GitHub (pinned to 5176682b65)

Solutions

  1. Provide a numeric literal where an integer is expected
  2. Remove quotes or units that turn the value into a non-number token
Defensive patterns

Strategy: type-guard

When it happens

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