@putout/printer 18.6.3 → 18.6.5

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,7 +1,18 @@
1
+ 2026.03.14, v18.6.5
2
+
3
+ feature:
4
+ - 93c758f @putout/printer: VariableDeclaration: afterIf: isNextAssign
5
+
6
+ 2026.03.14, v18.6.4
7
+
8
+ feature:
9
+ - ccfe6be @putout/printer: VariableDeclaration: afterIf: simplify
10
+ - 70a6c99 @putout/printer: VariableDeclration: afterIf: simplify
11
+
1
12
  2026.03.14, v18.6.3
2
13
 
3
14
  feature:
4
- - 5837376 @putout/printer: VariableDeclration: afterIf:
15
+ - 5837376 @putout/printer: VariableDeclration: afterIf: simplify
5
16
 
6
17
  2026.03.13, v18.6.2
7
18
 
@@ -7,6 +7,7 @@ import {isSpaceAfterComma} from './space.js';
7
7
  export const ObjectProperty = (path, printer, semantics) => {
8
8
  const {trailingComma} = semantics;
9
9
  const {shorthand} = path.node;
10
+
10
11
  const {
11
12
  maybe,
12
13
  traverse,
@@ -11,18 +11,35 @@ import {
11
11
  callWithPrev,
12
12
  } from '#is';
13
13
 
14
- const isTwoLinesDifferenceWithPrev = (path) => {
15
- const prev = path.getPrevSibling();
16
-
17
- return path.node.loc?.start.line === prev.node?.loc?.start?.line + 2;
18
- };
19
-
20
14
  const {
21
15
  isIfStatement,
22
16
  isFunctionDeclaration,
23
17
  isVariableDeclaration,
18
+ isExpressionStatement,
19
+ isAssignmentExpression,
24
20
  } = types;
25
21
 
22
+ const issLessThenThree = (a) => a < 3;
23
+ const callWithExpression = (fn) => (path) => fn(path.node.expression);
24
+
25
+ const isTwoLinesDifferenceWithPrev = (path) => {
26
+ const prev = path.getPrevSibling();
27
+ return path.node.loc?.start.line === prev.node?.loc?.start?.line + 2;
28
+ };
29
+
30
+ const isInsideBlockWithLessThenThreeSiblings = createTypeChecker([
31
+ ['-: parentPath -> !BlockStatement'],
32
+ ['+: parentPath.node.body.length', issLessThenThree],
33
+ ]);
34
+
35
+ const notLastPrevVarNotNextVar = createTypeChecker([
36
+ ['-: -> !', callWithPrev(exists)],
37
+ ['-', isTwoLinesDifferenceWithPrev],
38
+ ['-', isLast],
39
+ ['-: -> !', callWithPrev(isVariableDeclaration)],
40
+ ['+: -> !', callWithNext(isVariableDeclaration)],
41
+ ]);
42
+
26
43
  const isNoPrevAndNextConst = createTypeChecker([
27
44
  ['-: ->', callWithPrev(exists)],
28
45
  ['+', callWithNext(isVariableDeclaration)],
@@ -44,19 +61,11 @@ const notLastCoupleLines = createTypeChecker([
44
61
  ['+', isCoupleLines],
45
62
  ]);
46
63
 
47
- const isNextAssign = (path) => {
48
- const nextPath = path.getNextSibling();
49
-
50
- if (!nextPath.isExpressionStatement())
51
- return false;
52
-
53
- const {parentPath} = path;
54
-
55
- if (parentPath.isBlockStatement() && parentPath.node.body.length < 3)
56
- return false;
57
-
58
- return nextPath.get('expression').isAssignmentExpression();
59
- };
64
+ const isNextAssign = createTypeChecker([
65
+ ['-: -> !', callWithNext(isExpressionStatement)],
66
+ ['-', isInsideBlockWithLessThenThreeSiblings],
67
+ ['+', callWithNext(callWithExpression(isAssignmentExpression))],
68
+ ]);
60
69
 
61
70
  export const afterIf = createTypeChecker([
62
71
  ['+', callWithNext(isIfStatement)],
@@ -70,16 +79,3 @@ export const afterIf = createTypeChecker([
70
79
  ['+: parentPath -> ExportNamedDeclaration'],
71
80
  ['+: parentPath -> TSModuleBlock'],
72
81
  ]);
73
-
74
- function notLastPrevVarNotNextVar(path) {
75
- const prev = path.getPrevSibling();
76
- const next = path.getNextSibling();
77
-
78
- if (!exists(prev.getPrevSibling()))
79
- return false;
80
-
81
- if (path.node.loc?.start.line === prev.node?.loc?.start.line + 2)
82
- return false;
83
-
84
- return !isLast(path) && prev.isVariableDeclaration() && !next.isVariableDeclaration();
85
- }
@@ -23,6 +23,7 @@ export const report = (coverage) => {
23
23
  for (const index of difference(fullSet(length), covered)) {
24
24
  const currentType = typeNames[index];
25
25
  const rawCode = createRawCode(currentType);
26
+
26
27
  const code = codeFrameColumns(rawCode, {}, {
27
28
  forceColor: true,
28
29
  });
@@ -8,6 +8,7 @@ const noop = () => {};
8
8
  export const TSTypeParameterDeclaration = (path, printer, semantics) => {
9
9
  const {print, indent} = printer;
10
10
  const isNewline = hasComplexParameters(path);
11
+
11
12
  const printSpace = createPrintSpace({
12
13
  isNewline,
13
14
  printer,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.6.3",
3
+ "version": "18.6.5",
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",