swc-project/swc · error · Error
number, functions (math functions) or ident (with 'none' val
Error message
number, functions (math functions) or ident (with 'none' value) token
What it means
Thrown by swc_css_parser when the SECOND component of lab()/lch()/oklab()/oklch() begins with a token that is not a percentage, number, math function, or ident. The current token hits the catch-all arm; the error span (parser.input.cur_span()) points at the offending token. Like the other catch-all arms here, it is skipped when has_variable_before is true, i.e. a preceding var() makes the parser stop the component list instead of erroring.
Source
Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:1024
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, functions (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 modern syntax: lab(50% 10 20).
- Strip quotes around numeric tokens coming from templating: lab(50% 10 20) not lab(50% "10" 20).
- If commas must be supported in input, preprocess/normalize color functions before parsing.
- For dynamic components, wrap 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 modern_color_commas_removed(css: &str) -> bool {
!css.split_whitespace().any(|t| t.starts_with("lab(") && t.contains(','))
// or proactively: css.replace() commas inside lab()/lch()/oklab()/oklch()
} Type guard
fn is_space_separated_color_fn(v: &str) -> bool {
!v.contains(',')
} 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, functions")) => {
// comma/stray token in lab second slot; log span and skip declaration
}
_ => {}
} Prevention
- Convert any legacy comma syntax to modern space-separated form in a preprocessing pass.
- Ensure codegen emits unquoted numeric channels.
- Reject strings and hash tokens in component slots during linting.
- Use the recoverable errors vector for untrusted CSS so one bad color does not abort the file.
When it happens
Trigger: `lab(50%, 10, 20)` — legacy comma syntax: after parsing 50% the next token is the ',' delimiter; `lab(50% "10" 20)` — a string; `lab(50% #aaa 20)` — a hash token; `lab(50% url(x) 20)` — a non-math function.
Common situations: Color values converted from older rgb(a,b,c)-style generators that keep commas; CSS authored against pre-Color-4 docs; toolchains (SCSS functions, design-token compilers) emitting comma-separated lab values.
Related errors
- number, function (math functions) or ident (with 'none' valu
- number, dimension, functions (math functions) or ident (with
- percentage, functions (math functions) or ident (with 'none'
- 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/0f27660866f2f2a5.
Report an issue: GitHub.