@putout/printer 18.6.1 → 18.6.3
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 +10 -0
- package/lib/tokenize/statements/expression-statement/after-if.js +1 -1
- package/lib/tokenize/statements/variable-declaration/after-if.js +23 -17
- package/lib/tokenize/statements/variable-declaration/before-if.js +13 -0
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +3 -31
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -33,7 +33,7 @@ const isPathIsConsequent = ({node, parentPath}) => node !== parentPath.node.cons
|
|
|
33
33
|
|
|
34
34
|
const isBeforeElse = createTypeChecker([
|
|
35
35
|
['-: parentPath -> !IfStatement'],
|
|
36
|
-
['
|
|
36
|
+
['-', isPathIsConsequent],
|
|
37
37
|
['+: parentPath.node.alternate', Boolean],
|
|
38
38
|
]);
|
|
39
39
|
|
|
@@ -8,18 +8,37 @@ import {
|
|
|
8
8
|
isLast,
|
|
9
9
|
isNewlineBetweenSiblings,
|
|
10
10
|
isNext,
|
|
11
|
+
callWithPrev,
|
|
11
12
|
} from '#is';
|
|
12
13
|
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
14
|
+
const isTwoLinesDifferenceWithPrev = (path) => {
|
|
15
|
+
const prev = path.getPrevSibling();
|
|
16
|
+
|
|
17
|
+
return path.node.loc?.start.line === prev.node?.loc?.start?.line + 2;
|
|
18
|
+
};
|
|
17
19
|
|
|
18
20
|
const {
|
|
19
21
|
isIfStatement,
|
|
20
22
|
isFunctionDeclaration,
|
|
23
|
+
isVariableDeclaration,
|
|
21
24
|
} = types;
|
|
22
25
|
|
|
26
|
+
const isNoPrevAndNextConst = createTypeChecker([
|
|
27
|
+
['-: ->', callWithPrev(exists)],
|
|
28
|
+
['+', callWithNext(isVariableDeclaration)],
|
|
29
|
+
]);
|
|
30
|
+
|
|
31
|
+
const isNextCoupleLines = createTypeChecker([
|
|
32
|
+
['-', isNoPrevAndNextConst],
|
|
33
|
+
['-', isTwoLinesDifferenceWithPrev],
|
|
34
|
+
['+', callWithNext(isCoupleLines)],
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
const noNextParentBlock = createTypeChecker([
|
|
38
|
+
['-', isNext],
|
|
39
|
+
['+', isInsideBlock],
|
|
40
|
+
]);
|
|
41
|
+
|
|
23
42
|
const notLastCoupleLines = createTypeChecker([
|
|
24
43
|
['-', isLast],
|
|
25
44
|
['+', isCoupleLines],
|
|
@@ -52,19 +71,6 @@ export const afterIf = createTypeChecker([
|
|
|
52
71
|
['+: parentPath -> TSModuleBlock'],
|
|
53
72
|
]);
|
|
54
73
|
|
|
55
|
-
function isNextCoupleLines(path) {
|
|
56
|
-
const next = path.getNextSibling();
|
|
57
|
-
const prev = path.getPrevSibling();
|
|
58
|
-
|
|
59
|
-
if (!exists(prev.getPrevSibling()) && next.isVariableDeclaration())
|
|
60
|
-
return false;
|
|
61
|
-
|
|
62
|
-
if (path.node.loc?.start.line === prev.node?.loc?.start?.line + 2)
|
|
63
|
-
return false;
|
|
64
|
-
|
|
65
|
-
return isCoupleLines(next);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
74
|
function notLastPrevVarNotNextVar(path) {
|
|
69
75
|
const prev = path.getPrevSibling();
|
|
70
76
|
const next = path.getNextSibling();
|
|
@@ -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