@putout/printer 12.11.0 → 12.12.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,8 @@
1
+ 2025.01.24, v12.12.0
2
+
3
+ feature:
4
+ - 4a02949 @putout/printer: comments
5
+
1
6
  2025.01.23, v12.11.0
2
7
 
3
8
  feature:
@@ -17,6 +17,7 @@ const {
17
17
  isClassProperty,
18
18
  isTSPropertySignature,
19
19
  isSpreadElement,
20
+ isClassBody,
20
21
  } = types;
21
22
 
22
23
  const isProperty = satisfy([
@@ -70,10 +71,20 @@ function isCommentOnPreviousLine(path) {
70
71
  if (isCommentOfPrevious(path))
71
72
  return false;
72
73
 
73
- return line === loc.start.line - 1;
74
+ return line <= loc.start.line - 1;
74
75
  }
75
76
 
76
- const isFirst = (path) => path === path.parentPath?.get('properties')[0];
77
+ const isFirst = (path) => {
78
+ const {parentPath} = path;
79
+
80
+ if (path === parentPath.get('properties')[0])
81
+ return true;
82
+
83
+ if (isClassBody(parentPath) && isClassProperty(path))
84
+ return path === parentPath.get('body')[0];
85
+
86
+ return false;
87
+ };
77
88
 
78
89
  module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics) => {
79
90
  if (!semantics.comments)
@@ -101,10 +112,13 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
101
112
  && !insideFn
102
113
  && !propIs;
103
114
 
104
- for (const {type, value} of leadingComments) {
105
- maybe.indent(isIndent);
106
-
115
+ const count = leadingComments.length - 1;
116
+
117
+ for (const [index, {type, value}] of leadingComments.entries()) {
107
118
  if (type === 'CommentLine') {
119
+ if (!path.isClassProperty() || index)
120
+ maybe.indent(isIndent);
121
+
108
122
  maybeInsideFn(insideFn, {
109
123
  print,
110
124
  indent,
@@ -117,8 +131,12 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
117
131
 
118
132
  print(`//${value}`);
119
133
 
120
- maybe.print.breakline(propIs);
121
- maybe.print.newline(!propIs);
134
+ if (index === count) {
135
+ maybe.print.breakline(propIs);
136
+ maybe.print.newline(!propIs);
137
+ } else {
138
+ print.newline();
139
+ }
122
140
 
123
141
  if (isInsideVar(path)) {
124
142
  indent.inc();
@@ -130,6 +148,8 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
130
148
  }
131
149
 
132
150
  if (type === 'CommentBlock') {
151
+ maybe.indent(isIndent);
152
+
133
153
  const looksLikeMethod = path.isClassMethod();
134
154
  const looksLikeDirective = path.isDirective();
135
155
  const looksLikeProp = path.isObjectProperty();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "12.11.0",
3
+ "version": "12.12.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
@@ -52,13 +52,16 @@
52
52
  ],
53
53
  "imports": {
54
54
  "#test/printer": {
55
- "default": "./test/printer.js"
55
+ "default": "./test/print-extension/print-extension.js"
56
56
  },
57
57
  "#test/fixture": {
58
58
  "default": "./test/fixture.js"
59
59
  },
60
60
  "#printer": {
61
61
  "default": "./lib/printer.js"
62
+ },
63
+ "#test": {
64
+ "default": "./test/create-test.js"
62
65
  }
63
66
  },
64
67
  "devDependencies": {