swc-project/swc · error · Error
number, function (math functions) or ident (with 'none' valu
Error message
number, function (math functions) or ident (with 'none' value) token
What it means
Thrown by swc_css_parser when the THIRD component (b-axis) of lab()/oklab() begins with an unexpected token — anything that is not a percentage, number, math function, or ident. The catch-all arm (mod.rs:1139-1151) reports the expected-token message with the current token's span; a preceding var() suppresses it by ending the component list.
Source
Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:1141
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 {
Err(Error::new(
parser.input.cur_span(),
ErrorKind::Expected(
"number, function (math functions) or ident \
(with 'none' value) token",
),
))
} else {
Ok(None)
}
}
},
&mut has_variable,
)?;
if let Some(number_or_none) = number_or_none {
values.push(number_or_none);
}
View on GitHub (pinned to 5176682b65)
Solutions
- Use space-separated components: lab(50% 10 20).
- Remove trailing commas before the closing parenthesis.
- Ensure nested functions are real math functions (calc, min, max, clamp, round, ...) — arbitrary functions are rejected in this slot.
- Wrap dynamic values in var().
Example fix
/* before */ color: lab(50% 10, 20); /* after */ color: lab(50% 10 20);
Defensive patterns
Strategy: try-catch
Validate before calling
fn lab_third_token_ok(tok: &str) -> bool {
let t = tok.trim();
t.eq_ignore_ascii_case("none")
|| t.parse::<f64>().is_ok()
|| (t.ends_with('%') && t[..t.len() - 1].parse::<f64>().is_ok())
|| is_math_fn(t)
} Type guard
fn no_trailing_comma(v: &str) -> bool {
!v.trim_end_matches(')').trim().ends_with(',')
} Try / catch
match swc_css_parser::parse_file::<swc_css_ast::Stylesheet>(&fm, None, config, &mut errs) {
Err(e) if matches!(e.kind(), swc_css_parser::error::ErrorKind::Expected(m) if m.starts_with("number, function")) => {
// stray token in lab/oklab third slot; log span, skip declaration
}
_ => {}
} Prevention
- Remove trailing commas inside color functions.
- Only nest recognized math functions in component slots.
- Normalize commas to spaces for lab/oklab in preprocessing.
- Test generated CSS against parser fixtures.
When it happens
Trigger: `lab(50% 10,)` — trailing comma before ')'; `lab(50% 10, 20)` — legacy commas; `lab(50% 10 "20")` — string; `lab(50% 10 calc-summ(1))` — a non-math function.
Common situations: Comma-separated lab values from older tooling; stray trailing commas from generated CSS; interpolated strings.
Related errors
- number, functions (math functions) or ident (with 'none' val
- percentage, functions (math functions) or ident (with 'none'
- number, dimension, functions (math functions) or ident (with
- 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/e4fc389ffbed5d9a.
Report an issue: GitHub.