@putout/printer 18.18.0 → 18.20.0

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,14 @@
1
+ 2026.06.20, v18.20.0
2
+
3
+ feature:
4
+ - b38b9939 @putout/printer: new line before leading Comment, after CallExpression
5
+
6
+ 2026.06.19, v18.19.0
7
+
8
+ feature:
9
+ - ec918867 @putout/printer: @babel/parser v8.0.0
10
+ - 339814ed @putout/printer: TSImportEqualsDeclaration: newline
11
+
1
12
  2026.06.10, v18.18.0
2
13
 
3
14
  feature:
@@ -1,14 +1,27 @@
1
+ import {types} from '@putout/babel';
1
2
  import {createTypeChecker} from '#type-checker';
2
3
  import {
3
4
  hasTrailingComment,
4
- isCoupleLines,
5
5
  isInsideBlock,
6
+ isInsideReturn,
6
7
  isLast,
7
8
  isNext,
8
9
  isParentLast,
9
10
  satisfy,
11
+ exists,
12
+ isCoupleLines,
10
13
  } from '#is';
11
14
 
15
+ const {
16
+ isCallExpression,
17
+ isAssignmentExpression,
18
+ isArrayExpression,
19
+ isStringLiteral,
20
+ isTemplateLiteral,
21
+ isExpressionStatement,
22
+ isStatement,
23
+ } = types;
24
+
12
25
  function isNotLastOrParentLast(path) {
13
26
  return !isLast(path) && !isParentLast(path);
14
27
  }
@@ -37,16 +50,80 @@ const isBeforeElse = createTypeChecker([
37
50
  ['+: parentPath.node.alternate -> +'],
38
51
  ]);
39
52
 
40
- const hasTrailingCommentNotCoupleLines = createTypeChecker([
41
- ['-: -> !', hasTrailingComment],
42
- ['+: -> !', isCoupleLines],
43
- ]);
53
+ const isNextCallWithLeadingComments = (path) => {
54
+ const next = path.getNextSibling();
55
+
56
+ if (!exists(next))
57
+ return false;
58
+
59
+ if (!path.node.trailingComments)
60
+ return false;
61
+
62
+ if (isStatement(next) && isCoupleLines(path))
63
+ return true;
64
+
65
+ if (!isExpressionStatement(next))
66
+ return false;
67
+
68
+ const {expression} = path.node;
69
+
70
+ if (isCallExpression(expression))
71
+ return true;
72
+
73
+ const nextExpression = next.get('expression');
74
+
75
+ return isCallExpression(nextExpression);
76
+ };
77
+
78
+ function isNextWithLeadingComments(path) {
79
+ const next = path.getNextSibling();
80
+ const {expression} = path.node;
81
+
82
+ if (!path.node.trailingComments)
83
+ return true;
84
+
85
+ if (isAssignmentExpression(expression))
86
+ return true;
87
+
88
+ return !exists(next);
89
+ }
90
+
91
+ export function isNextSimpleWithLeadingComments(path) {
92
+ const next = path.getNextSibling();
93
+
94
+ if (!hasTrailingComment(path))
95
+ return false;
96
+
97
+ if (!isExpressionStatement(next))
98
+ return false;
99
+
100
+ const {expression} = next.node;
101
+
102
+ if (isStringLiteral(expression))
103
+ return true;
104
+
105
+ if (isTemplateLiteral(expression))
106
+ return true;
107
+
108
+ return isArrayExpression(next.node.expression);
109
+ }
110
+
111
+ function isAssignWithTrailingComments(path) {
112
+ const {expression} = path.node;
113
+
114
+ if (!isAssignmentExpression(expression))
115
+ return false;
116
+
117
+ return hasTrailingComment(path);
118
+ }
44
119
 
45
120
  export const afterIf = createTypeChecker([
121
+ ['-', isInsideReturn],
46
122
  ['-', isTopParentLast],
47
- ['-', hasTrailingCommentNotCoupleLines],
123
+ ['+', isNextCallWithLeadingComments],
124
+ ['-: -> !', isNextWithLeadingComments],
125
+ ['+', isAssignWithTrailingComments],
126
+ ['-: node.trailingComments.length -> +'],
48
127
  ['+', satisfyAfter],
49
128
  ['+', isBeforeElse],
50
- ['-: -> !', hasTrailingComment],
51
- ['+', isLast],
52
129
  ]);
@@ -2,11 +2,8 @@ import {types} from '@putout/babel';
2
2
  import {createTypeChecker} from '#type-checker';
3
3
  import {
4
4
  isNext,
5
- isLast,
6
5
  isNewlineBetweenSiblings,
7
6
  noTrailingComment,
8
- hasTrailingComment,
9
- isCoupleLines,
10
7
  isInsideReturn,
11
8
  callWithNext,
12
9
  hasLeadingComment,
@@ -15,7 +12,10 @@ import {
15
12
  printLeadingCommentLine,
16
13
  printLeadingCommentBlock,
17
14
  } from './comments.js';
18
- import {afterIf} from './after-if.js';
15
+ import {
16
+ afterIf,
17
+ isNextSimpleWithLeadingComments,
18
+ } from './after-if.js';
19
19
  import {beforeIf} from './before-if.js';
20
20
 
21
21
  const {isIfStatement} = types;
@@ -30,12 +30,6 @@ const isNextToAssignmentCall = createTypeChecker([
30
30
  ['+', callWithNext(isCallInsideExpression)],
31
31
  ]);
32
32
 
33
- const isBreaklineAfter = createTypeChecker([
34
- ['-: -> !', hasTrailingComment],
35
- ['-: -> !', isLast],
36
- ['+', isCoupleLines],
37
- ]);
38
-
39
33
  const isNextStatementWithBlockComment = createTypeChecker([
40
34
  '-: node.expression -> !CallExpression',
41
35
  '-: node.expression.arguments.0 -> !CallExpression',
@@ -80,13 +74,11 @@ export const ExpressionStatement = {
80
74
  },
81
75
  afterIf,
82
76
  after(path, {print, maybe, store}) {
83
- maybe.print.breakline(isBreaklineAfter(path));
77
+ maybe.indent(isIndentAfter(path));
84
78
 
85
- if (isInsideReturn(path))
86
- return;
79
+ if (!isNextSimpleWithLeadingComments(path))
80
+ print.newline();
87
81
 
88
- maybe.indent(isIndentAfter(path));
89
- print.newline();
90
82
  maybe.markAfter(store(), path);
91
83
  },
92
84
  };
@@ -1,4 +1,3 @@
1
- import {isNext} from '#is';
2
1
  import {printParams} from '#print-params';
3
2
  import {maybePrintTypeAnnotation} from '../maybe/maybe-type-annotation.js';
4
3
 
@@ -12,6 +11,7 @@ export {TSDeclareFunction} from './function/ts-declare-function.js';
12
11
  export {TSDeclareMethod} from './function/ts-declare-method.js';
13
12
  export {TSModuleDeclaration, TSModuleBlock} from './namespace/ts-module-declaration.js';
14
13
  export {TSInterfaceDeclaration} from './interface/ts-interface-declaration.js';
14
+ export {TSImportEqualsDeclaration} from './ts-import-equals-declaration/ts-import-equals-declaration.js';
15
15
  export {TSAsExpression} from './ts-as-expression/ts-as-expression.js';
16
16
  export {TSInterfaceBody} from './interface/ts-interface-body.js';
17
17
  export {TSIntersectionType} from './ts-intersection-type.js';
@@ -151,17 +151,6 @@ export const TSTypePredicate = (path, {print}) => {
151
151
  print('__typeAnnotation');
152
152
  };
153
153
 
154
- export const TSImportEqualsDeclaration = (path, {print, maybe}) => {
155
- maybe.print(path.node.isExport, 'export ');
156
- print('import ');
157
- print('__id');
158
- print.space();
159
- print('=');
160
- print.space();
161
- print('__moduleReference');
162
- print(';');
163
- maybe.print.newline(isNext(path));
164
- };
165
154
  export const TSExternalModuleReference = (path, {print}) => {
166
155
  print('require(');
167
156
  print('__expression');
@@ -0,0 +1,15 @@
1
+ import {isLast} from '#is';
2
+
3
+ export const TSImportEqualsDeclaration = (path, {print, maybe}) => {
4
+ maybe.print(path.node.isExport, 'export ');
5
+ print('import ');
6
+ print('__id');
7
+ print.space();
8
+ print('=');
9
+ print.space();
10
+ print('__moduleReference');
11
+ print(';');
12
+
13
+ if (!isLast(path) && !isLast(path.parentPath))
14
+ print.newline();
15
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.18.0",
3
+ "version": "18.20.0",
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",
@@ -76,7 +76,7 @@
76
76
  "#comments": "./lib/tokenize/comments/comments.js"
77
77
  },
78
78
  "devDependencies": {
79
- "@babel/parser": "^7.28.5",
79
+ "@babel/parser": "^8.0.0",
80
80
  "@putout/eslint": "^6.0.0",
81
81
  "@putout/eslint-flat": "^4.0.0",
82
82
  "@putout/plugin-minify": "^12.0.0",