File tree Expand file tree Collapse file tree 3 files changed +11
-6
lines changed
rewrite-javascript/rewrite Expand file tree Collapse file tree 3 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -290,7 +290,7 @@ export class SpacesVisitor<P> extends JavaScriptVisitor<P> {
290290 const ret = await super . visitMethodInvocation ( methodInv , p ) as J . MethodInvocation ;
291291 return produceAsync ( ret , async draft => {
292292 if ( draft . select ) {
293- draft . select = await this . spaceAfterRightPadded ( draft . select , this . style . beforeParentheses . functionCallParentheses ) ;
293+ draft . arguments = await this . spaceBeforeContainer ( draft . arguments , this . style . beforeParentheses . functionCallParentheses ) ;
294294 }
295295 if ( ret . arguments . elements . length > 0 && ret . arguments . elements [ 0 ] . element . kind != J . Kind . Empty ) {
296296 draft . arguments . elements = await Promise . all ( draft . arguments . elements . map ( async ( arg , index ) => {
@@ -1030,7 +1030,11 @@ export class BlankLinesVisitor<P> extends JavaScriptVisitor<P> {
10301030
10311031 private ensurePrefixHasNewLine < T extends J > ( node : Draft < J > ) {
10321032 if ( node . prefix && ! node . prefix . whitespace . includes ( "\n" ) ) {
1033- node . prefix . whitespace = "\n" + node . prefix . whitespace ;
1033+ if ( node . kind === JS . Kind . ExpressionStatement ) {
1034+ this . ensurePrefixHasNewLine ( ( node as JS . ExpressionStatement ) . expression ) ;
1035+ } else {
1036+ node . prefix . whitespace = "\n" + node . prefix . whitespace ;
1037+ }
10341038 }
10351039 }
10361040
Original file line number Diff line number Diff line change @@ -75,13 +75,15 @@ export class JavaScriptPrinter extends JavaScriptVisitor<PrintOutputCapture> {
7575 }
7676
7777 override async visitExpressionStatement ( statement : JS . ExpressionStatement , p : PrintOutputCapture ) : Promise < J | undefined > {
78- // has no markers or prefix
78+ await this . visitSpace ( statement . prefix , p ) ;
79+ await this . visitMarkers ( statement . markers , p ) ;
7980 await this . visit ( statement . expression , p ) ;
8081 return statement ;
8182 }
8283
8384 override async visitStatementExpression ( statementExpression : JS . StatementExpression , p : PrintOutputCapture ) : Promise < J | J | undefined > {
84- // has no markers or prefix
85+ await this . visitSpace ( statementExpression . prefix , p ) ;
86+ await this . visitMarkers ( statementExpression . markers , p ) ;
8587 await this . visit ( statementExpression . statement , p ) ;
8688 return statementExpression ;
8789 }
Original file line number Diff line number Diff line change @@ -22,8 +22,7 @@ describe('AutoformatVisitor', () => {
2222 const spec = new RecipeSpec ( )
2323 spec . recipe = fromVisitor ( new AutoformatVisitor ( ) ) ;
2424
25- // FIXME enable again once we've fixed `StatementExpression` and `ExpressionStatement` handling
26- test . skip ( 'everything' , ( ) => {
25+ test ( 'everything' , ( ) => {
2726 return spec . rewriteRun (
2827 // TODO there should be no newline after the default case in switch
2928 // TODO not sure if there should be a newline after the if and after the finally
You can’t perform that action at this time.
0 commit comments