swc-project/swc · error
Expected percentage token
Error message
Expected percentage token
What it means
Fired while parsing a Percentage: the current token was not a Percentage token (e.g. 50%), which is required to build a Percentage node. This `if !is!(self, Percentage)` check is a validation guard; input at fault is a percentage-required context receiving a plain number or other token.
Source
Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:2542
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();
if !is!(self, Percentage) {
return Err(Error::new(span, ErrorKind::Expected("percentage token")));
}
match bump!(self) {
Token::Percentage { value, raw } => {
let value = Number {
span: Span::new(span.lo, span.hi - BytePos(1)),
value,
raw: Some(raw),
};
Ok(Percentage { span, value })
}
_ => {
unreachable!()
}
}
}
}View on GitHub (pinned to 5176682b65)
Solutions
- Add the '%' suffix to the number
- Use a Number or Dimension parser if a different value type was intended
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:2542 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/ea0651e422b06a63.
Report an issue: GitHub.