{"record":{"id":"5eba61a8a69b77a3","repo":"swc-project/swc","slug":"failed-to-parse-number-as-char","errorCode":null,"errorMessage":"failed to parse number as char","messagePattern":"failed to parse number as char","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_lexer/src/common/lexer/mod.rs","lineNumber":998,"sourceCode":"                first = false;\n                c.is_ident_start()\n            } else {\n                c.is_ident_part() || c == '-'\n            }\n        });\n\n        Ok(Self::Token::jsx_name(slice, self))\n    }\n\n    fn read_jsx_entity(&mut self) -> LexResult<(char, String)> {\n        debug_assert!(self.syntax().jsx());\n\n        fn from_code(s: &str, radix: u32) -> LexResult<char> {\n            // TODO(kdy1): unwrap -> Err\n            let c = char::from_u32(\n                u32::from_str_radix(s, radix).expect(\"failed to parse string as number\"),\n            )\n            .expect(\"failed to parse number as char\");\n\n            Ok(c)\n        }\n\n        fn is_hex(s: &str) -> bool {\n            s.chars().all(|c| c.is_ascii_hexdigit())\n        }\n\n        fn is_dec(s: &str) -> bool {\n            s.chars().all(|c| c.is_ascii_digit())\n        }\n\n        let mut s = CompactString::default();\n\n        debug_assert!(self.input().cur().is_some_and(|c| c == b'&'));\n        self.bump();\n\n        let start_pos = self.input().cur_pos();","sourceCodeStart":980,"sourceCodeEnd":1016,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_lexer/src/common/lexer/mod.rs#L980-L1016","documentation":"In the JSX lexer's from_code helper (used by read_jsx_entity), the digits of a numeric JSX character reference (&#NNNN;) parsed as a number but char::from_u32 rejected the resulting code point — i.e. it falls in the surrogate range (0xD800-0xDFFF) or exceeds 0x10FFFF, so it is not a valid Unicode scalar. It fires while lexing a JSX entity containing such an invalid numeric escape.","triggerScenarios":"Thrown at crates/swc_ecma_lexer/src/common/lexer/mod.rs:998 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Use a valid scalar code point in the numeric entity (avoid surrogate ranges and values above 0x10FFFF)","Escape the desired character as a named entity instead of a numeric one","Sanitize unpaired-surrogate escapes in upstream tooling that generates JSX"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}