swc-project/swc · error · swc_css_parser::Error

Expected string, url or function tokens

Error message

Expected string, url or function tokens

What it means

Fired while parsing an @namespace at-rule prelude: the namespace URI was expected to be a string, a url(...) token, or a url(...) function form, but the current token matched none of them. This guard enforces the CSS Namespaces grammar (<string> | <url>) for the namespace URI; input like `@namespace svg http://www.w3.org/2000/svg;` (unquoted URI) triggers it.

Source

Thrown at crates/swc_css_parser/src/parser/at_rules/mod.rs:306

                if is!(self, Ident) {
                    prefix = match cur!(self) {
                        tok!("ident") => Some(self.parse()?),
                        _ => {
                            unreachable!()
                        }
                    };

                    self.input.skip_ws();
                }

                let uri = match cur!(self) {
                    tok!("string") => NamespacePreludeUri::Str(self.parse()?),
                    tok!("url") => NamespacePreludeUri::Url(self.parse()?),
                    tok!("function") => NamespacePreludeUri::Url(self.parse()?),
                    _ => {
                        let span = self.input.cur_span();

                        return Err(Error::new(
                            span,
                            ErrorKind::Expected("string, url or function tokens"),
                        ));
                    }
                };

                let prelude = AtRulePrelude::NamespacePrelude(NamespacePrelude {
                    span: span!(self, span.lo),
                    prefix,
                    uri: Box::new(uri),
                });

                self.input.skip_ws();

                Some(prelude)
            }
            "nest" => {
                self.input.skip_ws();

View on GitHub (pinned to 5176682b65)

Solutions

  1. Provide a valid string or url() namespace URI
  2. Report the collected error
  3. Remove the malformed @namespace rule
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_css_parser/src/parser/at_rules/mod.rs:306 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/63749ff9f5781c00. Report an issue: GitHub.