From dda9c2edceca6201a6795a216385247afa48af72 Mon Sep 17 00:00:00 2001 From: Boshen Date: Thu, 6 Apr 2023 20:59:49 +0800 Subject: [PATCH] fix(paresr): parse [+In] in template relates #255 --- crates/oxc_parser/src/js/expression.rs | 8 ++++++-- crates/oxc_parser/src/lib.rs | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/oxc_parser/src/js/expression.rs b/crates/oxc_parser/src/js/expression.rs index 81bd236667f0..72e37eea35b5 100644 --- a/crates/oxc_parser/src/js/expression.rs +++ b/crates/oxc_parser/src/js/expression.rs @@ -349,7 +349,9 @@ impl<'a> Parser<'a> { } Kind::TemplateHead => { quasis.push(self.parse_template_element(tagged)); - expressions.push(self.parse_expression()?); + // TemplateHead Expression[+In, ?Yield, ?Await] + let expr = self.with_context(Context::In, Self::parse_expression)?; + expressions.push(expr); self.re_lex_template_substitution_tail(); loop { match self.cur_kind() { @@ -362,7 +364,9 @@ impl<'a> Parser<'a> { quasis.push(self.parse_template_element(tagged)); } _ => { - expressions.push(self.parse_expression()?); + // TemplateMiddle Expression[+In, ?Yield, ?Await] + let expr = self.with_context(Context::In, Self::parse_expression)?; + expressions.push(expr); self.re_lex_template_substitution_tail(); } } diff --git a/crates/oxc_parser/src/lib.rs b/crates/oxc_parser/src/lib.rs index b8cc2dc2e522..71f3c94aa9e3 100644 --- a/crates/oxc_parser/src/lib.rs +++ b/crates/oxc_parser/src/lib.rs @@ -291,6 +291,7 @@ mod test { "null?async():null", "switch(null){case async():}", "for(new null(null in null);;);", + "for(`${null in null}`;;);", ]; for source in pass {