@putout/printer 18.6.1 → 18.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/ChangeLog
CHANGED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {createTypeChecker} from '#type-checker';
|
|
3
|
+
import {hasPrevNewline} from '#mark';
|
|
4
|
+
import {callWithPrev, isFirst} from '#is';
|
|
5
|
+
|
|
6
|
+
const {isBlockStatement} = types;
|
|
7
|
+
|
|
8
|
+
export const beforeIf = createTypeChecker([
|
|
9
|
+
['-', isFirst],
|
|
10
|
+
['-', hasPrevNewline],
|
|
11
|
+
['-: parentPath ->', hasPrevNewline],
|
|
12
|
+
['+', callWithPrev(isBlockStatement)],
|
|
13
|
+
]);
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {types} from '@putout/babel';
|
|
2
|
-
import {hasPrevNewline} from '#mark';
|
|
3
1
|
import {createTypeChecker} from '#type-checker';
|
|
4
2
|
import {isConcatenation} from '#is-concatenation';
|
|
5
3
|
import {maybeDeclare} from '#maybe-declare';
|
|
6
4
|
import {parseLeadingComments} from '#comments';
|
|
7
5
|
import {
|
|
8
6
|
isNext,
|
|
9
|
-
isCoupleLines,
|
|
10
7
|
isNewlineBetweenSiblings,
|
|
11
8
|
exists,
|
|
12
9
|
noTrailingComment,
|
|
@@ -17,16 +14,13 @@ import {
|
|
|
17
14
|
isInsideSwitchCase,
|
|
18
15
|
isInsideBody,
|
|
19
16
|
callWithParent,
|
|
17
|
+
isLast,
|
|
20
18
|
} from '#is';
|
|
21
19
|
import {afterIf} from './after-if.js';
|
|
22
20
|
import {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';
|
|
27
22
|
|
|
28
23
|
const isParentTSModuleBlock = (path) => path.parentPath.isTSModuleBlock();
|
|
29
|
-
|
|
30
24
|
const isInsideBlockLike = createTypeChecker([
|
|
31
25
|
isInsideProgram,
|
|
32
26
|
isInsideBlock,
|
|
@@ -61,7 +55,7 @@ const isNeedNewline = createTypeChecker([
|
|
|
61
55
|
]);
|
|
62
56
|
|
|
63
57
|
export const VariableDeclaration = {
|
|
64
|
-
beforeIf
|
|
58
|
+
beforeIf,
|
|
65
59
|
before(path, {print}) {
|
|
66
60
|
print.breakline();
|
|
67
61
|
},
|
|
@@ -138,25 +132,3 @@ const skipAfter = createTypeChecker([
|
|
|
138
132
|
['-: parentPath -> !', isLast],
|
|
139
133
|
['+: -> !', isInsideBlock],
|
|
140
134
|
]);
|
|
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
|
-
}
|
package/package.json
CHANGED