@putout/printer 18.52.1 → 18.52.2

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.11.22, v18.52.2
2
+
3
+ feature:
4
+ - e27532f0 @putout/printer: ObjectProperty: comments: improve
5
+
1
6
  2026.11.22, v18.52.1
2
7
 
3
8
  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
 
@@ -12,7 +12,6 @@ import {
12
12
 
13
13
  const {
14
14
  isArrowFunctionExpression,
15
- isObjectProperty,
16
15
  isVariableDeclarator,
17
16
  isClassProperty,
18
17
  isTSPropertySignature,
@@ -24,7 +23,6 @@ const {
24
23
  } = types;
25
24
 
26
25
  const isProperty = satisfy([
27
- isObjectProperty,
28
26
  isClassProperty,
29
27
  isTSPropertySignature,
30
28
  isSpreadElement,
@@ -166,17 +164,13 @@ export const parseLeadingComments = (path, printer, semantics, {currentTraverse
166
164
 
167
165
  const looksLikeMethod = path.isClassMethod();
168
166
  const looksLikeDirective = path.isDirective();
169
- const looksLikeProp = path.isObjectProperty();
170
-
171
- if (looksLikeProp)
172
- print.breakline();
173
167
 
174
168
  print(`/*${value}*/`);
175
169
 
176
- if (path.isStatement() || path.isTSEnumMember() || looksLikeDirective || looksLikeMethod || looksLikeProp || looksLikeSwitchCase) {
170
+ if (path.isStatement() || path.isTSEnumMember() || looksLikeDirective || looksLikeMethod || looksLikeSwitchCase) {
177
171
  print.newline();
178
172
  markBefore(path);
179
- maybe.indent(looksLikeMethod || looksLikeProp || looksLikeSwitchCase);
173
+ maybe.indent(looksLikeMethod || looksLikeSwitchCase);
180
174
  }
181
175
 
182
176
  continue;
@@ -1,4 +1,5 @@
1
1
  import {isConcatenation} from '#is-concatenation';
2
+ import {markBefore} from '#mark';
2
3
  import {isMultiline} from './object-expression.js';
3
4
  import {printKey} from './print-key.js';
4
5
  import {isCommaAfterProperty} from './comma.js';
@@ -31,3 +32,37 @@ export const ObjectProperty = (path, printer, semantics) => {
31
32
  if (isSpaceAfterComma(path, {multiline}))
32
33
  write.space();
33
34
  };
35
+
36
+ const isFirst = (path) => path === path.parentPath.get('properties')[0];
37
+
38
+ ObjectProperty.printLeadingCommentLine = (path, printer, semantics, {printComment, isLast, isPreviousLine}) => {
39
+ const {print, maybe} = printer;
40
+ const first = isFirst(path);
41
+
42
+ maybe.indent(first);
43
+
44
+ if (isPreviousLine())
45
+ maybe.print.breakline(!first);
46
+ else
47
+ print.space();
48
+
49
+ printComment();
50
+
51
+ if (isLast) {
52
+ print.breakline();
53
+ return;
54
+ }
55
+
56
+ print.newline();
57
+ };
58
+
59
+ ObjectProperty.printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
60
+ const {maybe, indent} = printer;
61
+ const first = isFirst(path);
62
+
63
+ maybe.indent(first);
64
+ maybe.print.breakline(!first);
65
+ printComment();
66
+ markBefore(path);
67
+ indent();
68
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.52.1",
3
+ "version": "18.52.2",
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",