swc-project/swc · error · Error
Expected function or ident tokens
Error message
Expected function or ident tokens
What it means
Fired at the end of pseudo-class selector parsing: a pseudo-class must be either a functional form (a Function token, parsed into name + children) or a simple ident; the current token was neither, so no PseudoClassSelector could be built. Input at fault is a `:` followed by a non-ident, non-function token, e.g. `: 5` or `:.`.
Source
Thrown at crates/swc_css_parser/src/parser/selectors/mod.rs:1064
name: Ident {
span: Span::new(fn_span.lo, fn_span.hi - BytePos(1)),
value: names.0,
raw: Some(names.1),
},
children: Some(children),
})
} else if is!(self, Ident) {
let name: Ident = self.parse()?;
Ok(PseudoClassSelector {
span: span!(self, span.lo),
name,
children: None,
})
} else {
let span = self.input.cur_span();
Err(Error::new(
span,
ErrorKind::Expected("function or ident tokens"),
))
}
}
}
impl<I> Parse<PseudoElementSelector> for Parser<I>
where
I: ParserInput,
{
fn parse(&mut self) -> PResult<PseudoElementSelector> {
let span = self.input.cur_span();
expect!(self, ":");
expect!(self, ":");
if is!(self, Function) {View on GitHub (pinned to 5176682b65)
Solutions
- Write pseudo-classes as :ident or :function(args)
- Surface the diagnostic from the parse result
- Fix the selector
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/swc_css_parser/src/parser/selectors/mod.rs:1064 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/eec4d6785e3b010b.
Report an issue: GitHub.