fix(parser): fix span for JSXEmptyExpression with comment (#2673)

[playground](https://oxc-project.github.io/oxc/playground/?code=3YCAAICVgICAgICAgICejwtjmCpbllbPawdM2eEFKwhGb62iFlQWu39yrLCA)

---------

Co-authored-by: Boshen <boshenc@gmail.com>
This commit is contained in:
Arnaud Barré 2024-03-11 11:50:33 +01:00 committed by GitHub
parent 68c01d304e
commit b378e7ecc9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -231,20 +231,24 @@ impl<'a> ParserImpl<'a> {
) -> Result<JSXExpressionContainer<'a>> { ) -> Result<JSXExpressionContainer<'a>> {
let span = self.start_span(); let span = self.start_span();
self.bump_any(); // bump `{` self.bump_any(); // bump `{`
let expr = match self.cur_kind() {
// {} empty let expr = if self.eat(Kind::RCurly) {
Kind::RCurly => { // Handle comment between curly braces (ex. `{/* comment */}`)
let span = self.start_span(); // ^^^^^^^^^^^^^ span
JSXExpression::EmptyExpression(self.ast.jsx_empty_expression(self.end_span(span))) let span = self.end_span(span);
} JSXExpression::EmptyExpression(
// {expr} self.ast.jsx_empty_expression(Span::new(span.start + 1, span.end - 1)),
_ => self.parse_jsx_assignment_expression().map(JSXExpression::Expression)?, )
};
if in_jsx_child {
self.expect_jsx_child(Kind::RCurly)?;
} else { } else {
self.expect(Kind::RCurly)?; let expr = self.parse_jsx_assignment_expression().map(JSXExpression::Expression)?;
} if in_jsx_child {
self.expect_jsx_child(Kind::RCurly)
} else {
self.expect(Kind::RCurly)
}?;
expr
};
Ok(self.ast.jsx_expression_container(self.end_span(span), expr)) Ok(self.ast.jsx_expression_container(self.end_span(span), expr))
} }