swc-project/swc · error · Error

Expected ident token

Error message

Expected ident token

What it means

Fired while parsing a CustomHighlightName (::highlight() name): the current token was not an Ident, so no valid custom highlight name could be read. The check `if !is!(self, Ident)` is a validation guard; input at fault is `::highlight()` or `::highlight(2foo)` where the argument is not an ident.

Source

Thrown at crates/swc_css_parser/src/parser/selectors/mod.rs:1435

                    b_raw,
                }))
            }
            _ => {
                return Err(Error::new(span, ErrorKind::InvalidAnPlusBMicrosyntax));
            }
        }
    }
}

impl<I> Parse<CustomHighlightName> for Parser<I>
where
    I: ParserInput,
{
    fn parse(&mut self) -> PResult<CustomHighlightName> {
        let span = self.input.cur_span();

        if !is!(self, Ident) {
            return Err(Error::new(span, ErrorKind::Expected("ident token")));
        }

        match bump!(self) {
            Token::Ident { value, raw, .. } => Ok(CustomHighlightName {
                span,
                value,
                raw: Some(raw),
            }),
            _ => {
                unreachable!()
            }
        }
    }
}

View on GitHub (pinned to 5176682b65)

Solutions

  1. Use an ident as the ::highlight name
  2. Report the collected error
  3. Fix the selector
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_css_parser/src/parser/selectors/mod.rs:1435 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/7f18f4000903cc1e. Report an issue: GitHub.