{"record":{"id":"626d7c6ab841a823","repo":"swc-project/swc","slug":"expected-percentage-or-number-token","errorCode":null,"errorMessage":"Expected percentage or number token","messagePattern":"Expected percentage or number token","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/swc_css_parser/src/parser/values_and_units/mod.rs","lineNumber":2461,"sourceCode":"                    raw: Some(raw),\n                })\n            }\n            _ => {\n                unreachable!()\n            }\n        }\n    }\n}\n\nimpl<I> Parse<AlphaValue> for Parser<I>\nwhere\n    I: ParserInput,\n{\n    fn parse(&mut self) -> PResult<AlphaValue> {\n        if !is_one_of!(self, \"percentage\", \"number\") {\n            let span = self.input.cur_span();\n\n            return Err(Error::new(\n                span,\n                ErrorKind::Expected(\"percentage or number token\"),\n            ));\n        }\n\n        match cur!(self) {\n            tok!(\"percentage\") => Ok(AlphaValue::Percentage(self.parse()?)),\n            tok!(\"number\") => Ok(AlphaValue::Number(self.parse()?)),\n            _ => {\n                unreachable!()\n            }\n        }\n    }\n}\n\nimpl<I> Parse<Hue> for Parser<I>\nwhere\n    I: ParserInput,","sourceCodeStart":2443,"sourceCodeEnd":2479,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/values_and_units/mod.rs#L2443-L2479","documentation":"Thrown by Parse<AlphaValue> in swc_css_parser when an <alpha-value> is expected but the current token is neither a percentage nor a number. AlphaValue only accepts '50%' or '0.5' shapes (is_one_of!(self, \"percentage\", \"number\")); an ident like 'none' (on versions without none support), a keyword 'auto', a dimension ('50px'), or EOF in the alpha slot after '/' in modern color syntax fails here.","triggerScenarios":"'rgb(255 0 0 / auto)', 'hsl(120 50% 50% / none)' on an older parser, 'rgb(255 0 0 / 50px)', or a truncated 'rgb(255 0 0 /' at EOF where the alpha component is missing.","commonSituations":"Newer CSS 'none' alpha or variable alpha (var()) fed to an older swc_css_parser, and generated colors appending a non-numeric opacity unit.","solutions":["Use a number (0-1) or percentage for alpha: 'rgb(255 0 0 / 50%)'.","Remove alpha entirely if it should be opaque ('rgb(255 0 0)').","Upgrade swc_css_parser/swc_core if you need 'none' alpha support; otherwise resolve var() before parsing."],"exampleFix":"/* before */\na { color: rgb(255 0 0 / auto); }\n\n/* after */\na { color: rgb(255 0 0 / 100%); }","handlingStrategy":"validation","validationCode":"const ALPHA = /^-?(\\d+\\.?\\d*|\\.\\d+)%?$/;\nfunction isValidAlphaValue(v: string): boolean {\n  return ALPHA.test(v.trim());\n}","typeGuard":"fn is_alpha_literal(v: &str) -> bool {\n    let t = v.strip_suffix('%').unwrap_or(v);\n    t.parse::<f64>().is_ok()\n}","tryCatchPattern":"use swc_css_parser::error::ErrorKind;\nif let Err(e) = parse_input::<Stylesheet>(src, opts) {\n    if matches!(e.kind(), ErrorKind::Expected(\"percentage or number token\")) {\n        return Err(format!(\"bad alpha value at {:?}\", e.span()).into());\n    }\n    return Err(e.into());\n}","preventionTips":["Serialize alpha as 0..1 number or percentage; never keywords.","If you need 'none' alpha or var(), upgrade swc_css_parser and verify support first.","Guard against EOF after '/' when concatenating color strings."],"tags":["css","swc","parser","color","alpha"],"backgroundTag":"css-invalid-alpha-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"}