Skip to content

Commit

Permalink
fix(es/parser): Parse yield<T> (v: T)=>v
Browse files Browse the repository at this point in the history
  • Loading branch information
magic-akari committed Jan 24, 2025
1 parent 9d6fe37 commit d164f81
Showing 1 changed file with 23 additions and 24 deletions.
47 changes: 23 additions & 24 deletions crates/swc_ecma_parser/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,32 @@ impl<I: Tokens> Parser<I> {
pub(super) fn parse_assignment_expr(&mut self) -> PResult<Box<Expr>> {
trace_cur!(self, parse_assignment_expr);

if self.input.syntax().typescript() && self.input.syntax().jsx() {
if self.input.syntax().typescript() && is!(self, JSXTagStart) {
// Note: When the JSX plugin is on, type assertions (`<T> x`) aren't valid
// syntax.

if is!(self, JSXTagStart) {
let cur_context = self.input.token_context().current();
debug_assert_eq!(cur_context, Some(TokenContext::JSXOpeningTag));
// Only time j_oTag is pushed is right after j_expr.
let cur_context = self.input.token_context().current();
debug_assert_eq!(cur_context, Some(TokenContext::JSXOpeningTag));
// Only time j_oTag is pushed is right after j_expr.
debug_assert_eq!(
self.input.token_context().0[self.input.token_context().len() - 2],
TokenContext::JSXExpr
);

let res = self.try_parse_ts(|p| p.parse_assignment_expr_base().map(Some));
if let Some(res) = res {
return Ok(res);
} else {
debug_assert_eq!(
self.input.token_context().0[self.input.token_context().len() - 2],
TokenContext::JSXExpr
self.input.token_context().current(),
Some(TokenContext::JSXOpeningTag)
);

let res = self.try_parse_ts(|p| p.parse_assignment_expr_base().map(Some));
if let Some(res) = res {
return Ok(res);
} else {
debug_assert_eq!(
self.input.token_context().current(),
Some(TokenContext::JSXOpeningTag)
);
self.input.token_context_mut().pop();
debug_assert_eq!(
self.input.token_context().current(),
Some(TokenContext::JSXExpr)
);
self.input.token_context_mut().pop();
}
self.input.token_context_mut().pop();
debug_assert_eq!(
self.input.token_context().current(),
Some(TokenContext::JSXExpr)
);
self.input.token_context_mut().pop();
}
}

Expand Down Expand Up @@ -2004,7 +2002,8 @@ impl<I: Tokens> Parser<I> {
}

if is!(self, ';')
|| (!is!(self, '*')
|| (!is!(self, '<')
&& !is!(self, '*')
&& !is!(self, '/')
&& !is!(self, "/=")
&& !cur!(self, false)
Expand Down

0 comments on commit d164f81

Please sign in to comment.