{"record":{"id":"3dba3c467e4eae0d","repo":"swc-project/swc","slug":"percentage-functions-math-functions-or-ident-w","errorCode":null,"errorMessage":"percentage, functions (math functions) or ident (with 'none' value) token","messagePattern":"percentage, 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":975,"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                                                    \"percentage, functions (math functions) or \\\n                                                     ident (with 'none' value) token\",\n                                                ),\n                                            ))\n                                        } else {\n                                            Ok(None)\n                                        }\n                                    }\n                                },\n                                &mut has_variable,\n                            )?;\n\n                            if let Some(percentage_or_none) = percentage_or_none {\n                                values.push(percentage_or_none);\n                            }\n","sourceCodeStart":957,"sourceCodeEnd":993,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/values_and_units/mod.rs#L957-L993","documentation":"Thrown by swc_css_parser when the SECOND component (whiteness) of hwb() starts with a token that is not a percentage, math function, or ident. The current token falls through to the catch-all arm, which errors with the span of parser.input.cur_span() — the exact offending token. Suppressed only when a var() custom-property reference appeared earlier in this color function (has_variable_before), in which case the component list ends gracefully with Ok(None).","triggerScenarios":"`hwb(0, 50%, 30%)` — a comma after the hue reaches the whiteness slot and is a delimiter token; `hwb(0 \"50%\" 30%)` — a string; `hwb(0 url(x) 30%)`; `hwb(0 #fff 30%)` — a hash token.","commonSituations":"Copy-pasting legacy comma-separated syntax into the modern space-separated hwb form; string values interpolated by templating languages; CSS minifiers re-serializing colors incorrectly.","solutions":["Remove the comma and use space-separated modern syntax: hwb(0 50% 30%).","If the token is a string/number-with-unit, convert it to a bare percentage: hwb(0 50% 30%) not hwb(0 \"50%\" 30%).","For dynamic values, wrap in var(): hwb(0 var(--w) 30%).","Report the error using its span — it marks the offending token precisely."],"exampleFix":"/* before */\ncolor: hwb(0, 50%, 30%);\n\n/* after */\ncolor: hwb(0 50% 30%);","handlingStrategy":"try-catch","validationCode":"// Normalize before parsing: reject/rewrite commas inside hwb()\nfn normalize_hwb(v: &str) -> String { v.replace(\",\", \" \") }","typeGuard":"fn hwb_uses_modern_syntax(v: &str) -> bool {\n    let inner = v.trim_start_matches(\"hwb(\").trim_end_matches(')');\n    !inner.contains(',')\n}","tryCatchPattern":"if let Err(e) = swc_css_parser::parse_file::<swc_css_ast::Stylesheet>(&fm, None, config, &mut errs) {\n    if let swc_css_parser::error::ErrorKind::Expected(m) = e.kind() {\n        if m.starts_with(\"percentage, functions\") {\n            // unexpected token in hwb() component; recover by skipping the declaration\n        }\n    }\n}","preventionTips":["Normalize legacy comma-separated color functions to space-separated form before parsing.","Unquote any interpolated numeric tokens.","Add fixture tests for hwb variants your pipeline emits.","Collect recoverable errors via the errors vector instead of failing the whole build."],"tags":["css","swc","parser","color","hwb","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"}