From 414e66910dc5d9fea254811618f69067ab4a7a67 Mon Sep 17 00:00:00 2001 From: Marvin Hagemeister Date: Mon, 3 Apr 2023 00:14:29 +0200 Subject: [PATCH] fix(es/parser): Fix infinite loop on jsx in js (#7191) --- crates/swc_ecma_parser/src/parser/stmt.rs | 4 +++ .../tests/errors/jsx_in_js/input.js | 5 +++ .../errors/jsx_in_js/input.js.swc-stderr | 32 +++++++++++++++++++ 3 files changed, 41 insertions(+) create mode 100644 crates/swc_ecma_parser/tests/errors/jsx_in_js/input.js create mode 100644 crates/swc_ecma_parser/tests/errors/jsx_in_js/input.js.swc-stderr diff --git a/crates/swc_ecma_parser/src/parser/stmt.rs b/crates/swc_ecma_parser/src/parser/stmt.rs index d6a9b82692bb..cc8160ad3dfd 100644 --- a/crates/swc_ecma_parser/src/parser/stmt.rs +++ b/crates/swc_ecma_parser/src/parser/stmt.rs @@ -845,6 +845,10 @@ impl<'a, I: Tokens> Parser { while !eat!(self, ';') { bump!(self); + + if let Some(Token::Error(_)) = self.input.cur() { + break; + } } } diff --git a/crates/swc_ecma_parser/tests/errors/jsx_in_js/input.js b/crates/swc_ecma_parser/tests/errors/jsx_in_js/input.js new file mode 100644 index 000000000000..00d7e01ada4e --- /dev/null +++ b/crates/swc_ecma_parser/tests/errors/jsx_in_js/input.js @@ -0,0 +1,5 @@ +const a = ( +
+ foo +
+); diff --git a/crates/swc_ecma_parser/tests/errors/jsx_in_js/input.js.swc-stderr b/crates/swc_ecma_parser/tests/errors/jsx_in_js/input.js.swc-stderr new file mode 100644 index 000000000000..d7d08fa07e8a --- /dev/null +++ b/crates/swc_ecma_parser/tests/errors/jsx_in_js/input.js.swc-stderr @@ -0,0 +1,32 @@ + + x Unterminated regexp literal + ,-[$DIR/tests/errors/jsx_in_js/input.js:2:1] + 2 |
+ 3 | foo + : ^^^ + 4 |
+ `---- + + x Expression expected + ,-[$DIR/tests/errors/jsx_in_js/input.js:1:1] + 1 | const a = ( + 2 |
+ : ^ + 3 | foo + `---- + + x Expression expected + ,-[$DIR/tests/errors/jsx_in_js/input.js:2:1] + 2 |
+ 3 | foo + : ^ + 4 |
+ `---- + + x Expected a semicolon + ,-[$DIR/tests/errors/jsx_in_js/input.js:2:1] + 2 |
+ 3 | foo + : ^^^^ + 4 |
+ `----