{"record":{"id":"0f27660866f2f2a5","repo":"swc-project/swc","slug":"number-functions-math-functions-or-ident-with","errorCode":null,"errorMessage":"number, functions (math functions) or ident (with 'none' value) token","messagePattern":"number, functions \\(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":1024,"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, functions (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":1006,"sourceCodeEnd":1042,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/values_and_units/mod.rs#L1006-L1042","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","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()."],"exampleFix":"/* before */\ncolor: lab(50%, 10, 20);\n\n/* after */\ncolor: lab(50% 10 20);","handlingStrategy":"try-catch","validationCode":"fn modern_color_commas_removed(css: &str) -> bool {\n    !css.split_whitespace().any(|t| t.starts_with(\"lab(\") && t.contains(','))\n    // or proactively: css.replace() commas inside lab()/lch()/oklab()/oklch()\n}","typeGuard":"fn is_space_separated_color_fn(v: &str) -> bool {\n    !v.contains(',')\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, functions\")) => {\n        // comma/stray token in lab second slot; log span and skip declaration\n    }\n    _ => {}\n}","preventionTips":["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."],"tags":["css","swc","parser","color","lab","oklab","lch","oklch","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-14T05:17:10.506Z"}