Skip to content
Merged
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
10 changes: 10 additions & 0 deletions crates/oxc_parser/src/js/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,9 @@ impl<'a> ParserImpl<'a> {
}

let span = self.start_span();
let lhs_parenthesized = self.at(Kind::LParen);
let lhs = self.parse_binary_expression_or_higher(Precedence::Comma);
let lhs_parenthesized_span = lhs_parenthesized.then(|| self.end_span(span));
let kind = self.cur_kind();

// `x => {}`
Expand All @@ -1258,6 +1260,7 @@ impl<'a> ParserImpl<'a> {
return self.parse_assignment_expression_recursive(
span,
lhs,
lhs_parenthesized_span,
allow_return_type_in_arrow_function,
);
}
Expand Down Expand Up @@ -1318,6 +1321,7 @@ impl<'a> ParserImpl<'a> {
&mut self,
span: u32,
lhs: Expression<'a>,
left_parenthesized_span: Option<Span>,
allow_return_type_in_arrow_function: bool,
) -> Expression<'a> {
let operator = map_assignment_operator(self.cur_kind());
Expand All @@ -1327,6 +1331,12 @@ impl<'a> ParserImpl<'a> {
// AssignmentPattern[Yield, Await] :
// ObjectAssignmentPattern
// ArrayAssignmentPattern
if let Some(span) = left_parenthesized_span {
// `({}) = x;`, `([]) = x;`
if matches!(lhs, Expression::ObjectExpression(_) | Expression::ArrayExpression(_)) {
self.error(diagnostics::invalid_assignment(span));
}
}
let left = AssignmentTarget::cover(lhs, self);
self.bump_any();
let right =
Expand Down
Loading