swc-project/swc · error · Error
ident token
Error message
ident token
What it means
Thrown by swc_css_parser inside color(...) when the first parameter is not an identifier. That parameter must be a predefined color space ident (srgb, display-p3, a98-rgb, prophoto-rgb, rec2020, xyz, xyz-d50, xyz-d65 — unknown idents are deliberately tolerated because browsers fall back) or a dashed custom ident starting with '--'. Unlike the component slots, this arm errors unconditionally — the closure ignores has_variable_before (mod.rs:1318-1346).
Source
Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:1340
is_custom_params = true;
Ok(Some(ComponentValue::DashedIdent(parser.parse()?)))
} else {
if matches_eq_ignore_ascii_case!(value, "xyz", "xyz-d50", "xyz-d65")
{
is_xyz = true
} else {
// There are predefined-rgb-params , but
// For unknown, we don't return an error
// to
// continue to support invalid color,
// because they fallback in browser
}
Ok(Some(ComponentValue::Ident(parser.parse()?)))
}
}
_ => Err(Error::new(
parser.input.cur_span(),
ErrorKind::Expected("ident token"),
)),
},
&mut has_variable,
)?;
if let Some(ident) = ident {
values.push(ident);
}
self.input.skip_ws();
let number_or_percentage_or_none = self.try_parse_variable_function(
|parser, has_variable_before| match cur!(parser) {
tok!("number") => Ok(Some(ComponentValue::Number(parser.parse()?))),
tok!("percentage") if !is_xyz => {
Ok(Some(ComponentValue::Percentage(parser.parse()?)))View on GitHub (pinned to 5176682b65)
Solutions
- Write the color space as a bare, unquoted identifier: color(srgb 0 0 0).
- For ICC profiles use a dashed ident: color(--my-profile 0.5 0.2 0.2).
- If the space comes from a variable, use var(): color(var(--space) 0 0 0).
- Remove any nested function or literal that occupies the first parameter position.
Example fix
/* before */
color: color("srgb" 0 0 0);
/* after */
color: color(srgb 0 0 0); Defensive patterns
Strategy: validation
Validate before calling
fn color_space_ok(tok: &str) -> bool {
let t = tok.trim();
t.starts_with("--") || t.chars().all(|c| c.is_ascii_alphanumeric() || c == '-')
// must be a bare ident (predefined space or --custom), not number/string/hash/function
} Type guard
fn is_color_space_ident(tok: &str) -> bool {
let t = tok.trim();
!t.is_empty()
&& !t.starts_with('"')
&& !t.starts_with('#')
&& t.parse::<f64>().is_err()
&& !t.ends_with(')')
} Try / catch
Err(e) if matches!(e.kind(), swc_css_parser::error::ErrorKind::Expected(m) if m == "ident token") => {
let (span, _) = e.into_inner();
// color() first parameter at span must be a color space ident or --custom ident
} Prevention
- Always write the color() color space as an unquoted identifier: color(srgb 0 0 0).
- Use dashed idents for custom profiles: color(--profile 0 0 0).
- Never quote, number, or nest a function as the first color() parameter.
- Use var(--space) when the color space is dynamic.
When it happens
Trigger: `color(123 0 0 0)` — number as color space; `color("srgb" 0 0 0)` — quoted color space; `color(#fff 0 0 0)`; `color(rgb(0 0 0))` — a nested function where the space ident should be. `color(var(--space) 0 0 0)` is fine because var() is intercepted first.
Common situations: New color() syntax where authors quote the color space or forget it entirely; generated CSS that interpolates the space from a typed (non-ident) variable; copy-paste from examples that wrap the space in quotes.
Related errors
- percentage, functions (math functions) or ident (with 'none'
- number, functions (math functions) or ident (with 'none' val
- number, function (math functions) or ident (with 'none' valu
- number, dimension, functions (math functions) or ident (with
- percentage, number, functions (math functions) or ident (wit
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/62ff3d4f449657a2.
Report an issue: GitHub.