@@ -83,6 +83,7 @@ use self::{
83
83
object_like:: ObjectLike ,
84
84
object_pattern_like:: ObjectPatternLike ,
85
85
parameters:: { ParameterLayout , ParameterList } ,
86
+ return_or_throw_statement:: FormatAdjacentArgument ,
86
87
semicolon:: OptionalSemicolon ,
87
88
type_parameters:: { FormatTSTypeParameters , FormatTSTypeParametersOptions } ,
88
89
utils:: {
@@ -659,7 +660,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, ForStatement<'a>> {
659
660
660
661
impl < ' a > FormatWrite < ' a > for AstNode < ' a , ForInStatement < ' a > > {
661
662
fn write ( & self , f : & mut Formatter < ' _ , ' a > ) -> FormatResult < ( ) > {
662
- let comments = f. context ( ) . comments ( ) . own_line_comments_before ( self . body . span ( ) . start ) ;
663
+ let comments = f. context ( ) . comments ( ) . own_line_comments_before ( self . right . span ( ) . start ) ;
663
664
write ! (
664
665
f,
665
666
[
@@ -683,7 +684,7 @@ impl<'a> FormatWrite<'a> for AstNode<'a, ForInStatement<'a>> {
683
684
684
685
impl < ' a > FormatWrite < ' a > for AstNode < ' a , ForOfStatement < ' a > > {
685
686
fn write ( & self , f : & mut Formatter < ' _ , ' a > ) -> FormatResult < ( ) > {
686
- let comments = f. context ( ) . comments ( ) . own_line_comments_before ( self . body . span ( ) . start ) ;
687
+ let comments = f. context ( ) . comments ( ) . own_line_comments_before ( self . right . span ( ) . start ) ;
687
688
688
689
let r#await = self . r#await ( ) ;
689
690
let left = self . left ( ) ;
@@ -857,12 +858,17 @@ impl<'a> FormatWrite<'a> for AstNode<'a, BindingPattern<'a>> {
857
858
858
859
impl < ' a > FormatWrite < ' a > for AstNode < ' a , AssignmentPattern < ' a > > {
859
860
fn write ( & self , f : & mut Formatter < ' _ , ' a > ) -> FormatResult < ( ) > {
860
- let comments = f. context ( ) . comments ( ) . own_line_comments_before ( self . right . span ( ) . start ) ;
861
+ let mut left = self . left ( ) . memoized ( ) ;
862
+ left. inspect ( f) ?;
861
863
write ! (
862
864
f,
863
865
[
864
- FormatLeadingComments :: Comments ( comments) ,
865
- self . left( ) ,
866
+ format_once( |f| {
867
+ let comments =
868
+ f. context( ) . comments( ) . own_line_comments_before( self . right. span( ) . start) ;
869
+ FormatLeadingComments :: Comments ( comments) . fmt( f)
870
+ } ) ,
871
+ left,
866
872
space( ) ,
867
873
"=" ,
868
874
space( ) ,
@@ -938,12 +944,9 @@ impl<'a> FormatWrite<'a, FormatJsArrowFunctionExpressionOptions>
938
944
939
945
impl < ' a > FormatWrite < ' a > for AstNode < ' a , YieldExpression < ' a > > {
940
946
fn write ( & self , f : & mut Formatter < ' _ , ' a > ) -> FormatResult < ( ) > {
941
- write ! ( f, "yield" ) ?;
942
- if self . delegate ( ) {
943
- write ! ( f, "*" ) ?;
944
- }
947
+ write ! ( f, [ "yield" , self . delegate( ) . then_some( "*" ) ] ) ?;
945
948
if let Some ( argument) = & self . argument ( ) {
946
- write ! ( f, [ space( ) , argument] ) ?;
949
+ write ! ( f, [ space( ) , FormatAdjacentArgument ( argument) ] ) ?;
947
950
}
948
951
Ok ( ( ) )
949
952
}
0 commit comments