@putout/printer 8.20.1 → 8.21.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
|
@@ -54,7 +54,7 @@ function isCommentOnNextLine(path) {
|
|
|
54
54
|
if (isTrailingIsLeading(path))
|
|
55
55
|
return false;
|
|
56
56
|
|
|
57
|
-
if (
|
|
57
|
+
if (path.isThrowStatement())
|
|
58
58
|
return false;
|
|
59
59
|
|
|
60
60
|
const [comment] = trailingComments;
|
|
@@ -82,7 +82,7 @@ module.exports.parseTrailingComments = (path, {write, maybe}, semantics) => {
|
|
|
82
82
|
|
|
83
83
|
const n = trailingComments.length - 1;
|
|
84
84
|
|
|
85
|
-
for (const {type, value, loc} of trailingComments) {
|
|
85
|
+
for (const [index, {type, value, loc}] of trailingComments.entries()) {
|
|
86
86
|
const sameLine = isSameLine(path, loc);
|
|
87
87
|
const commentOnNextLine = isCommentOnNextLine(path);
|
|
88
88
|
|
package/lib/tokenize/is.js
CHANGED
|
@@ -123,7 +123,17 @@ module.exports.satisfy = (conditions) => (path) => {
|
|
|
123
123
|
return false;
|
|
124
124
|
};
|
|
125
125
|
|
|
126
|
-
|
|
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,10 @@
|
|
|
2
2
|
|
|
3
3
|
const {parseComments} = require('../../comment/comment');
|
|
4
4
|
const {getDirectives} = require('../block-statement/get-directives');
|
|
5
|
+
const {
|
|
6
|
+
hasTrailingComment,
|
|
7
|
+
hasCoupleTrailingComments,
|
|
8
|
+
} = require('../../is');
|
|
5
9
|
|
|
6
10
|
module.exports.Program = (path, printer, semantics) => {
|
|
7
11
|
const {body} = path.node;
|
|
@@ -28,5 +32,8 @@ module.exports.Program = (path, printer, semantics) => {
|
|
|
28
32
|
if (directives.length && !body.length)
|
|
29
33
|
return;
|
|
30
34
|
|
|
35
|
+
if (body.length && hasCoupleTrailingComments(body.at(-1)))
|
|
36
|
+
return;
|
|
37
|
+
|
|
31
38
|
write.endOfFile();
|
|
32
39
|
};
|
package/package.json
CHANGED