@putout/printer 18.52.2 → 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,8 @@
1
+ 2026.11.22, v18.52.3
2
+
3
+ feature:
4
+ - 591947ec @putout/printer: SpreadElement: comments: simplify
5
+
1
6
  2026.11.22, v18.52.2
2
7
 
3
8
  feature:
@@ -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
+ };
@@ -15,18 +15,13 @@ const {
15
15
  isVariableDeclarator,
16
16
  isClassProperty,
17
17
  isTSPropertySignature,
18
- isSpreadElement,
19
18
  isClassBody,
20
19
  isBinaryExpression,
21
20
  isClassMethod,
22
21
  isDecorator,
23
22
  } = types;
24
23
 
25
- const isProperty = satisfy([
26
- isClassProperty,
27
- isTSPropertySignature,
28
- isSpreadElement,
29
- ]);
24
+ const isProperty = satisfy([isClassProperty, isTSPropertySignature]);
30
25
 
31
26
  const isInsideVar = (path) => {
32
27
  const {parentPath} = path;
@@ -42,13 +37,6 @@ const isInsideVar = (path) => {
42
37
 
43
38
  const hasDecoratorsWithComments = (path) => path?.parentPath.node?.decorators;
44
39
 
45
- function isCommentOfPrevious(path) {
46
- const [comment] = path.node.leadingComments;
47
- const {line} = comment.loc.start;
48
-
49
- return path.getPrevSibling().node?.loc.start.line === line;
50
- }
51
-
52
40
  function isCommentOnPreviousLine(path) {
53
41
  const {
54
42
  loc,
@@ -61,18 +49,12 @@ function isCommentOnPreviousLine(path) {
61
49
  const [comment] = leadingComments;
62
50
  const {line} = comment.loc.start;
63
51
 
64
- if (isCommentOfPrevious(path))
65
- return false;
66
-
67
52
  return line <= loc.start.line - 1;
68
53
  }
69
54
 
70
55
  const isFirst = (path) => {
71
56
  const {parentPath} = path;
72
57
 
73
- if (path === parentPath.get('properties')[0])
74
- return true;
75
-
76
58
  if (isClassBody(parentPath) && isClassProperty(path))
77
59
  return path === parentPath.get('body')[0];
78
60
 
@@ -130,8 +112,6 @@ export const parseLeadingComments = (path, printer, semantics, {currentTraverse
130
112
 
131
113
  if (isCommentOnPreviousLine(path))
132
114
  maybe.print.breakline(!isFirst(path));
133
- else
134
- maybe.print.space(propIs && !path.isClassProperty());
135
115
 
136
116
  print(`//${value}`);
137
117
 
@@ -1,5 +1,9 @@
1
1
  import {isConcatenation} from '#is-concatenation';
2
2
  import {markBefore} from '#mark';
3
+ import {
4
+ isFirstProperty,
5
+ printPropertyLeadingCommentLine,
6
+ } from '../../comments/comments-printer/property-comments.js';
3
7
  import {isMultiline} from './object-expression.js';
4
8
  import {printKey} from './print-key.js';
5
9
  import {isCommaAfterProperty} from './comma.js';
@@ -33,32 +37,11 @@ export const ObjectProperty = (path, printer, semantics) => {
33
37
  write.space();
34
38
  };
35
39
 
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
- };
40
+ ObjectProperty.printLeadingCommentLine = printPropertyLeadingCommentLine;
58
41
 
59
42
  ObjectProperty.printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
60
43
  const {maybe, indent} = printer;
61
- const first = isFirst(path);
44
+ const first = isFirstProperty(path);
62
45
 
63
46
  maybe.indent(first);
64
47
  maybe.print.breakline(!first);
@@ -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.2",
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",