@putout/printer 18.7.2 → 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 CHANGED
@@ -1,3 +1,13 @@
1
+ 2026.03.16, v18.7.4
2
+
3
+ feature:
4
+ - a03e0d22 @putout/printer: type-checker: comparison
5
+
6
+ 2026.03.15, v18.7.3
7
+
8
+ feature:
9
+ - 126ac069 @putout/printer: type-checker: boolean: +/-
10
+
1
11
  2026.03.15, v18.7.2
2
12
 
3
13
  feature:
@@ -62,7 +62,7 @@ const isObjectAfterString = (path) => {
62
62
  };
63
63
 
64
64
  export const isIncreaseIndent = createTypeChecker([
65
- ['-: node.elements.length -> !', Boolean],
65
+ ['-: node.elements.length -> -'],
66
66
  ['+', isBooleanAndObject],
67
67
  ['-', isInsideCallLoop],
68
68
  ['+: node.elements.0 -> ObjectExpression'],
@@ -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', isTwo],
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', isLessThenTwo],
166
+ ['-: node.elements.length', '<', 2],
169
167
  ['-: -> !', isInsideCall],
170
168
  ['-', hasObjects],
171
169
  ['+', isMoreThenMaxLiteralLength],
@@ -192,16 +190,15 @@ 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 -> !', isOne],
196
+ ['-: node.elements.length -> !', '=', 1],
200
197
  ['+', isBody],
201
198
  ]);
202
199
 
203
200
  export const isMultiLine = createTypeChecker([
204
- ['-: node.elements.length -> !', Boolean],
201
+ ['-: node.elements.length -> -'],
205
202
  ['+', isBodyWithOneElement],
206
203
  ['+', isMoreThenMaxElementLengthInOneLine],
207
204
  ['+', isElementsMoreThenMaxWithFirstString],
@@ -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
- ['+: node.typeParameters -> !', Boolean],
26
- ['+: node.typeParameters.params.length', isLessThenTwo],
24
+ ['+: node.typeParameters -> -'],
25
+ ['+: node.typeParameters.params.length', '<', 2],
27
26
  ]);
28
27
 
29
28
  const classVisitor = maybeDecorators((path, printer, semantics) => {
@@ -6,22 +6,20 @@ 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', isThree],
11
+ ['+: parentPath.parentPath.node.elements.length', '=', 3],
14
12
  ]);
15
13
 
16
14
  const hasDirectives = (a) => getDirectives(a).length;
17
15
 
18
- const isNewLineAfterOpenCurlyBrace = createTypeChecker([
16
+ const isNewlineAfterOpenCurlyBrace = createTypeChecker([
19
17
  ['+', hasDirectives],
20
- ['+: node.body.length', Boolean],
18
+ ['+: node.body.length -> +'],
21
19
  ]);
22
20
 
23
21
  const isLinebreakAfterDirectives = createTypeChecker([
24
- ['-: node.body.length -> !', Boolean],
22
+ ['-: node.body.length -> -'],
25
23
  ['+', hasDirectives],
26
24
  ]);
27
25
 
@@ -45,7 +43,7 @@ export const BlockStatement = {
45
43
  maybe.indent.inc(!insideArray);
46
44
  write('{');
47
45
 
48
- if (isNewLineAfterOpenCurlyBrace(path))
46
+ if (isNewlineAfterOpenCurlyBrace(path))
49
47
  write.newline();
50
48
 
51
49
  for (const directive of directives) {
@@ -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', Boolean],
37
+ ['+: parentPath.node.alternate -> +'],
38
38
  ]);
39
39
 
40
40
  const hasTrailingCommentNotCoupleLines = createTypeChecker([
@@ -5,8 +5,8 @@ import {
5
5
  import {createTypeChecker} from '#type-checker';
6
6
 
7
7
  const isInsideIfWithElse = createTypeChecker([
8
- ['-: parentPath -> !IfStatement'],
9
- ['+: parentPath.node.alternate', Boolean],
8
+ '-: parentPath -> !IfStatement',
9
+ '+: parentPath.node.alternate -> +',
10
10
  ]);
11
11
 
12
12
  export const afterIf = createTypeChecker([
@@ -38,6 +38,6 @@ export const ReturnStatement = {
38
38
  };
39
39
 
40
40
  const isJSXWithComment = createTypeChecker([
41
- ['-: node.argument -> !JSXElement'],
42
- ['+: node.argument.leadingComments ->', Boolean],
41
+ '-: node.argument -> !JSXElement',
42
+ '+: node.argument.leadingComments -> +',
43
43
  ]);
@@ -90,6 +90,6 @@ const isNewlineAfterClosingCurlyBrace = createTypeChecker([
90
90
  ]);
91
91
 
92
92
  const isNewlineAfterColon = createTypeChecker([
93
- ['-: node.consequent.length -> !', Boolean],
94
- ['+: node.consequent.0 -> !BlockStatement'],
93
+ '-: node.consequent.length -> -',
94
+ '+: node.consequent.0 -> !BlockStatement',
95
95
  ]);
@@ -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} `,
@@ -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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.7.2",
3
+ "version": "18.7.4",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",