{"record":{"id":"7e0e47096c80d34e","repo":"swc-project/swc","slug":"invalid-attribute-name","errorCode":null,"errorMessage":"Invalid attribute name","messagePattern":"Invalid attribute name","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"crates/swc_css_parser/src/parser/selectors/mod.rs","lineNumber":693,"sourceCode":"    I: ParserInput,\n{\n    fn parse(&mut self) -> PResult<AttributeSelector> {\n        let span = self.input.cur_span();\n\n        expect!(self, \"[\");\n\n        self.input.skip_ws();\n\n        let mut matcher = None;\n        let mut value = None;\n        let mut modifier = None;\n\n        let name = if let Ok(wq_name) = self.parse() {\n            wq_name\n        } else {\n            let span = self.input.cur_span();\n\n            return Err(Error::new(\n                span!(self, span.lo),\n                ErrorKind::InvalidAttrSelectorName,\n            ));\n        };\n\n        self.input.skip_ws();\n\n        if !is!(self, \"]\") {\n            matcher = Some(self.parse()?);\n\n            self.input.skip_ws();\n\n            value = Some(self.parse()?);\n\n            self.input.skip_ws();\n\n            if is!(self, Ident) {\n                modifier = Some(self.parse()?);","sourceCodeStart":675,"sourceCodeEnd":711,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_css_parser/src/parser/selectors/mod.rs#L675-L711","documentation":"Inside an attribute selector '[...]' the first thing after '[' (and optional whitespace) must be the attribute name, parsed as a WqName — an identifier with an optional namespace prefix. That parse failed, so the name slot does not hold a valid identifier: it is a number, string, delimiter, or a malformed namespaced name.","triggerScenarios":"'[=foo]' (name missing), '[\"data-foo\"]' (quoted name), '[123]' (numeric name), or '[ns|\"x\"]' — any attribute selector whose name token is not ident-shaped.","commonSituations":"Authors quoting the attribute name out of habit (only the VALUE may be quoted); templating that interpolates numeric attribute names; regex-built selectors where the name slot came out empty ('[=\"checked\"]').","solutions":["Write the name unquoted: '[data-foo=\"value\"]'","If the attribute name is exotic, escape it as an identifier instead of quoting: '[\\31 33=\"x\"]'","Check for a missing name between '[' and the matcher"],"exampleFix":"/* before */\n[\"data-foo\"=\"bar\"] { color: red; }\n/* after */\n[data-foo=\"bar\"] { color: red; }","handlingStrategy":"validation","validationCode":"// Attribute names: unquoted ident with optional ns prefix\nconst attrNameOk = /^(-?[_A-Za-z][\\w-]*|\\[0-9a-fA-F]{1,6} ?)(\\|(-?[_A-Za-z][\\w-]*|\\*))?$/;","typeGuard":null,"tryCatchPattern":"// JS\ntry { parseSelector(sel, opts); } catch (e) { if (/attribute name/.test(e.message)) report(`unquote or fix the attribute name in: ${sel}`); else throw e; }","preventionTips":["Never quote attribute NAMES (only values)","Route exotic attribute names through an identifier escaper"],"tags":["css","selector","attribute-selector","syntax"],"backgroundTag":"css-attribute-selector-syntax-error","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"}