swc-project/swc · error · Error
Expected percentage, number, function (math functions) or id
Error message
Expected percentage, number, function (math functions) or ident (with 'none' value) token
What it means
Fired while parsing a color function component: expected a percentage, number, math function, or the ident 'none', but the current token is none of these (except that within device-cmyk the ident case is excluded). The component cannot be parsed into any accepted form.
Source
Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:1555
}
Token::Function { value, .. } if is_math_function(value) => {
Ok(Some(ComponentValue::Function(parser.parse()?)))
}
tok!("ident") if !matches!(&*lower_fname, "device-cmyk") => {
let ident: Box<Ident> = parser.parse()?;
if ident.value.eq_ignore_ascii_case("none") {
Ok(Some(ComponentValue::Ident(ident)))
} else {
Err(Error::new(
ident.span,
ErrorKind::Expected("'none' value of an ident token"),
))
}
}
_ => {
if !has_variable_before {
Err(Error::new(
parser.input.cur_span(),
ErrorKind::Expected(
"percentage, number, function (math functions) or \
ident (with 'none' value) token",
),
))
} else {
Ok(None)
}
}
},
&mut has_variable,
)?;
if let Some(alpha_value) = alpha_value {
values.push(alpha_value);
}
View on GitHub (pinned to 5176682b65)
Solutions
- Use a percentage or number for the channel value
- Use a math function (calc, min, max, ...) or 'none' where allowed
- Remove invalid identifiers from the component slot
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:1555 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/222047329d1bc7ba.
Report an issue: GitHub.