@putout/printer 18.52.1 → 18.52.3

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.11.22, v18.52.3
2
+
3
+ feature:
4
+ - 591947ec @putout/printer: SpreadElement: comments: simplify
5
+
6
+ 2026.11.22, v18.52.2
7
+
8
+ feature:
9
+ - e27532f0 @putout/printer: ObjectProperty: comments: improve
10
+
1
11
  2026.11.22, v18.52.1
2
12
 
3
13
  feature:
@@ -2,6 +2,9 @@ const isCommentOfPrevious = (path) => {
2
2
  const [comment] = path.node.leadingComments;
3
3
  const prev = path.getPrevSibling();
4
4
 
5
+ if (!prev.node)
6
+ return false;
7
+
5
8
  return prev.node.loc.start.line === comment.loc.start.line;
6
9
  };
7
10
 
@@ -0,0 +1,22 @@
1
+ export const isFirstProperty = (path) => path === path.parentPath.get('properties')[0];
2
+
3
+ export const printPropertyLeadingCommentLine = (path, printer, semantics, {printComment, isLast, isPreviousLine}) => {
4
+ const {print, maybe} = printer;
5
+ const first = isFirstProperty(path);
6
+
7
+ maybe.indent(first);
8
+
9
+ if (isPreviousLine())
10
+ maybe.print.breakline(!first);
11
+ else
12
+ print.space();
13
+
14
+ printComment();
15
+
16
+ if (isLast) {
17
+ print.breakline();
18
+ return;
19
+ }
20
+
21
+ print.newline();
22
+ };
@@ -12,23 +12,16 @@ import {
12
12
 
13
13
  const {
14
14
  isArrowFunctionExpression,
15
- isObjectProperty,
16
15
  isVariableDeclarator,
17
16
  isClassProperty,
18
17
  isTSPropertySignature,
19
- isSpreadElement,
20
18
  isClassBody,
21
19
  isBinaryExpression,
22
20
  isClassMethod,
23
21
  isDecorator,
24
22
  } = types;
25
23
 
26
- const isProperty = satisfy([
27
- isObjectProperty,
28
- isClassProperty,
29
- isTSPropertySignature,
30
- isSpreadElement,
31
- ]);
24
+ const isProperty = satisfy([isClassProperty, isTSPropertySignature]);
32
25
 
33
26
  const isInsideVar = (path) => {
34
27
  const {parentPath} = path;
@@ -44,13 +37,6 @@ const isInsideVar = (path) => {
44
37
 
45
38
  const hasDecoratorsWithComments = (path) => path?.parentPath.node?.decorators;
46
39
 
47
- function isCommentOfPrevious(path) {
48
- const [comment] = path.node.leadingComments;
49
- const {line} = comment.loc.start;
50
-
51
- return path.getPrevSibling().node?.loc.start.line === line;
52
- }
53
-
54
40
  function isCommentOnPreviousLine(path) {
55
41
  const {
56
42
  loc,
@@ -63,18 +49,12 @@ function isCommentOnPreviousLine(path) {
63
49
  const [comment] = leadingComments;
64
50
  const {line} = comment.loc.start;
65
51
 
66
- if (isCommentOfPrevious(path))
67
- return false;
68
-
69
52
  return line <= loc.start.line - 1;
70
53
  }
71
54
 
72
55
  const isFirst = (path) => {
73
56
  const {parentPath} = path;
74
57
 
75
- if (path === parentPath.get('properties')[0])
76
- return true;
77
-
78
58
  if (isClassBody(parentPath) && isClassProperty(path))
79
59
  return path === parentPath.get('body')[0];
80
60
 
@@ -132,8 +112,6 @@ export const parseLeadingComments = (path, printer, semantics, {currentTraverse
132
112
 
133
113
  if (isCommentOnPreviousLine(path))
134
114
  maybe.print.breakline(!isFirst(path));
135
- else
136
- maybe.print.space(propIs && !path.isClassProperty());
137
115
 
138
116
  print(`//${value}`);
139
117
 
@@ -166,17 +144,13 @@ export const parseLeadingComments = (path, printer, semantics, {currentTraverse
166
144
 
167
145
  const looksLikeMethod = path.isClassMethod();
168
146
  const looksLikeDirective = path.isDirective();
169
- const looksLikeProp = path.isObjectProperty();
170
-
171
- if (looksLikeProp)
172
- print.breakline();
173
147
 
174
148
  print(`/*${value}*/`);
175
149
 
176
- if (path.isStatement() || path.isTSEnumMember() || looksLikeDirective || looksLikeMethod || looksLikeProp || looksLikeSwitchCase) {
150
+ if (path.isStatement() || path.isTSEnumMember() || looksLikeDirective || looksLikeMethod || looksLikeSwitchCase) {
177
151
  print.newline();
178
152
  markBefore(path);
179
- maybe.indent(looksLikeMethod || looksLikeProp || looksLikeSwitchCase);
153
+ maybe.indent(looksLikeMethod || looksLikeSwitchCase);
180
154
  }
181
155
 
182
156
  continue;
@@ -1,4 +1,9 @@
1
1
  import {isConcatenation} from '#is-concatenation';
2
+ import {markBefore} from '#mark';
3
+ import {
4
+ isFirstProperty,
5
+ printPropertyLeadingCommentLine,
6
+ } from '../../comments/comments-printer/property-comments.js';
2
7
  import {isMultiline} from './object-expression.js';
3
8
  import {printKey} from './print-key.js';
4
9
  import {isCommaAfterProperty} from './comma.js';
@@ -31,3 +36,16 @@ export const ObjectProperty = (path, printer, semantics) => {
31
36
  if (isSpaceAfterComma(path, {multiline}))
32
37
  write.space();
33
38
  };
39
+
40
+ ObjectProperty.printLeadingCommentLine = printPropertyLeadingCommentLine;
41
+
42
+ ObjectProperty.printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
43
+ const {maybe, indent} = printer;
44
+ const first = isFirstProperty(path);
45
+
46
+ maybe.indent(first);
47
+ maybe.print.breakline(!first);
48
+ printComment();
49
+ markBefore(path);
50
+ indent();
51
+ };
@@ -1,4 +1,8 @@
1
1
  import {hasTrailingComment} from '#is';
2
+ import {
3
+ isFirstProperty,
4
+ printPropertyLeadingCommentLine,
5
+ } from '../../comments/comments-printer/property-comments.js';
2
6
 
3
7
  export const SpreadElement = (path, printer) => {
4
8
  const {print} = printer;
@@ -8,3 +12,14 @@ export const SpreadElement = (path, printer) => {
8
12
  if (hasTrailingComment(path))
9
13
  print(',');
10
14
  };
15
+
16
+ SpreadElement.printLeadingCommentLine = printPropertyLeadingCommentLine;
17
+
18
+ SpreadElement.printLeadingCommentBlock = (path, printer, semantics, {index}) => {
19
+ const {print, maybe} = printer;
20
+ const {value} = path.node.leadingComments[index];
21
+
22
+ maybe.indent(isFirstProperty(path));
23
+ print(`/*${value}*/`);
24
+ print.space();
25
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.52.1",
3
+ "version": "18.52.3",
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",