swc-project/swc · error · Error

Expected ident or str tokens

Error message

Expected ident or str tokens

What it means

Fired while parsing the `:lang()` pseudo-class argument: after the `lang` name, the parser expects a sequence of ident or string tokens representing language-range tags, but the current token was neither. Input at fault is a malformed :lang() such as `:lang()` with a non-string/non-ident argument.

Source

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

                            ));
                        }
                        "dir" => {
                            self.input.skip_ws();

                            let ident: Ident = self.parse()?;

                            self.input.skip_ws();

                            children.push(PseudoClassSelectorChildren::Ident(ident));
                        }
                        "lang" => {
                            self.input.skip_ws();

                            let child = match cur!(self) {
                                tok!("ident") => PseudoClassSelectorChildren::Ident(self.parse()?),
                                tok!("string") => PseudoClassSelectorChildren::Str(self.parse()?),
                                _ => {
                                    return Err(Error::new(
                                        span,
                                        ErrorKind::Expected("ident or str tokens"),
                                    ));
                                }
                            };

                            children.push(child);

                            loop {
                                self.input.skip_ws();

                                if is!(self, ",") {
                                    children.push(PseudoClassSelectorChildren::Delimiter(
                                        self.parse()?,
                                    ));

                                    self.input.skip_ws();
                                } else {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Pass an ident or quoted string to the pseudo-class
  2. Report the collected error
  3. Fix the selector syntax
Defensive patterns

Strategy: validation

When it happens

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