@@ -531,22 +531,27 @@ impl NeedsParentheses<'_> for AstNode<'_, AssignmentExpression<'_>> {
531531 AstNodes :: SequenceExpression ( sequence) => {
532532 // Skip through SequenceExpression and ParenthesizedExpression ancestors
533533 if let Some ( ancestor) = self . ancestors ( ) . find ( |p| {
534- !matches ! ( p, AstNodes :: SequenceExpression ( _) | AstNodes :: ParenthesizedExpression ( _) )
535- } ) && let AstNodes :: ForStatement ( for_stmt) = ancestor {
536- let is_initializer = for_stmt
537- . init
538- . as_ref ( )
539- . is_some_and ( |init| init. span ( ) . contains_inclusive ( self . span ( ) ) ) ;
540- let is_update = for_stmt. update . as_ref ( ) . is_some_and ( |update| {
541- update. span ( ) . contains_inclusive ( self . span ( ) )
542- } ) ;
543- return !( is_initializer || is_update) ;
544- }
534+ !matches ! (
535+ p,
536+ AstNodes :: SequenceExpression ( _) | AstNodes :: ParenthesizedExpression ( _)
537+ )
538+ } ) && let AstNodes :: ForStatement ( for_stmt) = ancestor
539+ {
540+ let is_initializer = for_stmt
541+ . init
542+ . as_ref ( )
543+ . is_some_and ( |init| init. span ( ) . contains_inclusive ( self . span ( ) ) ) ;
544+ let is_update = for_stmt
545+ . update
546+ . as_ref ( )
547+ . is_some_and ( |update| update. span ( ) . contains_inclusive ( self . span ( ) ) ) ;
548+ return !( is_initializer || is_update) ;
549+ }
545550
546551 true
547552 }
548- // `interface { [a = 1]; }` and `class { [a = 1]; }` not need parens
549- AstNodes :: TSPropertySignature ( _) | AstNodes :: PropertyDefinition ( _ ) |
553+ // `interface A { [a = 1]; }` not need parens
554+ AstNodes :: TSPropertySignature ( _) |
550555 // Never need parentheses in these contexts:
551556 // - `a = (b = c)` = nested assignments don't need extra parens
552557 AstNodes :: AssignmentExpression ( _) => false ,
@@ -567,6 +572,7 @@ impl NeedsParentheses<'_> for AstNode<'_, AssignmentExpression<'_>> {
567572 // - `new (a = b)`
568573 // - `(a = b).prop`
569574 // - `await (a = b)`
575+ // - `class { [a = 1]; }`
570576 // - etc.
571577 _ => true ,
572578 }
0 commit comments