@putout/printer 18.0.0 → 18.0.1

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,15 @@
1
+ 2026.03.04, v18.0.1
2
+
3
+ feature:
4
+ - 5e6e906 @putout/printer: VariableDeclaration: after: simplify
5
+ - 852f982 @putout/printer: @putout/plugin-printer v8.0.0
6
+ - 7b3977d @putout/printer: VariableDeclaration: skipAfter
7
+ - 4f43a9f VariableDeclaration: isNeedNewline
8
+ - 9dece24 @putout/printer: VariableDeclaration: isSemicolon
9
+ - b9a27e0 @putout/printer: VariableDeclaration: isInsideIf
10
+ - 06d6255 @putout/printer: is: isParentProgram -> isInsideProgram
11
+ - 2a0ef4e is: isParentBlock -> isInsideBlock
12
+
1
13
  2026.03.04, v18.0.0
2
14
 
3
15
  feature:
@@ -60,6 +60,7 @@ const isSiblingIsArray = (path) => {
60
60
  };
61
61
 
62
62
  const isEmptyArray = (path) => !path.node.elements.length;
63
+
63
64
  const isAllLiterals = (path) => {
64
65
  const {elements} = path.node;
65
66
  const literals = elements.filter(isStringLiteral);
@@ -329,4 +330,3 @@ export const isCurrentNewLine = (path) => {
329
330
 
330
331
  return !path.isObjectExpression();
331
332
  };
332
-
@@ -1,7 +1,7 @@
1
1
  import {maybeParens} from '#maybe-parens';
2
2
  import {
3
- isParentBlock,
4
- isParentProgram,
3
+ isInsideBlock,
4
+ isInsideProgram,
5
5
  } from '#is';
6
6
  import {condition} from './maybe-parens-condition.js';
7
7
  import {printSeparator} from './print-separator.js';
@@ -27,7 +27,7 @@ export const AssignmentExpression = maybeParens({
27
27
  printSeparator(path, printer);
28
28
  print('__right');
29
29
 
30
- if (isParentBlock(path) || isParentProgram(path)) {
30
+ if (isInsideBlock(path) || isInsideProgram(path)) {
31
31
  print(';');
32
32
  print.breakline();
33
33
  }
@@ -1,4 +1,4 @@
1
- import {exists} from '#is';
1
+ import {exists, isInsideCall} from '#is';
2
2
  import {maybeParens} from '#maybe-parens';
3
3
 
4
4
  const {isArray} = Array;
@@ -14,7 +14,7 @@ const parseArgs = (path) => {
14
14
 
15
15
  export const CallExpression = maybeParens((path, {indent, print, maybe, traverse}) => {
16
16
  const args = parseArgs(path);
17
- const isParentCall = tooLong(args) && path.parentPath.isCallExpression();
17
+ const isParentCall = tooLong(args) && isInsideCall(path);
18
18
 
19
19
  const callee = path.get('callee');
20
20
  const typeParameters = path.get('typeArguments');
@@ -18,8 +18,8 @@ const {
18
18
  isTSModuleBlock,
19
19
  } = types;
20
20
 
21
- export const isParentProgram = (path) => isProgram(path.parentPath);
22
- export const isParentBlock = (path) => isBlockStatement(path.parentPath);
21
+ export const isInsideProgram = (path) => isProgram(path.parentPath);
22
+ export const isInsideBlock = (path) => isBlockStatement(path.parentPath);
23
23
 
24
24
  export const isParentBlockLike = createTypeChecker('path.parentPath', [
25
25
  'Program',
@@ -59,7 +59,7 @@ export const isPrev = (path) => {
59
59
  };
60
60
 
61
61
  export const isNextParent = (path) => isNext(path.parentPath);
62
- export const isLast = (path) => isParentProgram(path) && !isNext(path);
62
+ export const isLast = (path) => isInsideProgram(path) && !isNext(path);
63
63
 
64
64
  export const isNextObject = (a) => a
65
65
  .getNextSibling()
@@ -2,11 +2,11 @@ import {types} from '@putout/babel';
2
2
  import {createTypeChecker} from '#type-checker';
3
3
  import {
4
4
  isNext,
5
- isParentProgram,
5
+ isInsideProgram,
6
6
  isLast,
7
7
  exists,
8
8
  satisfy,
9
- isParentBlock,
9
+ isInsideBlock,
10
10
  } from '#is';
11
11
  import {insideIfWithNoBody} from './inside-if-with-no-body.js';
12
12
 
@@ -27,7 +27,7 @@ const isTopLevelWithNoNext = (path) => {
27
27
  if (isNext(path))
28
28
  return false;
29
29
 
30
- return !isNext(path.parentPath) && isParentProgram(path.parentPath);
30
+ return !isNext(path.parentPath) && isInsideProgram(path.parentPath);
31
31
  };
32
32
 
33
33
  const isInsideDoWhile = ({parentPath}) => isDoWhileStatement(parentPath);
@@ -55,7 +55,7 @@ const isNoNewline = satisfy([
55
55
  ]);
56
56
 
57
57
  export const shouldAddNewlineAfter = createTypeChecker([
58
- ['+', isParentBlock],
58
+ ['+', isInsideBlock],
59
59
  ['-', isNoNewline],
60
60
  ['+', isInsideIfWithoutElseInsideFn],
61
61
  ['-', isEmptyBodyNoNext],
@@ -1,5 +1,5 @@
1
1
  import {
2
- isParentBlock,
2
+ isInsideBlock,
3
3
  isNextParent,
4
4
  isInsideIf,
5
5
  isInsideLabel,
@@ -21,7 +21,7 @@ export const BreakStatement = {
21
21
  print(';');
22
22
  },
23
23
  afterSatisfy: () => [
24
- isParentBlock,
24
+ isInsideBlock,
25
25
  isNextParent,
26
26
  isInsideCase,
27
27
  isInsideIf,
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  isNext,
3
3
  isInsideIf,
4
- isParentBlock,
4
+ isInsideBlock,
5
5
  } from '#is';
6
6
 
7
7
  export const DebuggerStatement = {
@@ -11,7 +11,7 @@ export const DebuggerStatement = {
11
11
  },
12
12
  afterSatisfy: () => [
13
13
  isNext,
14
- isParentBlock,
14
+ isInsideBlock,
15
15
  isInsideIf,
16
16
  ],
17
17
  after(path, {print}) {
@@ -1,7 +1,7 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {printAttributes} from '#import-attributes';
3
3
  import {
4
- isParentBlock,
4
+ isInsideBlock,
5
5
  isNewlineBetweenSiblings,
6
6
  exists,
7
7
  isNext,
@@ -169,7 +169,7 @@ export const ExportNamedDeclaration = {
169
169
  if (isNewlineBetweenSiblings(path))
170
170
  return true;
171
171
 
172
- return isParentBlock(path);
172
+ return isInsideBlock(path);
173
173
  },
174
174
  after(path, {print, indent}) {
175
175
  const next = path.getNextSibling();
@@ -2,7 +2,7 @@ import {types} from '@putout/babel';
2
2
  import {
3
3
  isNext,
4
4
  isLast,
5
- isParentBlock,
5
+ isInsideBlock,
6
6
  isParentLast,
7
7
  isNewlineBetweenSiblings,
8
8
  satisfy,
@@ -42,7 +42,7 @@ const notInsideReturn = not(isInsideReturn);
42
42
 
43
43
  const satisfyAfter = satisfy([
44
44
  isNotLastOrParentLast,
45
- isParentBlock,
45
+ isInsideBlock,
46
46
  isNext,
47
47
  isNextUp,
48
48
  ]);
@@ -1,5 +1,5 @@
1
1
  import {types} from '@putout/babel';
2
- import {isNext, isParentBlock} from '#is';
2
+ import {isNext, isInsideBlock} from '#is';
3
3
 
4
4
  const {isBlockStatement} = types;
5
5
 
@@ -24,6 +24,6 @@ export const printTrailingCommentLine = (path, printer, semantics, {printComment
24
24
 
25
25
  printComment();
26
26
 
27
- if (hasNext || isParentBlock(path))
27
+ if (hasNext || isInsideBlock(path))
28
28
  print.newline();
29
29
  };
@@ -2,7 +2,7 @@ import {types} from '@putout/babel';
2
2
  import {
3
3
  isNext,
4
4
  isNextTry,
5
- isParentBlock,
5
+ isInsideBlock,
6
6
  } from '#is';
7
7
 
8
8
  const {isExpressionStatement} = types;
@@ -55,5 +55,5 @@ export const CatchClause = (path, {print, maybe}) => {
55
55
  }
56
56
 
57
57
  print(body);
58
- maybe.print.newline(isParentBlock(parentPath));
58
+ maybe.print.newline(isInsideBlock(parentPath));
59
59
  };
@@ -8,26 +8,43 @@ import {
8
8
  exists,
9
9
  noTrailingComment,
10
10
  isParentBlockLike,
11
+ isInsideIf,
12
+ isInsideBlock,
11
13
  } from '#is';
12
14
  import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
13
15
  import {isConcatenation} from '../../expressions/binary-expression/concatenate.js';
14
16
  import {parseLeadingComments} from '../../comment/comment.js';
15
17
  import {maybeDeclare} from '../../maybe/maybe-declare.js';
16
18
 
19
+ const isLast = (path) => path.parentPath?.isProgram() && !isNext(path);
20
+
17
21
  const {isExportDeclaration} = types;
18
22
 
19
23
  const isParentTSModuleBlock = (path) => path.parentPath.isTSModuleBlock();
20
24
  const isParentSwitchCase = (path) => path.parentPath.isSwitchCase();
21
25
  const isFirstInSwitch = (path) => path.parentPath.get('consequent.0') === path;
22
- const isParentIf = (path) => path.parentPath.isIfStatement();
23
26
 
24
- const isParentBlock = createTypeChecker('path.parentPath', [
27
+ const isIsideParentLike = createTypeChecker('path.parentPath', [
25
28
  'Program',
26
29
  'BlockStatement',
27
30
  'ExportNamedDeclaration',
28
31
  'LabeledStatement',
29
32
  ]);
30
33
 
34
+ const isNeedSemicolon = createTypeChecker([
35
+ isIsideParentLike,
36
+ isParentSwitchCase,
37
+ isParentTSModuleBlock,
38
+ isInsideIf,
39
+ ]);
40
+
41
+ const isNeedNewline = createTypeChecker([
42
+ ['-: -> !', isIsideParentLike],
43
+ ['-: -> !', isNext],
44
+ ['+', noTrailingComment],
45
+ ['+', isNewlineBetweenSiblings],
46
+ ]);
47
+
31
48
  export const VariableDeclaration = {
32
49
  beforeIf: shouldAddNewlineBefore,
33
50
  before(path, {print}) {
@@ -78,9 +95,7 @@ export const VariableDeclaration = {
78
95
  }
79
96
 
80
97
  maybe.indent.dec(n);
81
-
82
- if (isParentBlock(path) || isParentSwitchCase(path) || isParentTSModuleBlock(path) || isParentIf(path))
83
- write(';');
98
+ maybe.write(isNeedSemicolon(path), ';');
84
99
 
85
100
  let wasNewline = false;
86
101
 
@@ -91,7 +106,7 @@ export const VariableDeclaration = {
91
106
  wasNewline = true;
92
107
  }
93
108
 
94
- if (isParentBlock(path) && isNext(path) && (noTrailingComment(path) || isNewlineBetweenSiblings(path))) {
109
+ if (isNeedNewline(path)) {
95
110
  write.newline();
96
111
  wasNewline = true;
97
112
  }
@@ -110,18 +125,23 @@ export const VariableDeclaration = {
110
125
  notLastParentExport,
111
126
  isParentTSModuleBlock,
112
127
  ],
113
- after(path, {maybe, store}) {
128
+ after(path, {maybe, store, print}) {
114
129
  const wasNewline = store();
115
130
 
116
- if (isLast(path.parentPath) && !path.parentPath.isBlockStatement() || !isParentBlock(path) && !isParentTSModuleBlock(path))
117
- return false;
131
+ if (skipAfter(path))
132
+ return;
118
133
 
119
- maybe.print.linebreak(wasNewline);
120
- maybe.print.newline(!wasNewline);
134
+ maybe.indent(wasNewline);
135
+ print.newline();
121
136
  maybe.markAfter(wasNewline, path);
122
137
  },
123
138
  };
124
139
 
140
+ const skipAfter = createTypeChecker([
141
+ ['-: parentPath -> !', isLast],
142
+ ['+: -> !', isInsideBlock],
143
+ ]);
144
+
125
145
  function noNextParentBlock(path) {
126
146
  if (isNext(path))
127
147
  return false;
@@ -169,8 +189,6 @@ function isNextCoupleLines(path) {
169
189
  return isCoupleLines(next);
170
190
  }
171
191
 
172
- const isLast = (path) => path.parentPath?.isProgram() && !isNext(path);
173
-
174
192
  function shouldAddNewlineBefore(path) {
175
193
  if (isFirst(path))
176
194
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.0.0",
3
+ "version": "18.0.1",
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",
@@ -70,7 +70,7 @@
70
70
  "@putout/eslint": "^6.0.0",
71
71
  "@putout/eslint-flat": "^4.0.0",
72
72
  "@putout/plugin-minify": "^11.2.1",
73
- "@putout/plugin-printer": "^7.0.0",
73
+ "@putout/plugin-printer": "^8.0.0",
74
74
  "@putout/plugin-promises": "^19.0.0",
75
75
  "@putout/plugin-react-hook-form": "^6.0.0",
76
76
  "@putout/plugin-react-hooks": "^9.0.0",