{"record":{"id":"9957c49694cc81a2","repo":"swc-project/swc","slug":"expected-hash-ident-with-named-color-system-col","errorCode":null,"errorMessage":"Expected hash, ident (with named color, system color, 'transparent' or 'currentColor' value) or function (with color function name) token","messagePattern":"Expected hash, ident \\(with named color, system color, 'transparent' or 'currentColor' 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":2370,"sourceCode":"        let span = self.input.cur_span();\n\n        match cur!(self) {\n            // currentcolor | <system-color>\n            Token::Ident { value, .. }\n                if value.as_ref().eq_ignore_ascii_case(\"currentcolor\")\n                    || is_system_color(value) =>\n            {\n                Ok(Color::CurrentColorOrSystemColor(self.parse()?))\n            }\n            // <device-cmyk()>\n            Token::Function { value, .. } if value.as_ref().eq_ignore_ascii_case(\"device-cmyk\") => {\n                Ok(Color::Function(self.parse()?))\n            }\n            // <absolute-color-base>\n            _ => match self.parse() {\n                Ok(absolute_color_base) => Ok(Color::AbsoluteColorBase(absolute_color_base)),\n                Err(_) => {\n                    return Err(Error::new(\n                        span,\n                        ErrorKind::Expected(\n                            \"hash, ident (with named color, system color, 'transparent' or \\\n                             'currentColor' value) or function (with color function name) token\",\n                        ),\n                    ));\n                }\n            },\n        }\n    }\n}\n\nimpl<I> Parse<AbsoluteColorBase> for Parser<I>\nwhere\n    I: ParserInput,\n{\n    fn parse(&mut self) -> PResult<AbsoluteColorBase> {\n        let span = self.input.cur_span();","sourceCodeStart":2352,"sourceCodeEnd":2388,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/values_and_units/mod.rs#L2352-L2388","documentation":"Catch-all thrown by Parse<Color> in swc_css_parser after every <color> shape has been tried and failed: the token is not a hash, not an ident holding currentColor/transparent (or a named/system color), not a device-cmyk() function, and the inner AbsoluteColorBase parse also failed. The error span is the current token, captured before the attempts, and the message enumerates the accepted token kinds.","triggerScenarios":"Typed color parsing on tokens like a bare number ('color: 5'), a string, an unknown ident ('color: brandcolor'), or a function that is neither a color function nor device-cmyk (e.g. 'var(--brand)' on versions without var() support in typed color positions).","commonSituations":"User-defined theme variables passed where a literal <color> is required, typo'd color names, and newer syntax (relative colors, color-mix, none components) fed to an older swc_css_parser build.","solutions":["Use a literal the parser understands: hex (#fff), a named/system color, currentColor, transparent, or a standard color function (rgb(), hsl(), lab(), oklch(), color(), device-cmyk(), ...).","Resolve var() references at build time before handing the value to the parser, or upgrade swc_core/swc_css_parser so modern color syntax is supported.","Fix typos in color names ('brandcolor' -> a real named color).","If the position accepts arbitrary values, parse it as a component value rather than typed Color."],"exampleFix":"/* before */\na { color: brandcolor; }\n\n/* after */\na { color: crimson; }","handlingStrategy":"try-catch","validationCode":"const NAMED = /^(transparent)$/i; // in practice: full CSS named-color list\nconst COLOR_FN = /^(rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch|color|device-cmyk)\\(/i;\nfunction looksLikeColor(v: string): boolean {\n  const s = v.trim();\n  return /^#[0-9a-fA-F]{3,8}$/.test(s) || NAMED.test(s) || COLOR_FN.test(s);\n}","typeGuard":"fn is_literal_color(v: &str) -> bool {\n    let t = v.trim();\n    t.starts_with('#')\n        || t.eq_ignore_ascii_case(\"transparent\")\n        || t.ends_with(')') && t.contains('(') // function; refine with a color-function whitelist\n}","tryCatchPattern":"use swc_css_parser::error::ErrorKind;\nmatch parse_input::<Stylesheet>(src, opts) {\n    Ok(ast) => ast,\n    Err(e) if matches!(e.kind(), ErrorKind::Expected(_)) && e.message().contains(\"color\") => {\n        log::warn!(\"invalid color at {:?}: {}\", e.span(), e.message());\n        Stylesheet::default()\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Resolve var()/design-token indirections to literal colors before parsing.","Pin a recent swc_core / swc_css_parser version if you rely on modern color syntax (color-mix, relative colors, none).","Spell check color keywords against the CSS named-color list in linting."],"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"}