Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/parser): Parse yield<T> (v: T)=>v #9915

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions crates/swc_ecma_parser/src/parser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ 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() {
// Note: When the JSX plugin is on, type assertions (`<T> x`) aren't valid
// syntax.

if is!(self, JSXTagStart) {
if self.input.syntax().jsx() && 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.
Expand All @@ -67,6 +67,14 @@ impl<I: Tokens> Parser<I> {
);
self.input.token_context_mut().pop();
}
} else if is!(self, '<') && !self.input.syntax().disallow_ambiguous_jsx_like() {
let res = self.try_parse_ts(|p| {
let expr = p.parse_assignment_expr_base()?;
Ok(Some(expr))
});
if let Some(res) = res {
return Ok(res);
}
}
}

Expand Down
Loading