{"record":{"id":"62ff3d4f449657a2","repo":"swc-project/swc","slug":"ident-token","errorCode":null,"errorMessage":"ident token","messagePattern":"ident token","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/swc_css_parser/src/parser/values_and_units/mod.rs","lineNumber":1340,"sourceCode":"                                is_custom_params = true;\n\n                                Ok(Some(ComponentValue::DashedIdent(parser.parse()?)))\n                            } else {\n                                if matches_eq_ignore_ascii_case!(value, \"xyz\", \"xyz-d50\", \"xyz-d65\")\n                                {\n                                    is_xyz = true\n                                } else {\n                                    // There are predefined-rgb-params , but\n                                    // For unknown, we don't return an error\n                                    // to\n                                    // continue to support invalid color,\n                                    // because they fallback in browser\n                                }\n\n                                Ok(Some(ComponentValue::Ident(parser.parse()?)))\n                            }\n                        }\n                        _ => Err(Error::new(\n                            parser.input.cur_span(),\n                            ErrorKind::Expected(\"ident token\"),\n                        )),\n                    },\n                    &mut has_variable,\n                )?;\n\n                if let Some(ident) = ident {\n                    values.push(ident);\n                }\n\n                self.input.skip_ws();\n\n                let number_or_percentage_or_none = self.try_parse_variable_function(\n                    |parser, has_variable_before| match cur!(parser) {\n                        tok!(\"number\") => Ok(Some(ComponentValue::Number(parser.parse()?))),\n                        tok!(\"percentage\") if !is_xyz => {\n                            Ok(Some(ComponentValue::Percentage(parser.parse()?)))","sourceCodeStart":1322,"sourceCodeEnd":1358,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/values_and_units/mod.rs#L1322-L1358","documentation":"Thrown by swc_css_parser inside color(...) when the first parameter is not an identifier. That parameter must be a predefined color space ident (srgb, display-p3, a98-rgb, prophoto-rgb, rec2020, xyz, xyz-d50, xyz-d65 — unknown idents are deliberately tolerated because browsers fall back) or a dashed custom ident starting with '--'. Unlike the component slots, this arm errors unconditionally — the closure ignores has_variable_before (mod.rs:1318-1346).","triggerScenarios":"`color(123 0 0 0)` — number as color space; `color(\"srgb\" 0 0 0)` — quoted color space; `color(#fff 0 0 0)`; `color(rgb(0 0 0))` — a nested function where the space ident should be. `color(var(--space) 0 0 0)` is fine because var() is intercepted first.","commonSituations":"New color() syntax where authors quote the color space or forget it entirely; generated CSS that interpolates the space from a typed (non-ident) variable; copy-paste from examples that wrap the space in quotes.","solutions":["Write the color space as a bare, unquoted identifier: color(srgb 0 0 0).","For ICC profiles use a dashed ident: color(--my-profile 0.5 0.2 0.2).","If the space comes from a variable, use var(): color(var(--space) 0 0 0).","Remove any nested function or literal that occupies the first parameter position."],"exampleFix":"/* before */\ncolor: color(\"srgb\" 0 0 0);\n\n/* after */\ncolor: color(srgb 0 0 0);","handlingStrategy":"validation","validationCode":"fn color_space_ok(tok: &str) -> bool {\n    let t = tok.trim();\n    t.starts_with(\"--\") || t.chars().all(|c| c.is_ascii_alphanumeric() || c == '-')\n    // must be a bare ident (predefined space or --custom), not number/string/hash/function\n}","typeGuard":"fn is_color_space_ident(tok: &str) -> bool {\n    let t = tok.trim();\n    !t.is_empty()\n        && !t.starts_with('\"')\n        && !t.starts_with('#')\n        && t.parse::<f64>().is_err()\n        && !t.ends_with(')')\n}","tryCatchPattern":"Err(e) if matches!(e.kind(), swc_css_parser::error::ErrorKind::Expected(m) if m == \"ident token\") => {\n    let (span, _) = e.into_inner();\n    // color() first parameter at span must be a color space ident or --custom ident\n}","preventionTips":["Always write the color() color space as an unquoted identifier: color(srgb 0 0 0).","Use dashed idents for custom profiles: color(--profile 0 0 0).","Never quote, number, or nest a function as the first color() parameter.","Use var(--space) when the color space is dynamic."],"tags":["css","swc","parser","color","color-function","color-space","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-14T00:17:10.932Z"}