Skip to content

Commit

Permalink
u
Browse files Browse the repository at this point in the history
  • Loading branch information
Boshen committed Oct 13, 2024
1 parent afbf849 commit 43a33c8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
13 changes: 10 additions & 3 deletions crates/oxc_ast/src/precedence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use oxc_syntax::precedence::{GetPrecedence, Precedence};

use crate::ast::{
match_member_expression, AssignmentExpression, AwaitExpression, BinaryExpression,
CallExpression, ComputedMemberExpression, ConditionalExpression, Expression, ImportExpression,
LogicalExpression, MemberExpression, NewExpression, PrivateFieldExpression, SequenceExpression,
StaticMemberExpression, TSTypeAssertion, UnaryExpression, UpdateExpression, YieldExpression,
CallExpression, ChainExpression, ComputedMemberExpression, ConditionalExpression, Expression,
ImportExpression, LogicalExpression, MemberExpression, NewExpression, PrivateFieldExpression,
SequenceExpression, StaticMemberExpression, TSTypeAssertion, UnaryExpression, UpdateExpression,
YieldExpression,
};

impl<'a> GetPrecedence for Expression<'a> {
Expand Down Expand Up @@ -103,6 +104,12 @@ impl<'a> GetPrecedence for NewExpression<'a> {
}
}

impl<'a> GetPrecedence for ChainExpression<'a> {
fn precedence(&self) -> Precedence {
Precedence::Member
}
}

impl<'a> GetPrecedence for MemberExpression<'a> {
fn precedence(&self) -> Precedence {
Precedence::Member
Expand Down
11 changes: 3 additions & 8 deletions crates/oxc_codegen/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,8 +1051,7 @@ impl<'a> GenExpr for Expression<'a> {

impl<'a> GenExpr for ParenthesizedExpression<'a> {
fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) {
let wrap = matches!(self.expression, Expression::ChainExpression(_));
p.wrap(wrap, |p| self.expression.print_expr(p, precedence, ctx));
self.expression.print_expr(p, precedence, ctx);
}
}

Expand Down Expand Up @@ -2051,12 +2050,12 @@ impl<'a> GenExpr for AwaitExpression<'a> {

impl<'a> GenExpr for ChainExpression<'a> {
fn gen_expr(&self, p: &mut Codegen, precedence: Precedence, ctx: Context) {
match &self.expression {
p.wrap(precedence >= Precedence::Postfix, |p| match &self.expression {
ChainElement::CallExpression(expr) => expr.print_expr(p, precedence, ctx),
match_member_expression!(ChainElement) => {
self.expression.to_member_expression().print_expr(p, precedence, ctx);
}
}
});
}
}

Expand Down Expand Up @@ -2782,10 +2781,6 @@ impl<'a> Gen for Decorator<'a> {
Expression::Identifier(_)
| Expression::StaticMemberExpression(_)
| Expression::PrivateFieldExpression(_) => false,
Expression::ParenthesizedExpression(parent_expr) => {
// We will print parenthesis in ParenthesizedExpression
!matches!(parent_expr.expression, Expression::ChainExpression(_))
}
Expression::CallExpression(call_expr) => need_wrap(&call_expr.callee),
// "@(foo + bar)"
// "@(() => {})"
Expand Down

0 comments on commit 43a33c8

Please sign in to comment.