{"record":{"id":"6ee61215dac5023a","repo":"swc-project/swc","slug":"expected-known-named-color-or-transparent-keywor","errorCode":null,"errorMessage":"Expected known named color or 'transparent' keyword","messagePattern":"Expected known named color or 'transparent' keyword","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/swc_css_parser/src/parser/values_and_units/mod.rs","lineNumber":2396,"sourceCode":"            },\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();\n\n        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                ));","sourceCodeStart":2378,"sourceCodeEnd":2414,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/values_and_units/mod.rs#L2378-L2414","documentation":"Thrown by Parse<AbsoluteColorBase> in swc_css_parser when the token IS an ident but it is neither a CSS named color nor the keyword transparent. The impl checks is_named_color(value) || value == 'transparent' (case-insensitive); a typo'd or custom ident such as 'redd', 'primary', or 'grean' fails here with the ident's span.","triggerScenarios":"Typed color parsing of idents like 'color: redd', 'color: primary', 'color: currentColor' is fine but 'color: currentcolor2' fails, and CSS-variable-style names ('--brand' lexes as ident '--brand') in a typed color position.","commonSituations":"Typos in color keywords, design-token names used verbatim as color values, and assumptions that arbitrary idents fall back gracefully (they do not in typed color parsing).","solutions":["Correct the keyword to a real named color or 'transparent'.","Replace token names with their resolved values (#hex or rgb()) before parsing.","If unknown idents must pass through, parse as generic component values instead of typed colors."],"exampleFix":"/* before */\na { color: redd; }\n\n/* after */\na { color: red; }","handlingStrategy":"validation","validationCode":"import namedColors from 'css-named-colors'; // any full list\nfunction isNamedColorOrTransparent(v: string): boolean {\n  const s = v.trim().toLowerCase();\n  return s === 'transparent' || namedColors.has(s);\n}","typeGuard":"fn is_named_color_or_transparent(v: &str) -> bool {\n    v.eq_ignore_ascii_case(\"transparent\") || is_named_color(&v.to_ascii_lowercase().into()) // swc's own list via swc_css_utils\n}","tryCatchPattern":"use swc_css_parser::error::ErrorKind;\nif let Err(e) = parse_input::<Stylesheet>(src, opts) {\n    if matches!(e.kind(), ErrorKind::Expected(\"known named color or 'transparent' keyword\")) {\n        return Err(format!(\"unknown color name at {:?}\", e.span()).into());\n    }\n    return Err(e.into());\n}","preventionTips":["Validate color names against the CSS named-color list before emitting CSS.","Treat design-token names as unresolvable by the parser; substitute values at build time.","Lint for common misspellings (redd, grean, bleu) in fixture corpora."],"tags":["css","swc","parser","color","named-color"],"backgroundTag":"css-unknown-named-color","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"}