@putout/printer 15.27.0 → 15.28.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.11.27, v15.28.0
2
+
3
+ feature:
4
+ - b47c2fc @putout/printer: ObjectPattern: properties: leadingComments
5
+
1
6
  2025.11.12, v15.27.0
2
7
 
3
8
  feature:
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ const createPrintCommentLine = (fn) => (value) => fn(`//${value}`);
4
+ const createPrintCommentBlock = (fn) => (value) => fn(`/*${value}*/`);
5
+
6
+ module.exports.printLeadingComments = (path, {print}) => {
7
+ const printCommentLine = createPrintCommentLine(print);
8
+ const printCommentBlock = createPrintCommentBlock(print);
9
+ const {leadingComments} = path.node;
10
+
11
+ if (!leadingComments)
12
+ return;
13
+
14
+ for (const {type, value} of leadingComments) {
15
+ if (type === 'CommentLine')
16
+ printCommentLine(value);
17
+ else
18
+ printCommentBlock(value);
19
+
20
+ print.breakline();
21
+ }
22
+ };
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('@putout/babel');
4
+
4
5
  const {wrongShorthand} = require('./wrong-shorthand');
5
6
 
6
7
  const {
@@ -20,6 +21,8 @@ const {
20
21
  isLongAssignPattern,
21
22
  } = require('./calculate-long-assign-pattern');
22
23
 
24
+ const {printLeadingComments} = require('./comments');
25
+
23
26
  const {
24
27
  isObjectExpression,
25
28
  isIdentifier,
@@ -152,6 +155,9 @@ module.exports.ObjectPattern = {
152
155
  if (!isAssign && nextAssignObject)
153
156
  print.breakline();
154
157
 
158
+ printLeadingComments(property, {
159
+ print,
160
+ });
155
161
  printKey(property, printer);
156
162
 
157
163
  if (!shorthand || wrongShorthand({computed, isAssign, keyPath, valuePath})) {
@@ -273,11 +279,23 @@ function hasObjectPattern(properties) {
273
279
  const ONE_LINE = false;
274
280
  const COUPLE_LINES = true;
275
281
 
282
+ function hasPropertyLeadingComment(properties) {
283
+ for (const property of properties) {
284
+ if (property.node.leadingComments)
285
+ return true;
286
+ }
287
+
288
+ return false;
289
+ }
290
+
276
291
  function shouldAddNewline(path, semantics) {
277
292
  const {parentPath} = path;
278
293
  const properties = path.get('properties');
279
294
  const n = properties.length - 1;
280
295
 
296
+ if (hasPropertyLeadingComment(properties))
297
+ return true;
298
+
281
299
  const {
282
300
  maxPropertiesInOneLine,
283
301
  maxPropertiesLengthInOneLine,
@@ -88,9 +88,9 @@ module.exports.ImportDeclaration = {
88
88
  maybe.write(n, ',');
89
89
 
90
90
  const last = index === n;
91
- const penulty = index === n - 1;
91
+ const penalty = index === n - 1;
92
92
 
93
- maybe.write.newline(penulty && defaults.length);
93
+ maybe.write.newline(penalty && defaults.length);
94
94
  maybe.write.newline(last);
95
95
  }
96
96
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "15.27.0",
3
+ "version": "15.28.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",