{"record":{"id":"53d583de2ba8195b","repo":"swc-project/swc","slug":"expected-number-ident-dimension-or-function-toke","errorCode":null,"errorMessage":"Expected number, ident, dimension or function token","messagePattern":"Expected number, ident, dimension or function token","errorType":"validation","errorClass":"swc_css_parser::error::Error","httpStatus":null,"severity":"error","filePath":"crates/swc_css_parser/src/parser/at_rules/mod.rs","lineNumber":1917,"sourceCode":"                        left,\n                        right,\n                    }));\n                }\n\n                Ok(MediaFeatureValue::Number(left))\n            }\n            tok!(\"ident\") => {\n                let name: Ident = self.parse()?;\n\n                Ok(MediaFeatureValue::Ident(name))\n            }\n            tok!(\"dimension\") => Ok(MediaFeatureValue::Dimension(self.parse()?)),\n            Token::Function { value, .. } if is_math_function(value) => {\n                let function = self.parse()?;\n\n                Ok(MediaFeatureValue::Function(function))\n            }\n            _ => Err(Error::new(\n                span,\n                ErrorKind::Expected(\"number, ident, dimension or function token\"),\n            )),\n        }\n    }\n}\n\nimpl<I> Parse<PageSelectorList> for Parser<I>\nwhere\n    I: ParserInput,\n{\n    fn parse(&mut self) -> PResult<PageSelectorList> {\n        let selector: PageSelector = self.parse()?;\n        let mut selectors = vec![selector];\n\n        loop {\n            self.input.skip_ws();\n","sourceCodeStart":1899,"sourceCodeEnd":1935,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/at_rules/mod.rs#L1899-L1935","documentation":"Defines what a <media-feature-value> may be: a number, an identifier, a dimension, or a math function recognized by is_math_function (calc, min, max, clamp and friends). Any other token in the value slot of a feature raises ErrorKind::Expected(\"number, ident, dimension or function token\") at the feature's span.","triggerScenarios":"'@media (min-width: \"600px\")' (string), '@media (color: #fff)' (hash/color token), '@media (width: 10px, 5px)' (comma), '@media (prefers-color-scheme: rgb(0 0 0))' (non-math function).","commonSituations":"Values interpolated from JS without type conversion (sizes arriving as strings), attempts to use colors or var() references in media features, and copy-paste of declaration values into feature slots.","solutions":["Emit plain numbers/dimensions: @media (min-width: 600px)","Wrap arithmetic in a math function: @media (min-width: calc(100% - 2rem)) — percentages only inside math contexts","Keep colors and other typed values out of media features; use style queries or custom properties instead","When interpolating from JS, serialize numbers without quotes"],"exampleFix":"/* before */\n@media (min-width: \"600px\") { }\n\n/* after */\n@media (min-width: 600px) { }","handlingStrategy":"try-catch","validationCode":"fn feature_value_kind_ok(v: &str) -> bool {\n    let t = v.trim();\n    if t.starts_with('\"') || t.starts_with('#') || t.contains(',') {\n        return false;\n    }\n    if let Some(open) = t.find('(') {\n        let head = &t[..open];\n        return [\"calc\", \"min\", \"max\", \"clamp\"].iter().any(|f| head.eq_ignore_ascii_case(f));\n    }\n    t.parse::<f64>().is_ok() || t.chars().next().map_or(false, |c| c.is_ascii_alphabetic() || c == '-')\n}","typeGuard":"fn is_feature_value_error(e: &swc_css_parser::error::Error) -> bool {\n    matches!(e.kind(), swc_css_parser::error::ErrorKind::Expected(m) if *m == \"number, ident, dimension or function token\")\n}","tryCatchPattern":"match parse_file::<Stylesheet>(&fm, None, config, &mut errors) {\n    Ok(sheet) => handle(sheet),\n    Err(err) if is_feature_value_error(&err) => {\n        let (span, _) = *err.into_inner();\n        hint_at_span(css, span, \"media feature values accept number, ident, dimension, or calc/min/max/clamp — remove strings, colors, and commas\");\n    }\n    Err(err) => return Err(err.into()),\n}","preventionTips":["Serialize numeric values from JS/CSS-in-JS without quotes","Wrap arithmetic in calc()","Keep colors and var() references out of media features","Validate the value slot with a whitelist before emitting"],"tags":["css","swc","parser","at-rules","media-query","media-feature","values","syntax"],"backgroundTag":"css-media-feature-syntax","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"}