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

A numeric separator is only allowed between two digits

Error message

A numeric separator is only allowed between two digits

What it means

Lexer error from read_radix_number: a BigInt radix literal (e.g. 0x1_n) has a numeric separator '_' at the start of its digit string; separators are only permitted between two digits, so the underscore directly after the radix prefix is rejected.

Source

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

        );
        debug_assert_eq!(self.cur(), Some(b'0'));
        self.bump(1); // `0`

        debug_assert!(self
            .cur()
            .is_some_and(|c| matches!(c, b'b' | b'B' | b'o' | b'O' | b'x' | b'X')));
        self.bump(1); // `cur` matches one of the bytes above

        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);

View on GitHub (pinned to 5176682b65)

Solutions

  1. Remove the underscore adjacent to the radix prefix, e.g. write 0x1_n as 0x1n or 0x1_0n
  2. Place separators strictly between digits
Defensive patterns

Strategy: validation

When it happens

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