@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 CHANGED
@@ -1,3 +1,8 @@
1
+ 2026.03.16, v18.7.4
2
+
3
+ feature:
4
+ - a03e0d22 @putout/printer: type-checker: comparison
5
+
1
6
  2026.03.15, v18.7.3
2
7
 
3
8
  feature:
@@ -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,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 -> !', isOne],
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', isLessThenTwo],
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', 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
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 (isNewLineAfterOpenCurlyBrace(path))
46
+ if (isNewlineAfterOpenCurlyBrace(path))
49
47
  write.newline();
50
48
 
51
49
  for (const directive of directives) {
@@ -93,4 +93,3 @@ const isNewlineAfterColon = createTypeChecker([
93
93
  '-: node.consequent.length -> -',
94
94
  '+: node.consequent.0 -> !BlockStatement',
95
95
  ]);
96
-
@@ -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.3",
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",