From 59e29f286a15bab11f9364b182e3983142144a4f Mon Sep 17 00:00:00 2001 From: Boshen Date: Sat, 20 Jan 2024 23:03:44 +0800 Subject: [PATCH] chore(parser): explain the reason for omitting "}" and ">" in jsx text lexer (#2097) closes #2094 --- crates/oxc_parser/src/lexer/mod.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/oxc_parser/src/lexer/mod.rs b/crates/oxc_parser/src/lexer/mod.rs index e5a3b45eff780..0009de001dd4e 100644 --- a/crates/oxc_parser/src/lexer/mod.rs +++ b/crates/oxc_parser/src/lexer/mod.rs @@ -954,9 +954,11 @@ impl<'a> Lexer<'a> { } Some(_) => { loop { - // `>` and `}` are errors in TypeScript but not Babel - // let's make this less strict so we can parse more code - if matches!(self.peek(), Some('{' | '<')) { + // The tokens `{`, `<`, `>` and `}` cannot appear in a jsx text. + // The TypeScript compiler raises the error "Unexpected token. Did you mean `{'>'}` or `>`?". + // Where as the Babel compiler does not raise any errors. + // The following check omits `>` and `}` so that more Babel tests can be passed. + if self.peek().is_some_and(|c| c == '{' || c == '<') { break; } if self.current.chars.next().is_none() {