@putout/printer 18.7.1 → 18.7.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 +12 -0
- package/lib/tokenize/expressions/array-expression/indent.js +1 -1
- package/lib/tokenize/expressions/array-expression/newline.js +1 -1
- package/lib/tokenize/expressions/class/class.js +1 -1
- package/lib/tokenize/statements/block-statement/block-statement.js +2 -2
- package/lib/tokenize/statements/expression-statement/after-if.js +1 -1
- package/lib/tokenize/statements/return-statement/after-if.js +17 -0
- package/lib/tokenize/statements/return-statement/before-if.js +18 -0
- package/lib/tokenize/statements/return-statement/maybe-space-after-keyword.js +35 -16
- package/lib/tokenize/statements/return-statement/return-statement.js +8 -50
- package/lib/tokenize/statements/switch-statement/switch-statement.js +3 -2
- package/lib/tokenize/type-checker/create-tuple.js +12 -0
- package/lib/tokenize/type-checker/type-checker.js +2 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
2026.03.15, v18.7.3
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 126ac069 @putout/printer: type-checker: boolean: +/-
|
|
5
|
+
|
|
6
|
+
2026.03.15, v18.7.2
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 03c11aa @putout/printer: ReturnStatements: maybeSpaceAfterKeyword: simplify
|
|
10
|
+
- 2a0d633 @putout/printer: ReturnStatement: isJSXWithComment
|
|
11
|
+
- 3ee3a68 @putout/printer: ReturnStatement: afterIf
|
|
12
|
+
|
|
1
13
|
2026.03.14, v18.7.1
|
|
2
14
|
|
|
3
15
|
feature:
|
|
@@ -62,7 +62,7 @@ const isObjectAfterString = (path) => {
|
|
|
62
62
|
};
|
|
63
63
|
|
|
64
64
|
export const isIncreaseIndent = createTypeChecker([
|
|
65
|
-
['-: node.elements.length ->
|
|
65
|
+
['-: node.elements.length -> -'],
|
|
66
66
|
['+', isBooleanAndObject],
|
|
67
67
|
['-', isInsideCallLoop],
|
|
68
68
|
['+: node.elements.0 -> ObjectExpression'],
|
|
@@ -201,7 +201,7 @@ const isBodyWithOneElement = createTypeChecker([
|
|
|
201
201
|
]);
|
|
202
202
|
|
|
203
203
|
export const isMultiLine = createTypeChecker([
|
|
204
|
-
['-: node.elements.length ->
|
|
204
|
+
['-: node.elements.length -> -'],
|
|
205
205
|
['+', isBodyWithOneElement],
|
|
206
206
|
['+', isMoreThenMaxElementLengthInOneLine],
|
|
207
207
|
['+', isElementsMoreThenMaxWithFirstString],
|
|
@@ -22,7 +22,7 @@ const {isFunction} = types;
|
|
|
22
22
|
const isLessThenTwo = (a) => a < 2;
|
|
23
23
|
|
|
24
24
|
const isSpaceBeforeImplements = createTypeChecker([
|
|
25
|
-
['+: node.typeParameters ->
|
|
25
|
+
['+: node.typeParameters -> -'],
|
|
26
26
|
['+: node.typeParameters.params.length', isLessThenTwo],
|
|
27
27
|
]);
|
|
28
28
|
|
|
@@ -17,11 +17,11 @@ const hasDirectives = (a) => getDirectives(a).length;
|
|
|
17
17
|
|
|
18
18
|
const isNewLineAfterOpenCurlyBrace = createTypeChecker([
|
|
19
19
|
['+', hasDirectives],
|
|
20
|
-
['+: node.body.length'
|
|
20
|
+
['+: node.body.length -> +'],
|
|
21
21
|
]);
|
|
22
22
|
|
|
23
23
|
const isLinebreakAfterDirectives = createTypeChecker([
|
|
24
|
-
['-: node.body.length ->
|
|
24
|
+
['-: node.body.length -> -'],
|
|
25
25
|
['+', hasDirectives],
|
|
26
26
|
]);
|
|
27
27
|
|
|
@@ -34,7 +34,7 @@ const isPathIsConsequent = ({node, parentPath}) => node !== parentPath.node.cons
|
|
|
34
34
|
const isBeforeElse = createTypeChecker([
|
|
35
35
|
['-: parentPath -> !IfStatement'],
|
|
36
36
|
['-', isPathIsConsequent],
|
|
37
|
-
['+: parentPath.node.alternate'
|
|
37
|
+
['+: parentPath.node.alternate -> +'],
|
|
38
38
|
]);
|
|
39
39
|
|
|
40
40
|
const hasTrailingCommentNotCoupleLines = createTypeChecker([
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {
|
|
2
|
+
isLast,
|
|
3
|
+
noTrailingComment,
|
|
4
|
+
} from '#is';
|
|
5
|
+
import {createTypeChecker} from '#type-checker';
|
|
6
|
+
|
|
7
|
+
const isInsideIfWithElse = createTypeChecker([
|
|
8
|
+
'-: parentPath -> !IfStatement',
|
|
9
|
+
'+: parentPath.node.alternate -> +',
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
export const afterIf = createTypeChecker([
|
|
13
|
+
['+', isInsideIfWithElse],
|
|
14
|
+
['-', isLast],
|
|
15
|
+
['-: parentPath', isLast],
|
|
16
|
+
['+', noTrailingComment],
|
|
17
|
+
]);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {callWithPrev} from '#is';
|
|
3
|
+
import {hasPrevNewline} from '#mark';
|
|
4
|
+
import {createTypeChecker} from '#type-checker';
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
isTryStatement,
|
|
8
|
+
isBlockStatement,
|
|
9
|
+
} = types;
|
|
10
|
+
|
|
11
|
+
const isBodyLength = ({parentPath}) => parentPath.node?.body?.length > 2;
|
|
12
|
+
|
|
13
|
+
export const beforeIf = createTypeChecker([
|
|
14
|
+
['+', callWithPrev(isTryStatement)],
|
|
15
|
+
['-: ->', hasPrevNewline],
|
|
16
|
+
['+: ->', isBodyLength],
|
|
17
|
+
['+: ->', callWithPrev(isBlockStatement)],
|
|
18
|
+
]);
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
import {createTypeChecker} from '#type-checker';
|
|
2
|
+
|
|
3
|
+
const isSequenceOption = (a, {roundBraces}) => roundBraces.sequence;
|
|
4
|
+
const isArrowOption = (a, {roundBraces}) => roundBraces.arrow;
|
|
5
|
+
const isNot = (a) => a === '!';
|
|
6
|
+
|
|
1
7
|
export const maybeSpaceAfterKeyword = (path, {print}, semantics) => {
|
|
2
8
|
const {roundBraces} = semantics;
|
|
3
9
|
const {node} = path;
|
|
@@ -5,22 +11,35 @@ export const maybeSpaceAfterKeyword = (path, {print}, semantics) => {
|
|
|
5
11
|
if (!node)
|
|
6
12
|
return;
|
|
7
13
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (type === 'StringLiteral' || type === 'TemplateLiteral')
|
|
14
|
-
return print.space();
|
|
15
|
-
|
|
16
|
-
if (type === 'ArrayExpression' || type === 'ObjectExpression')
|
|
17
|
-
return print.space();
|
|
18
|
-
|
|
19
|
-
if (type === 'UnaryExpression' && node.operator === '!')
|
|
20
|
-
return print.space();
|
|
21
|
-
|
|
22
|
-
if (type === 'ArrowFunctionExpression' && roundBraces.arrow)
|
|
23
|
-
return print.space();
|
|
14
|
+
if (isOptionalSpace(path, {roundBraces})) {
|
|
15
|
+
print.space();
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
24
18
|
|
|
25
19
|
print(' ');
|
|
26
20
|
};
|
|
21
|
+
|
|
22
|
+
const isSequenceWithOption = createTypeChecker([
|
|
23
|
+
['-: -> !SequenceExpression'],
|
|
24
|
+
['+', isSequenceOption],
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const isArrowWithOption = createTypeChecker([
|
|
28
|
+
['-: -> !ArrowFunctionExpression'],
|
|
29
|
+
['+', isArrowOption],
|
|
30
|
+
]);
|
|
31
|
+
|
|
32
|
+
const isUnaryNot = createTypeChecker([
|
|
33
|
+
['-: -> !UnaryExpression'],
|
|
34
|
+
['+: node.operator', isNot],
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
const isOptionalSpace = createTypeChecker([
|
|
38
|
+
['+: -> StringLiteral'],
|
|
39
|
+
['+: -> TemplateLiteral'],
|
|
40
|
+
['+: -> ArrayExpression'],
|
|
41
|
+
['+: -> ObjectExpression'],
|
|
42
|
+
['+', isUnaryNot],
|
|
43
|
+
['+', isSequenceWithOption],
|
|
44
|
+
['+', isArrowWithOption],
|
|
45
|
+
]);
|
|
@@ -1,33 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {hasPrevNewline} from '#mark';
|
|
1
|
+
import {isInsideLabel} from '#is';
|
|
3
2
|
import {createTypeChecker} from '#type-checker';
|
|
4
|
-
import {
|
|
5
|
-
isInsideLabel,
|
|
6
|
-
noTrailingComment,
|
|
7
|
-
isLast,
|
|
8
|
-
callWithPrev,
|
|
9
|
-
} from '#is';
|
|
10
3
|
import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
isJSXElement,
|
|
14
|
-
isTryStatement,
|
|
15
|
-
isBlockStatement,
|
|
16
|
-
} = types;
|
|
17
|
-
|
|
18
|
-
const isBodyLength = ({parentPath}) => parentPath.node?.body?.length > 2;
|
|
19
|
-
|
|
20
|
-
const isInsideIfWithElse = createTypeChecker([
|
|
21
|
-
['-: parentPath -> !IfStatement'],
|
|
22
|
-
['+: parentPath.node.alternate', Boolean],
|
|
23
|
-
]);
|
|
24
|
-
|
|
25
|
-
const beforeIf = createTypeChecker([
|
|
26
|
-
['+', callWithPrev(isTryStatement)],
|
|
27
|
-
['-: ->', hasPrevNewline],
|
|
28
|
-
['+: ->', isBodyLength],
|
|
29
|
-
['+: ->', callWithPrev(isBlockStatement)],
|
|
30
|
-
]);
|
|
4
|
+
import {beforeIf} from './before-if.js';
|
|
5
|
+
import {afterIf} from './after-if.js';
|
|
31
6
|
|
|
32
7
|
export const ReturnStatement = {
|
|
33
8
|
beforeIf,
|
|
@@ -56,30 +31,13 @@ export const ReturnStatement = {
|
|
|
56
31
|
print('__argument');
|
|
57
32
|
print(';');
|
|
58
33
|
},
|
|
59
|
-
afterIf
|
|
60
|
-
if (isInsideIfWithElse(path))
|
|
61
|
-
return true;
|
|
62
|
-
|
|
63
|
-
if (isLast(path))
|
|
64
|
-
return false;
|
|
65
|
-
|
|
66
|
-
if (isLast(path.parentPath))
|
|
67
|
-
return false;
|
|
68
|
-
|
|
69
|
-
return noTrailingComment(path);
|
|
70
|
-
},
|
|
34
|
+
afterIf,
|
|
71
35
|
after(path, {print}) {
|
|
72
36
|
print.newline();
|
|
73
37
|
},
|
|
74
38
|
};
|
|
75
39
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return;
|
|
81
|
-
|
|
82
|
-
const {leadingComments} = arg;
|
|
83
|
-
|
|
84
|
-
return isJSXElement(arg) && leadingComments?.length;
|
|
85
|
-
}
|
|
40
|
+
const isJSXWithComment = createTypeChecker([
|
|
41
|
+
'-: node.argument -> !JSXElement',
|
|
42
|
+
'+: node.argument.leadingComments -> +',
|
|
43
|
+
]);
|
|
@@ -90,6 +90,7 @@ const isNewlineAfterClosingCurlyBrace = createTypeChecker([
|
|
|
90
90
|
]);
|
|
91
91
|
|
|
92
92
|
const isNewlineAfterColon = createTypeChecker([
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
'-: node.consequent.length -> -',
|
|
94
|
+
'+: node.consequent.0 -> !BlockStatement',
|
|
95
95
|
]);
|
|
96
|
+
|
|
@@ -4,6 +4,18 @@ export function createTuple(typeName) {
|
|
|
4
4
|
const array = typeWithNot.split('!');
|
|
5
5
|
const operation = afterSplit.join(' ');
|
|
6
6
|
|
|
7
|
+
if (typeWithNot === '+')
|
|
8
|
+
return [
|
|
9
|
+
`${operation} `,
|
|
10
|
+
Boolean,
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
if (typeWithNot === '-')
|
|
14
|
+
return [
|
|
15
|
+
`${operation} !`,
|
|
16
|
+
Boolean,
|
|
17
|
+
];
|
|
18
|
+
|
|
7
19
|
if (array.length === 1)
|
|
8
20
|
return [
|
|
9
21
|
`${operation} `,
|
|
@@ -14,13 +14,13 @@ export const createTypeChecker = (typeNames, overrides = {}) => {
|
|
|
14
14
|
} = overrides;
|
|
15
15
|
|
|
16
16
|
const tuples = parseTypeNames(typeNames);
|
|
17
|
-
const checkers =
|
|
17
|
+
const checkers = [];
|
|
18
18
|
const results = new Set();
|
|
19
19
|
|
|
20
20
|
for (const [operation, typeName] of tuples) {
|
|
21
21
|
const [result, selector, not] = parseOperation(operation);
|
|
22
22
|
results.add(result);
|
|
23
|
-
checkers.
|
|
23
|
+
checkers.push({
|
|
24
24
|
result,
|
|
25
25
|
selector,
|
|
26
26
|
not,
|
package/package.json
CHANGED