swc-project/swc · error · Error

Expected '--' at the start of dashed-ident

Error message

Expected '--' at the start of dashed-ident

What it means

Fired by the DashedIdent parser: an Ident token was found, but its value does not start with '--', so it is not a <dashed-ident>. Only identifiers beginning with two hyphens (custom-property style) are accepted.

Source

Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:1867

        }
    }
}

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

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

        match bump!(self) {
            Token::Ident { value, raw, .. } => {
                if !value.starts_with("--") {
                    return Err(Error::new(
                        span,
                        ErrorKind::Expected("'--' at the start of dashed-ident"),
                    ));
                }

                if value.len() < 3 {
                    return Err(Error::new(
                        span,
                        ErrorKind::Expected("dashed-ident must be at least 3 characters"),
                    ));
                }

                Ok(DashedIdent {
                    span,
                    value: self.input.atom(&value[2..]),
                    raw: Some(raw),
                })
            }

View on GitHub (pinned to 5176682b65)

Solutions

  1. Prefix the identifier with '--' (e.g. '--my-var')
  2. Use a plain Ident type if the double-dash prefix is not required
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_css_parser/src/parser/values_and_units/mod.rs:1867 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/4c2e820e94eba41a. Report an issue: GitHub.