1- import { types } from '@putout/babel' ;
2- import { hasPrevNewline } from '#mark' ;
31import { createTypeChecker } from '#type-checker' ;
42import { isConcatenation } from '#is-concatenation' ;
53import { maybeDeclare } from '#maybe-declare' ;
64import { parseLeadingComments } from '#comments' ;
75import {
86 isNext ,
9- isCoupleLines ,
107 isNewlineBetweenSiblings ,
118 exists ,
129 noTrailingComment ,
@@ -17,16 +14,13 @@ import {
1714 isInsideSwitchCase ,
1815 isInsideBody ,
1916 callWithParent ,
17+ isLast ,
2018} from '#is' ;
2119import { afterIf } from './after-if.js' ;
2220import { maybeSpaceAfterKeyword } from './maybe-space-after-keyword.js' ;
23-
24- const { isExportDeclaration} = types ;
25-
26- const isLast = ( path ) => path . parentPath ?. isProgram ( ) && ! isNext ( path ) ;
21+ import { beforeIf } from './before-if.js' ;
2722
2823const isParentTSModuleBlock = ( path ) => path . parentPath . isTSModuleBlock ( ) ;
29-
3024const isInsideBlockLike = createTypeChecker ( [
3125 isInsideProgram ,
3226 isInsideBlock ,
@@ -61,7 +55,7 @@ const isNeedNewline = createTypeChecker([
6155] ) ;
6256
6357export const VariableDeclaration = {
64- beforeIf : shouldAddNewlineBefore ,
58+ beforeIf,
6559 before ( path , { print} ) {
6660 print . breakline ( ) ;
6761 } ,
@@ -138,25 +132,3 @@ const skipAfter = createTypeChecker([
138132 [ '-: parentPath -> !' , isLast ] ,
139133 [ '+: -> !' , isInsideBlock ] ,
140134] ) ;
141-
142- function shouldAddNewlineBefore ( path ) {
143- if ( isFirst ( path ) )
144- return false ;
145-
146- if ( hasPrevNewline ( path ) )
147- return false ;
148-
149- if ( hasPrevNewline ( path . parentPath ) )
150- return false ;
151-
152- const prevPath = path . getPrevSibling ( ) ;
153-
154- if ( prevPath . isStatement ( ) && ! prevPath . isExpressionStatement ( ) && ! prevPath . isBlockStatement ( ) )
155- return false ;
156-
157- return ! isExportDeclaration ( path . parentPath ) && isCoupleLines ( path ) ;
158- }
159-
160- function isFirst ( path ) {
161- return path . node === path . parentPath . node . body ?. [ 0 ] ;
162- }
0 commit comments