swc-project/swc · error · Error
Expected dimension token
Error message
Expected dimension token
What it means
Fired while parsing a Dimension: the current token was not a Dimension token (a number with a unit, e.g. 10px), which is required to build a Dimension node. This `if !is!(self, Dimension)` check is a validation guard; input at fault is a length/angle/etc. position in input that receives a bare number, string, or other token.
Source
Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:1963
value,
raw: Some(raw),
}),
_ => {
unreachable!()
}
}
}
}
impl<I> Parse<Dimension> for Parser<I>
where
I: ParserInput,
{
fn parse(&mut self) -> PResult<Dimension> {
let span = self.input.cur_span();
if !is!(self, Dimension) {
return Err(Error::new(span, ErrorKind::Expected("dimension token")));
}
match cur!(self) {
Token::Dimension {
dimension: dimension_token,
} => {
match &dimension_token.unit {
// <length>
unit if is_length_unit(unit)
|| (self.ctx.in_container_at_rule && is_container_lengths_unit(unit)) =>
{
Ok(Dimension::Length(self.parse()?))
}
// <angle>
unit if is_angle_unit(unit) => Ok(Dimension::Angle(self.parse()?)),
// <time>
unit if is_time_unit(unit) => Ok(Dimension::Time(self.parse()?)),
// <frequency>View on GitHub (pinned to 5176682b65)
Solutions
- Provide a number with a unit (e.g. '10px', '2em')
- Use a plain number or percentage type if no unit was intended
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:1963 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/af3e5c76bd9dd3af.
Report an issue: GitHub.