swc-project/swc · error · Error
number, dimension, functions (math functions) or ident (with
Error message
number, dimension, functions (math functions) or ident (with 'none' value) token
What it means
Thrown by swc_css_parser when the hue (third) component of lch()/oklch() starts with a token that is not a number, dimension, math function, or ident. This catch-all arm is the only one in the group that uses `return Err(...)` (mod.rs:1186-1193); the span is the current token. Suppressed when a var() precedes it in the same color function.
Source
Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:1187
Ok(Some(ComponentValue::Function(parser.parse()?)))
}
tok!("ident") => {
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 {
return Err(Error::new(
parser.input.cur_span(),
ErrorKind::Expected(
"number, dimension, functions (math \
functions) or ident (with 'none' value) token",
),
));
} else {
Ok(None)
}
}
},
&mut has_variable,
)?;
if let Some(hue_or_none) = hue_or_none {
values.push(hue_or_none);
}
View on GitHub (pinned to 5176682b65)
Solutions
- Provide hue as number/angle or via a math function: oklch(70% 0.1 120) or oklch(70% 0.1 calc(120deg * 2)).
- Remove commas: lch(50% 10 30).
- Unquote interpolated numeric values.
- Wrap dynamic hue in var().
Example fix
/* before */ color: oklch(70% 0.1 "120"); /* after */ color: oklch(70% 0.1 120);
Defensive patterns
Strategy: try-catch
Validate before calling
fn lch_hue_token_ok(tok: &str) -> bool {
let t = tok.trim();
t.eq_ignore_ascii_case("none")
|| t.parse::<f64>().is_ok()
|| is_angle_or_number(t)
|| is_math_fn(t)
} Type guard
fn hue_is_unquoted(t: &str) -> bool {
!t.trim().starts_with('"') && !t.trim().starts_with('\'')
} Try / catch
if let Err(e) = swc_css_parser::parse_file::<swc_css_ast::Stylesheet>(&fm, None, config, &mut errs) {
if let swc_css_parser::error::ErrorKind::Expected(m) = e.kind() {
if m.starts_with("number, dimension, functions") {
// bad hue token in lch/oklch at e span; recover and report
}
}
} Prevention
- Never quote hue values produced by templating.
- Strip commas when converting legacy color syntax.
- Reject nested non-math functions in the hue slot during lint.
- Feed dynamic hue through var().
When it happens
Trigger: `oklch(70% 0.1 "120")` — hue given as a string; `lch(50% 10, 30)` — legacy comma reaching the hue slot; `lch(50% 10 #fff)`; `oklch(70% 0.1 rgb(0 0 0))` — a non-math function in the hue slot.
Common situations: Mechanical conversion from comma-separated syntax; string interpolation of hue values; nesting a color function where a hue is expected.
Related errors
- number, functions (math functions) or ident (with 'none' val
- percentage, functions (math functions) or ident (with 'none'
- number, function (math functions) or ident (with 'none' valu
- percentage, number, functions (math functions) or ident (wit
- ident token
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/3b6983b656ac1d89.
Report an issue: GitHub.