swc-project/swc · error · Error

Expected Num

Error message

Expected Num

What it means

Fired while parsing the An+B microsyntax: after the `n` part the parser handled a '+' or '-' delim that must be followed by a signless integer forming the `b` component, but the next token was not a number. Input at fault is an expression like `:nth-child(2n +)` or `:nth-child(2n - x)` with no integer after the sign.

Source

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

                        b_raw = Some(self.input.atom(b_raw_str));
                    }
                    // '+'? n ['+' | '-'] <signless-integer>
                    // -n ['+' | '-'] <signless-integer>
                    // <n-dimension> ['+' | '-'] <signless-integer>
                    tok!("-") | tok!("+") => {
                        let (b_sign, b_sign_raw) = match bump!(self) {
                            Token::Delim { value, .. } => (if value == '-' { -1 } else { 1 }, value),
                            _ => {
                                unreachable!();
                            }
                        };

                        self.input.skip_ws();

                        let number = match bump!(self) {
                            Token::Number { value, raw, .. } => (value, raw),
                            _ => {
                                return Err(Error::new(span, ErrorKind::Expected("Num")));
                            }
                        };

                        b = Some(b_sign * number.0 as i32);

                        let mut b_raw_str = String::new();

                        b_raw_str.push(' ');
                        b_raw_str.push(b_sign_raw);
                        b_raw_str.push(' ');
                        b_raw_str.push_str(&number.1);
                        b_raw = Some(self.input.atom(b_raw_str));
                    }
                    // '+'? <ndashdigit-ident>
                    // <dashndashdigit-ident>
                    // <ndashdigit-dimension>
                    _ if dash_after_n == Some('-') => {
                        let b_from_ident = &n_value[2..];

View on GitHub (pinned to 5176682b65)

Solutions

  1. Provide a signless integer after the +/- sign
  2. Surface the parse error
  3. Fix the An+B syntax
Defensive patterns

Strategy: validation

When it happens

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