@putout/printer 18.7.3 → 18.7.4
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 +5 -0
- package/lib/tokenize/expressions/array-expression/indent.js +1 -3
- package/lib/tokenize/expressions/array-expression/newline.js +3 -5
- package/lib/tokenize/expressions/class/class.js +1 -2
- package/lib/tokenize/statements/block-statement/block-statement.js +3 -5
- package/lib/tokenize/statements/switch-statement/switch-statement.js +0 -1
- package/lib/tokenize/type-checker/parsers.js +25 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -98,12 +98,10 @@ export function isArrayInsideArray(path) {
|
|
|
98
98
|
return length <= 3 && length !== 1;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
const isTwo = (a) => a === 2;
|
|
102
|
-
|
|
103
101
|
export const isHideIndent = createTypeChecker([
|
|
104
102
|
['-: -> !', isInsideArray],
|
|
105
103
|
['-: parentPath -> !', isStringAndArray],
|
|
106
|
-
['+: parentPath.node.elements.length',
|
|
104
|
+
['+: parentPath.node.elements.length', '=', 2],
|
|
107
105
|
]);
|
|
108
106
|
|
|
109
107
|
const isLastElementObjectExpression = ({node}) => isObjectExpression(node.elements.at(-1));
|
|
@@ -162,10 +162,8 @@ const hasObjects = (path) => {
|
|
|
162
162
|
return literals.length;
|
|
163
163
|
};
|
|
164
164
|
|
|
165
|
-
const isLessThenTwo = (a) => a < 2;
|
|
166
|
-
|
|
167
165
|
const isMoreThenMaxElementLengthInOneLine = createTypeChecker([
|
|
168
|
-
['-: node.elements.length',
|
|
166
|
+
['-: node.elements.length', '<', 2],
|
|
169
167
|
['-: -> !', isInsideCall],
|
|
170
168
|
['-', hasObjects],
|
|
171
169
|
['+', isMoreThenMaxLiteralLength],
|
|
@@ -192,11 +190,10 @@ const isElementsMoreThenMaxWithFirstString = createTypeChecker([
|
|
|
192
190
|
['+', isElementsMoreThenMax],
|
|
193
191
|
]);
|
|
194
192
|
|
|
195
|
-
const isOne = (a) => a === 1;
|
|
196
193
|
const isBody = ({node, parentPath}) => node === parentPath.node.body;
|
|
197
194
|
|
|
198
195
|
const isBodyWithOneElement = createTypeChecker([
|
|
199
|
-
['-: node.elements.length -> !',
|
|
196
|
+
['-: node.elements.length -> !', '=', 1],
|
|
200
197
|
['+', isBody],
|
|
201
198
|
]);
|
|
202
199
|
|
|
@@ -311,3 +308,4 @@ export const isIndentBeforeElement = createTypeChecker([
|
|
|
311
308
|
['+: -> SpreadElement'],
|
|
312
309
|
['+: -> !ObjectExpression'],
|
|
313
310
|
]);
|
|
311
|
+
|
|
@@ -19,11 +19,10 @@ const afterIf = createTypeChecker([
|
|
|
19
19
|
]);
|
|
20
20
|
|
|
21
21
|
const {isFunction} = types;
|
|
22
|
-
const isLessThenTwo = (a) => a < 2;
|
|
23
22
|
|
|
24
23
|
const isSpaceBeforeImplements = createTypeChecker([
|
|
25
24
|
['+: node.typeParameters -> -'],
|
|
26
|
-
['+: node.typeParameters.params.length',
|
|
25
|
+
['+: node.typeParameters.params.length', '<', 2],
|
|
27
26
|
]);
|
|
28
27
|
|
|
29
28
|
const classVisitor = maybeDecorators((path, printer, semantics) => {
|
|
@@ -6,16 +6,14 @@ import {getDirectives} from './get-directives.js';
|
|
|
6
6
|
import {isCallInsideChain} from './is-call-inside-chain.js';
|
|
7
7
|
import {shouldAddNewlineAfter} from './block-statement-newline.js';
|
|
8
8
|
|
|
9
|
-
const isThree = (a) => a === 3;
|
|
10
|
-
|
|
11
9
|
const isInsideArrayTupleOfThree = createTypeChecker([
|
|
12
10
|
['-: parentPath.parentPath -> !ArrayExpression'],
|
|
13
|
-
['+: parentPath.parentPath.node.elements.length',
|
|
11
|
+
['+: parentPath.parentPath.node.elements.length', '=', 3],
|
|
14
12
|
]);
|
|
15
13
|
|
|
16
14
|
const hasDirectives = (a) => getDirectives(a).length;
|
|
17
15
|
|
|
18
|
-
const
|
|
16
|
+
const isNewlineAfterOpenCurlyBrace = createTypeChecker([
|
|
19
17
|
['+', hasDirectives],
|
|
20
18
|
['+: node.body.length -> +'],
|
|
21
19
|
]);
|
|
@@ -45,7 +43,7 @@ export const BlockStatement = {
|
|
|
45
43
|
maybe.indent.inc(!insideArray);
|
|
46
44
|
write('{');
|
|
47
45
|
|
|
48
|
-
if (
|
|
46
|
+
if (isNewlineAfterOpenCurlyBrace(path))
|
|
49
47
|
write.newline();
|
|
50
48
|
|
|
51
49
|
for (const directive of directives) {
|
|
@@ -30,7 +30,7 @@ export function parseTypeNames(typeNames) {
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
if (isArray(typeName)) {
|
|
33
|
-
tuples.push(typeName);
|
|
33
|
+
tuples.push(parseComparison(typeName));
|
|
34
34
|
continue;
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -45,3 +45,27 @@ export function parseTypeNames(typeNames) {
|
|
|
45
45
|
|
|
46
46
|
return tuples;
|
|
47
47
|
}
|
|
48
|
+
|
|
49
|
+
const equal = (a) => (b) => b === a;
|
|
50
|
+
const more = (a) => (b) => b > a;
|
|
51
|
+
const less = (a) => (b) => b < a;
|
|
52
|
+
const moreOrEqual = (a) => (b) => b >= a;
|
|
53
|
+
const lessOrEqual = (a) => (b) => b <= a;
|
|
54
|
+
|
|
55
|
+
const CMP = {
|
|
56
|
+
'=': equal,
|
|
57
|
+
'>': more,
|
|
58
|
+
'<': less,
|
|
59
|
+
'>=': moreOrEqual,
|
|
60
|
+
'<=': lessOrEqual,
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
function parseComparison(typeName) {
|
|
64
|
+
if (typeName.length === 3) {
|
|
65
|
+
const [result, comparison, value] = typeName;
|
|
66
|
+
|
|
67
|
+
return [result, CMP[comparison](value)];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return typeName;
|
|
71
|
+
}
|
package/package.json
CHANGED