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

Expected {} digit

Error message

Expected {} digit

What it means

Lexer error from read_radix_number: after the radix prefix (0x/0o/0b) the scanner requires at least one digit, but none was read (or the required digit count was not met), so the radix literal is malformed. The span covers the digit region of the literal.

Source

Thrown at crates/swc_ecma_parser/src/lexer/mod.rs:1316

        let lazy_integer = self.read_number_no_dot_as_str::<RADIX>()?;
        let has_underscore = lazy_integer.has_underscore;

        let s = unsafe {
            // Safety: We got both start and end position from `self.input`
            self.input_slice_str(lazy_integer.start, self.cur_pos())
        };
        if self.eat(b'n') {
            if s.starts_with('_') {
                return Err(Error::new(
                    Span::new(lazy_integer.start, lazy_integer.end),
                    SyntaxError::NumericSeparatorIsAllowedOnlyBetweenTwoDigits,
                ));
            }

            let Some(bigint_value) = num_bigint::BigInt::parse_bytes(s.as_bytes(), RADIX as _)
            else {
                // just a fallback in case there is anything we did not catch
                return Err(Error::new(
                    Span::new(lazy_integer.start, lazy_integer.end),
                    SyntaxError::ExpectedDigit { radix: RADIX },
                ));
            };
            return Ok(Either::Right(Box::new(bigint_value)));
        }
        let s = remove_underscore(s, has_underscore);
        let val = parse_integer::<RADIX>(&s);

        self.ensure_not_ident()?;

        Ok(Either::Left(val))
    }

    /// Consume pending comments.
    ///
    /// This is called when the input is exhausted.
    #[cold]

View on GitHub (pinned to 5176682b65)

Solutions

  1. Add at least one valid digit after the radix prefix (0x1F, 0o7, 0b101)
  2. Remove the stray prefix if a plain number was intended
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_ecma_parser/src/lexer/mod.rs:1316 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/b43699985b67f345. Report an issue: GitHub.