{"record":{"id":"a98aeb0a0f23b33b","repo":"swc-project/swc","slug":"expected-hash-ident-with-named-color-or-transpa","errorCode":null,"errorMessage":"Expected hash, ident (with named color or 'transparent' value) or function (with color function name) token","messagePattern":"Expected hash, ident \\(with named color or 'transparent' value\\) or function \\(with color function name\\) token","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/swc_css_parser/src/parser/values_and_units/mod.rs","lineNumber":2408,"sourceCode":"        match cur!(self) {\n            tok!(\"#\") => Ok(AbsoluteColorBase::HexColor(self.parse()?)),\n            Token::Ident { value, .. } => {\n                if !(is_named_color(value) || value.as_ref().eq_ignore_ascii_case(\"transparent\")) {\n                    let span = self.input.cur_span();\n\n                    return Err(Error::new(\n                        span,\n                        ErrorKind::Expected(\"known named color or 'transparent' keyword\"),\n                    ));\n                }\n\n                Ok(AbsoluteColorBase::NamedColorOrTransparent(self.parse()?))\n            }\n            Token::Function { value, .. } if is_absolute_color_base_function(value) => {\n                Ok(AbsoluteColorBase::Function(self.parse()?))\n            }\n            _ => {\n                return Err(Error::new(\n                    span,\n                    ErrorKind::Expected(\n                        \"hash, ident (with named color or 'transparent' value) or function (with \\\n                         color function name) token\",\n                    ),\n                ));\n            }\n        }\n    }\n}\n\nimpl<I> Parse<HexColor> for Parser<I>\nwhere\n    I: ParserInput,\n{\n    fn parse(&mut self) -> PResult<HexColor> {\n        let span = self.input.cur_span();\n","sourceCodeStart":2390,"sourceCodeEnd":2426,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/values_and_units/mod.rs#L2390-L2426","documentation":"Thrown by Parse<AbsoluteColorBase> in swc_css_parser when the current token is neither a hash, an ident, nor a color function. The match arms cover tok!('#'), Token::Ident, and Token::Function gated by is_absolute_color_base_function; anything else - a number ('10'), a string, a comma, an at-keyword, or EOF - falls to the final arm and reports this error with the pre-captured span.","triggerScenarios":"Typed absolute-color parsing on 'color: 5', 'color: \"red\"' (string token), 'rgb(255 0 0 /' followed by EOF, or an operator token where a color is expected (e.g. a malformed function argument list).","commonSituations":"Malformed function calls produced by string concatenation (missing hex/ident after a slash or comma), minified CSS truncated mid-value, and feed data where numbers appear in color slots.","solutions":["Put an actual color token (hex, named color ident, or color function) in the position.","Repair the surrounding syntax first (e.g. 'rgb(255 0 0 / 0.5)' not 'rgb(255 0 0 /)').","Validate that each color slot in generated CSS starts with '#', a letter, or a known function name."],"exampleFix":"/* before */\na { color: \"red\"; }\n\n/* after */\na { color: red; }","handlingStrategy":"try-catch","validationCode":"function colorSlotLooksValid(v: string): boolean {\n  const s = v.trim();\n  return s.length > 0 && (/^#/.test(s) || /^[a-zA-Z]/.test(s)); // hex, ident, or function\n}","typeGuard":"function isColorTokenStart(v: string): boolean {\n  const s = v.trim();\n  return s.startsWith('#') || /^[a-zA-Z][a-zA-Z0-9-]*\\(?/.test(s);\n}","tryCatchPattern":"use swc_css_parser::error::ErrorKind;\nmatch parse_input::<Stylesheet>(src, opts) {\n    Ok(ast) => ast,\n    Err(e) if e.message().contains(\"hash, ident\") => {\n        log::warn!(\"bad color token at {:?}\", e.span());\n        Stylesheet::default()\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Never wrap color values in quotes; strings are not color tokens.","Check for truncation when minifying/consuming streamed CSS (EOF mid-value lands here).","Build color function arguments with a helper that guarantees token order."],"tags":["css","swc","parser","color","token"],"backgroundTag":"css-invalid-color-value","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"}