@putout/printer 18.52.0 → 18.52.1

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.1
2
+
3
+ feature:
4
+ - 8b19aaa1 VariableDeclarator: comments: improve
5
+
1
6
  2026.11.22, v18.52.0
2
7
 
3
8
  feature:
@@ -1,3 +1,4 @@
1
+ import {isCommentOnPreviousLine} from './is-comment-on-previous-line.js';
1
2
  import {printCommentBlock} from './print-comment-block.js';
2
3
 
3
4
  const createPrintCommentLine = (fn, value) => () => fn(`//${value}`);
@@ -60,6 +61,7 @@ export const printLeadingComments = (path, printer, semantics, {currentTraverse}
60
61
  index,
61
62
  printComment: createPrintCommentLine(print, value),
62
63
  isLast: index === n,
64
+ isPreviousLine: () => isCommentOnPreviousLine(path),
63
65
  });
64
66
  continue;
65
67
  }
@@ -0,0 +1,20 @@
1
+ const isCommentOfPrevious = (path) => {
2
+ const [comment] = path.node.leadingComments;
3
+ const prev = path.getPrevSibling();
4
+
5
+ return prev.node.loc.start.line === comment.loc.start.line;
6
+ };
7
+
8
+ export const isCommentOnPreviousLine = (path) => {
9
+ const {
10
+ loc,
11
+ leadingComments,
12
+ } = path.node;
13
+
14
+ const [comment] = leadingComments;
15
+
16
+ if (isCommentOfPrevious(path))
17
+ return false;
18
+
19
+ return comment.loc.start.line <= loc.start.line - 1;
20
+ };
@@ -25,7 +25,6 @@ const {
25
25
 
26
26
  const isProperty = satisfy([
27
27
  isObjectProperty,
28
- isVariableDeclarator,
29
28
  isClassProperty,
30
29
  isTSPropertySignature,
31
30
  isSpreadElement,
@@ -19,6 +19,7 @@ import {
19
19
  } from './after-if.js';
20
20
  import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
21
21
  import {beforeIf} from './before-if.js';
22
+ import {VariableDeclarator} from './variable-declarator.js';
22
23
  import {
23
24
  isInsideParentLike,
24
25
  isNeedBreaklineAfterComma,
@@ -95,7 +96,9 @@ export const VariableDeclaration = {
95
96
  write(',');
96
97
 
97
98
  if (hasLeadingComment(next)) {
98
- parseLeadingComments(next, printer, semantics);
99
+ parseLeadingComments(next, printer, semantics, {
100
+ currentTraverse: VariableDeclarator,
101
+ });
99
102
  continue;
100
103
  }
101
104
 
@@ -0,0 +1,26 @@
1
+ export const VariableDeclarator = {};
2
+
3
+ VariableDeclarator.printLeadingCommentLine = (path, printer, semantics, {printComment, isLast, isPreviousLine}) => {
4
+ const {print} = printer;
5
+
6
+ if (isPreviousLine())
7
+ print.breakline();
8
+ else
9
+ print.space();
10
+
11
+ printComment();
12
+
13
+ if (isLast) {
14
+ print.breakline();
15
+ return;
16
+ }
17
+
18
+ print.newline();
19
+ };
20
+
21
+ VariableDeclarator.printLeadingCommentBlock = (path, printer, semantics, {index}) => {
22
+ const {print} = printer;
23
+ const {value} = path.node.leadingComments[index];
24
+
25
+ print(`/*${value}*/`);
26
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.52.0",
3
+ "version": "18.52.1",
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",