{"record":{"id":"e4fc389ffbed5d9a","repo":"swc-project/swc","slug":"number-function-math-functions-or-ident-with","errorCode":null,"errorMessage":"number, function (math functions) or ident (with 'none' value) token","messagePattern":"number, function \\(math functions\\) or ident \\(with 'none' value\\) token","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/swc_css_parser/src/parser/values_and_units/mod.rs","lineNumber":1141,"sourceCode":"                                        Ok(Some(ComponentValue::Function(parser.parse()?)))\n                                    }\n                                    tok!(\"ident\") => {\n                                        let ident: Box<Ident> = parser.parse()?;\n\n                                        if ident.value.eq_ignore_ascii_case(\"none\") {\n                                            Ok(Some(ComponentValue::Ident(ident)))\n                                        } else {\n                                            Err(Error::new(\n                                                ident.span,\n                                                ErrorKind::Expected(\n                                                    \"'none' value of an ident token\",\n                                                ),\n                                            ))\n                                        }\n                                    }\n                                    _ => {\n                                        if !has_variable_before {\n                                            Err(Error::new(\n                                                parser.input.cur_span(),\n                                                ErrorKind::Expected(\n                                                    \"number, function (math functions) or ident \\\n                                                     (with 'none' value) token\",\n                                                ),\n                                            ))\n                                        } else {\n                                            Ok(None)\n                                        }\n                                    }\n                                },\n                                &mut has_variable,\n                            )?;\n\n                            if let Some(number_or_none) = number_or_none {\n                                values.push(number_or_none);\n                            }\n","sourceCodeStart":1123,"sourceCodeEnd":1159,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/values_and_units/mod.rs#L1123-L1159","documentation":"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.","triggerScenarios":"`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.","commonSituations":"Comma-separated lab values from older tooling; stray trailing commas from generated CSS; interpolated strings.","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()."],"exampleFix":"/* before */\ncolor: lab(50% 10, 20);\n\n/* after */\ncolor: lab(50% 10 20);","handlingStrategy":"try-catch","validationCode":"fn lab_third_token_ok(tok: &str) -> bool {\n    let t = tok.trim();\n    t.eq_ignore_ascii_case(\"none\")\n        || t.parse::<f64>().is_ok()\n        || (t.ends_with('%') && t[..t.len() - 1].parse::<f64>().is_ok())\n        || is_math_fn(t)\n}","typeGuard":"fn no_trailing_comma(v: &str) -> bool {\n    !v.trim_end_matches(')').trim().ends_with(',')\n}","tryCatchPattern":"match swc_css_parser::parse_file::<swc_css_ast::Stylesheet>(&fm, None, config, &mut errs) {\n    Err(e) if matches!(e.kind(), swc_css_parser::error::ErrorKind::Expected(m) if m.starts_with(\"number, function\")) => {\n        // stray token in lab/oklab third slot; log span, skip declaration\n    }\n    _ => {}\n}","preventionTips":["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."],"tags":["css","swc","parser","color","lab","oklab","legacy-comma","syntax"],"backgroundTag":"css-unexpected-token","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}