{"record":{"id":"7abea286da01d2af","repo":"swc-project/swc","slug":"none-value-of-an-ident-token","errorCode":null,"errorMessage":"'none' value of an ident token","messagePattern":"'none' value of an ident token","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/swc_css_parser/src/parser/values_and_units/mod.rs","lineNumber":423,"sourceCode":"                    \"rgb\" | \"rgba\" => {\n                        let percentage_or_number_or_none = self.try_parse_variable_function(\n                            |parser, has_variable_before| match cur!(parser) {\n                                tok!(\"percentage\") => {\n                                    Ok(Some(ComponentValue::Percentage(parser.parse()?)))\n                                }\n                                tok!(\"number\") => Ok(Some(ComponentValue::Number(parser.parse()?))),\n                                Token::Function { value, .. } if is_math_function(value) => {\n                                    Ok(Some(ComponentValue::Function(parser.parse()?)))\n                                }\n                                tok!(\"ident\") => {\n                                    is_legacy_syntax = false;\n\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(\"'none' value of an ident token\"),\n                                        ))\n                                    }\n                                }\n                                _ => {\n                                    if !has_variable_before {\n                                        Err(Error::new(\n                                            parser.input.cur_span(),\n                                            ErrorKind::Expected(\n                                                \"percentage, number, function (math functions) or \\\n                                                 ident (with 'none' value) token\",\n                                            ),\n                                        ))\n                                    } else {\n                                        Ok(None)\n                                    }\n                                }","sourceCodeStart":405,"sourceCodeEnd":441,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/values_and_units/mod.rs#L405-L441","documentation":"Thrown by swc_css_parser while parsing the FIRST channel of an rgb()/rgba() function (crates/swc_css_parser/src/parser/values_and_units/mod.rs:415-428). When that channel is an identifier, CSS Color 4 allows only the keyword 'none' (matched with eq_ignore_ascii_case); any other word is a grammar violation and the parser returns ErrorKind::Expected(\"'none' value of an ident token\") with the span of the offending ident. Note this ident arm is unconditional, so it fires even in comma-style legacy syntax like rgb(red, 0, 0). The error only fires on literal tokens: if a var()/env()/constant() was consumed earlier, try_parse_variable_function returns Ok(None) instead of erroring.","triggerScenarios":"Calling swc_css_parser::parse_string (directly or via an swc-based minifier/transform) on CSS whose first rgb()/rgba() argument is a word that is not 'none': 'color: rgb(red 0 0)', 'rgb(red, 0, 0)', 'rgba(primary 25 50)'. The tok!(\"ident\") arm at line 415 sets is_legacy_syntax = false, parses the ident, and errors at ident.span when the value check at line 420 fails.","commonSituations":"Using a named color inside rgb() instead of as the color value itself; template interpolation that inserts a variable name ('primary') instead of a number into a generated rgb() string; porting Sass/older tooling that tolerated keyword channels; hand-written design-token CSS pasted from specs that use lab/oklch-style keyword examples.","solutions":["Replace the ident channel with a numeric channel: 'color: rgb(red 0 0)' -> 'color: rgb(255 0 0)', or just write 'color: red' since the keyword is already a valid color.","If you want keyword-derived channels, use relative color syntax: 'rgb(from red r g b)'.","For dynamic values pass them through var(): 'rgb(var(--ch) 0 0)' — the parser skips the strict grammar once a var() is seen.","Read err.kind()/err.message() and the span from err.into_inner().0 to pinpoint the exact ident in the source file."],"exampleFix":"/* before */\ncolor: rgb(red 0 0);\ncolor: rgb(red, 0, 0);\n\n/* after */\ncolor: red;\ncolor: rgb(255 0 0);\ncolor: rgb(from red r g b);","handlingStrategy":"try-catch","validationCode":"fn rgb_first_channel_ok(arg: &str) -> bool {\n    let a = arg.trim();\n    a.eq_ignore_ascii_case(\"none\")\n        || a.ends_with('%')\n        || a.parse::<f64>().is_ok()\n        || a.starts_with(\"var(\")\n        || a.starts_with(\"env(\")\n        || [\"calc\",\"min\",\"max\",\"clamp\"].iter().any(|f| a.starts_with(f))\n}\n// before emitting generated CSS:\nassert!(rgb_first_channel_ok(ch), \"rgb() first channel must be number/percentage/none, got {ch}\");","typeGuard":"fn is_valid_none_ident(ident: &swc_css_ast::Ident) -> bool {\n    ident.value.eq_ignore_ascii_case(\"none\")\n}","tryCatchPattern":"let parsed = swc_css_parser::parse_string::<swc_css_ast::Stylesheet>(css, config);\nif let Err(err) = parsed {\n    if matches!(&err.kind(), swc_css_parser::error::ErrorKind::Expected(m) if m.contains(\"'none' value of an ident token\")) {\n        let (span, _) = err.into_inner();\n        // report: rgb()/rgba() channel is a keyword; only 'none' is allowed, span points at it\n    }\n    return Err(err.into());\n}","preventionTips":["Never put named colors inside rgb()/rgba() channels; use them directly as the property value.","Validate generated color channels with a small checker (number, percentage, 'none', var(), math function) before string-building CSS.","Log err.message() plus the span from err.into_inner().0 so users of your tool see the exact offending word."],"tags":["css","swc","css-parser","rgb","color-function","none-keyword"],"backgroundTag":"css-color-function-none-keyword","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"}