mirror of
https://github.com/danbulant/oxc
synced 2026-05-24 20:32:10 +00:00
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:
parent
68c01d304e
commit
b378e7ecc9
1 changed files with 17 additions and 13 deletions
|
|
@ -231,20 +231,24 @@ impl<'a> ParserImpl<'a> {
|
|||
) -> Result<JSXExpressionContainer<'a>> {
|
||||
let span = self.start_span();
|
||||
self.bump_any(); // bump `{`
|
||||
let expr = match self.cur_kind() {
|
||||
// {} empty
|
||||
Kind::RCurly => {
|
||||
let span = self.start_span();
|
||||
JSXExpression::EmptyExpression(self.ast.jsx_empty_expression(self.end_span(span)))
|
||||
}
|
||||
// {expr}
|
||||
_ => self.parse_jsx_assignment_expression().map(JSXExpression::Expression)?,
|
||||
};
|
||||
if in_jsx_child {
|
||||
self.expect_jsx_child(Kind::RCurly)?;
|
||||
|
||||
let expr = if self.eat(Kind::RCurly) {
|
||||
// Handle comment between curly braces (ex. `{/* comment */}`)
|
||||
// ^^^^^^^^^^^^^ span
|
||||
let span = self.end_span(span);
|
||||
JSXExpression::EmptyExpression(
|
||||
self.ast.jsx_empty_expression(Span::new(span.start + 1, span.end - 1)),
|
||||
)
|
||||
} 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))
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue