@putout/printer 8.20.1 → 8.22.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,13 @@
1
+ 2024.04.29, v8.22.0
2
+
3
+ feature:
4
+ - 1d67db1 @putout/printer: improve trailingComments support
5
+
6
+ 2024.04.29, v8.21.0
7
+
8
+ feature:
9
+ - 2abb228 @putout/printer: comments: improve
10
+
1
11
  2024.04.24, v8.20.1
2
12
 
3
13
  feature:
@@ -54,7 +54,7 @@ function isCommentOnNextLine(path) {
54
54
  if (isTrailingIsLeading(path))
55
55
  return false;
56
56
 
57
- if (trailingComments.length > 1)
57
+ if (path.isThrowStatement())
58
58
  return false;
59
59
 
60
60
  const [comment] = trailingComments;
@@ -62,10 +62,13 @@ function isCommentOnNextLine(path) {
62
62
 
63
63
  const next = path.getNextSibling();
64
64
 
65
- if (line < next.node?.loc.start.line)
65
+ if (next.node && line < next.node.loc.start.line)
66
66
  return false;
67
67
 
68
- return line === loc.start.line + 1;
68
+ const isNextLine = line === loc.start.line + 1;
69
+ const isNextLineAfterNewline = line === loc.start.line + 2;
70
+
71
+ return isNextLine || isNextLineAfterNewline;
69
72
  }
70
73
 
71
74
  module.exports.parseTrailingComments = (path, {write, maybe}, semantics) => {
@@ -123,7 +123,17 @@ module.exports.satisfy = (conditions) => (path) => {
123
123
  return false;
124
124
  };
125
125
 
126
- module.exports.hasTrailingComment = (path) => path.node?.trailingComments?.length;
126
+ const parseNode = (path) => path.node || path;
127
+
128
+ module.exports.hasCoupleTrailingComments = (path) => {
129
+ const node = parseNode(path);
130
+ return node?.trailingComments?.length > 1;
131
+ };
132
+
133
+ module.exports.hasTrailingComment = (path) => {
134
+ const node = parseNode(path);
135
+ return node.trailingComments?.length;
136
+ };
127
137
  module.exports.hasLeadingComment = (path) => path.node?.leadingComments?.length;
128
138
 
129
139
  module.exports.noTrailingComment = (path) => !path.node.trailingComments?.length;
@@ -2,6 +2,7 @@
2
2
 
3
3
  const {parseComments} = require('../../comment/comment');
4
4
  const {getDirectives} = require('../block-statement/get-directives');
5
+ const {hasCoupleTrailingComments} = require('../../is');
5
6
 
6
7
  module.exports.Program = (path, printer, semantics) => {
7
8
  const {body} = path.node;
@@ -28,5 +29,8 @@ module.exports.Program = (path, printer, semantics) => {
28
29
  if (directives.length && !body.length)
29
30
  return;
30
31
 
32
+ if (body.length && hasCoupleTrailingComments(body.at(-1)))
33
+ return;
34
+
31
35
  write.endOfFile();
32
36
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.20.1",
3
+ "version": "8.22.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",