swc-project/swc · error · SyntaxError

Invalid unicode escape

Error message

Invalid unicode escape

What it means

Lexing error raised inside read_int_u32 while accumulating digits of an integer literal: the running value overflows u32 (checked_mul/checked_add fail) and the closure returns an error spanned from the literal's start. It indicates the numeric literal in the source cannot be represented in 32 bits.

Source

Thrown at crates/swc_ecma_lexer/src/common/lexer/mod.rs:867

        };
        Ok(Either::Left((val, raw_str.into())))
    }

    fn read_int_u32<const RADIX: u8>(&mut self, len: u8) -> LexResult<Option<u32>> {
        let start = self.state().start();

        let mut count = 0;
        let v = self.read_digits::<_, Option<u32>, RADIX>(
            |opt: Option<u32>, radix, val| {
                count += 1;

                let total = opt
                    .unwrap_or_default()
                    .checked_mul(radix as u32)
                    .and_then(|v| v.checked_add(val))
                    .ok_or_else(|| {
                        let span = Span::new_with_checked(start, start);
                        crate::error::Error::new(span, SyntaxError::InvalidUnicodeEscape)
                    })?;

                Ok((Some(total), count != len))
            },
            true,
            &mut false,
        )?;
        if len != 0 && count != len {
            Ok(None)
        } else {
            Ok(v)
        }
    }

    /// Returns `Left(value)` or `Right(BigInt)`
    fn read_radix_number<const RADIX: u8>(
        &mut self,
    ) -> LexResult<Either<(f64, Atom), (Box<BigIntValue>, Atom)>> {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Fix the source so the numeric literal fits in a u32 (or drop the u32-specific parse path)
  2. Ensure the correct radix/scanner path is used for literals that may exceed u32
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at crates/swc_ecma_lexer/src/common/lexer/mod.rs:867 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/94c3e1a6ef9849a9. Report an issue: GitHub.