@putout/printer 15.7.0 → 15.9.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,15 @@
1
+ 2025.07.03, v15.9.0
2
+
3
+ feature:
4
+ - 57013dc @putout/printer: ExpressionStatement: inside BlockStatement: leading comment
5
+ - f2f187f @putout/printer: ExpressionStatement inside ArrowFunction: leadinging comment
6
+ - 0afbf8d @putout/printer: @putout/plugin-printer v6.0.0
7
+
8
+ 2025.07.02, v15.8.0
9
+
10
+ feature:
11
+ - 3576b80 @putout/printer: ImportDeclaration: comments before ExpressionStatement
12
+
1
13
  2025.07.02, v15.7.0
2
14
 
3
15
  feature:
@@ -21,13 +21,27 @@ module.exports.printLeadingComments = (path, printer, semantics, {currentTravers
21
21
  leadingComments = [],
22
22
  } = path.node;
23
23
 
24
- const {printLeadingCommentLine} = currentTraverse;
24
+ const {
25
+ printLeadingCommentLine,
26
+ printLeadingCommentBlock,
27
+ } = currentTraverse;
28
+
29
+ const n = leadingComments.length - 1;
25
30
 
26
31
  for (const [index, {type, value}] of leadingComments.entries()) {
27
- if (type === 'CommentLine')
32
+ if (type === 'CommentLine') {
28
33
  printLeadingCommentLine?.(path, printer, semantics, {
29
34
  index,
30
35
  printComment: createPrintCommentLine(print, value),
36
+ isLast: index === n,
37
+ });
38
+ continue;
39
+ }
40
+
41
+ if (type === 'CommentBlock')
42
+ printLeadingCommentBlock?.(path, printer, semantics, {
43
+ index,
44
+ printComment: createPrintCommentBlock(print, value),
31
45
  });
32
46
  }
33
47
  };
@@ -38,9 +52,23 @@ module.exports.printTrailingComments = (path, printer, semantics, {currentTraver
38
52
  trailingComments = [],
39
53
  } = path.node;
40
54
 
41
- const {printTrailingCommentBlock} = currentTraverse;
55
+ const {
56
+ printTrailingCommentLine,
57
+ printTrailingCommentBlock,
58
+ } = currentTraverse;
59
+
60
+ const n = trailingComments.length - 1;
42
61
 
43
62
  for (const [index, {type, value}] of trailingComments.entries()) {
63
+ if (type === 'CommentLine') {
64
+ printTrailingCommentLine?.(path, printer, semantics, {
65
+ index,
66
+ printComment: createPrintCommentLine(print, value),
67
+ isLast: index === n,
68
+ });
69
+ continue;
70
+ }
71
+
44
72
  if (type === 'CommentBlock')
45
73
  printTrailingCommentBlock?.(path, printer, semantics, {
46
74
  index,
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('@putout/babel');
4
+ const {hasTrailingComment} = require('#is');
5
+
6
+ const {
7
+ isBlockStatement,
8
+ isProgram,
9
+ isIfStatement,
10
+ } = types;
11
+
12
+ module.exports.printLeadingCommentLine = (path, printer, semantics, {index, isLast, printComment}) => {
13
+ const {print, indent} = printer;
14
+ const prev = path.getPrevSibling();
15
+ const {parentPath} = path;
16
+
17
+ if (hasTrailingComment(prev))
18
+ return;
19
+
20
+ if (!index && !prev.node && (isIfStatement(parentPath) || isBlockStatement(parentPath)))
21
+ indent();
22
+
23
+ printComment();
24
+ print.newline();
25
+
26
+ if (!isLast && !path.parentPath.isIfStatement())
27
+ print.indent();
28
+ };
29
+
30
+ module.exports.printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
31
+ const {indent} = printer;
32
+ const prev = path.getPrevSibling();
33
+
34
+ if (hasTrailingComment(prev))
35
+ return;
36
+
37
+ if (isBlockStatement(path.parentPath) && !isProgram(path.parentPath.parentPath))
38
+ indent();
39
+
40
+ printComment();
41
+ };
@@ -15,6 +15,12 @@ const {
15
15
  } = require('../../is');
16
16
 
17
17
  const {isInsideAssignNextAssignFunction} = require('./is-inside-assign-next-assign-function');
18
+
19
+ const {
20
+ printLeadingCommentLine,
21
+ printLeadingCommentBlock,
22
+ } = require('./comments');
23
+
18
24
  const isCommentBlock = (a) => a?.type === 'CommentBlock';
19
25
 
20
26
  const {
@@ -117,6 +123,8 @@ module.exports.ExpressionStatement = {
117
123
  }
118
124
  },
119
125
  };
126
+ module.exports.ExpressionStatement.printLeadingCommentLine = printLeadingCommentLine;
127
+ module.exports.ExpressionStatement.printLeadingCommentBlock = printLeadingCommentBlock;
120
128
 
121
129
  function isTopParentLast({parentPath}) {
122
130
  if (!parentPath.isIfStatement())
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('@putout/babel');
4
+ const {isExportDeclaration} = types;
5
+
6
+ module.exports.printTrailingCommentLine = (path, printer, semantics, {printComment}) => {
7
+ const {print} = printer;
8
+ printComment();
9
+ print.breakline();
10
+ };
11
+
12
+ module.exports.printTrailingCommentBlock = (path, printer, semantics, {printComment}) => {
13
+ const {maybe} = printer;
14
+ const next = path.getNextSibling();
15
+
16
+ maybe.print.breakline(!isExportDeclaration(next));
17
+ printComment();
18
+ };
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {parseImportSpecifiers} = require('parse-import-specifiers');
4
- const {types} = require('@putout/babel');
4
+
5
5
  const {markAfter} = require('../../mark');
6
6
  const {isLast, isNext} = require('../../is');
7
7
 
@@ -10,7 +10,10 @@ const {
10
10
  ImportAttribute,
11
11
  } = require('./import-attribute');
12
12
 
13
- const {isExportDeclaration} = types;
13
+ const {
14
+ printTrailingCommentBlock,
15
+ printTrailingCommentLine,
16
+ } = require('./comments');
14
17
 
15
18
  module.exports.ImportAttribute = ImportAttribute;
16
19
  module.exports.ImportDeclaration = {
@@ -137,10 +140,5 @@ function parseMaxSpecifiers(imports, semantics) {
137
140
  return maxSpecifiersInOneLine;
138
141
  }
139
142
 
140
- module.exports.ImportDeclaration.printTrailingCommentBlock = (path, printer, semantics, {printComment}) => {
141
- const {maybe} = printer;
142
- const next = path.getNextSibling();
143
-
144
- maybe.print.breakline(!isExportDeclaration(next));
145
- printComment();
146
- };
143
+ module.exports.ImportDeclaration.printTrailingCommentBlock = printTrailingCommentBlock;
144
+ module.exports.ImportDeclaration.printTrailingCommentLine = printTrailingCommentLine;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "15.7.0",
3
+ "version": "15.9.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",
@@ -71,7 +71,7 @@
71
71
  "devDependencies": {
72
72
  "@putout/eslint": "^4.1.0",
73
73
  "@putout/plugin-minify": "^10.0.0",
74
- "@putout/plugin-printer": "^5.0.0",
74
+ "@putout/plugin-printer": "^6.0.0",
75
75
  "@putout/plugin-promises": "^18.0.0",
76
76
  "@putout/plugin-react-hook-form": "^6.0.0",
77
77
  "@putout/plugin-react-hooks": "^9.0.0",