@putout/printer 1.73.1 → 1.73.2
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
package/lib/tokenize/comments.js
CHANGED
|
@@ -2,10 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const {isNext} = require('./is');
|
|
4
4
|
|
|
5
|
-
const {
|
|
6
|
-
markBefore,
|
|
7
|
-
isMarkedAfter,
|
|
8
|
-
} = require('./mark');
|
|
5
|
+
const {markBefore} = require('./mark');
|
|
9
6
|
|
|
10
7
|
module.exports.parseLeadingComments = (path, {print, maybe, indent}) => {
|
|
11
8
|
const {leadingComments} = path.node;
|
|
@@ -64,10 +61,6 @@ module.exports.parseTrailingComments = (path, {write, maybe}) => {
|
|
|
64
61
|
maybe.write.space(sameLine);
|
|
65
62
|
maybe.indent(!sameLine);
|
|
66
63
|
|
|
67
|
-
if (!isMarkedAfter(path) && !sameLine) {
|
|
68
|
-
write.newline();
|
|
69
|
-
}
|
|
70
|
-
|
|
71
64
|
write(`//${value}`);
|
|
72
65
|
write.newline();
|
|
73
66
|
}
|
package/lib/tokenize/is.js
CHANGED
|
@@ -84,6 +84,8 @@ module.exports.satisfy = (conditions) => (path) => {
|
|
|
84
84
|
return false;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
+
module.exports.hasTrailingComment = (path) => path.node?.trailingComments?.length;
|
|
88
|
+
|
|
87
89
|
module.exports.noTrailingComment = (path) => !path.node.trailingComments?.length;
|
|
88
90
|
module.exports.noComment = (path) => !path.node.comments?.length;
|
|
89
91
|
module.exports.noLeadingComment = (path) => !path.node.leadingComments?.length;
|
|
@@ -7,8 +7,17 @@ const {
|
|
|
7
7
|
isParentLast,
|
|
8
8
|
isNewlineBetweenSiblings,
|
|
9
9
|
satisfy,
|
|
10
|
+
noTrailingComment,
|
|
11
|
+
hasTrailingComment,
|
|
10
12
|
} = require('../is');
|
|
11
13
|
|
|
14
|
+
const isNextLiteral = (path) => {
|
|
15
|
+
const next = path.getNextSibling();
|
|
16
|
+
const expression = next.get('expression');
|
|
17
|
+
|
|
18
|
+
return expression.isLiteral();
|
|
19
|
+
};
|
|
20
|
+
|
|
12
21
|
const shouldBreakline = satisfy([
|
|
13
22
|
isNewlineBetweenSiblings,
|
|
14
23
|
isNotLastBody,
|
|
@@ -23,7 +32,7 @@ module.exports.ExpressionStatement = {
|
|
|
23
32
|
|
|
24
33
|
if (shouldBreakline(path)) {
|
|
25
34
|
print.newline();
|
|
26
|
-
maybe.indent(isNext(path));
|
|
35
|
+
maybe.indent(isNext(path) && noTrailingComment(path));
|
|
27
36
|
store(true);
|
|
28
37
|
}
|
|
29
38
|
},
|
|
@@ -34,6 +43,9 @@ module.exports.ExpressionStatement = {
|
|
|
34
43
|
isNextUp,
|
|
35
44
|
],
|
|
36
45
|
after(path, {print, maybe, store}) {
|
|
46
|
+
if (hasTrailingComment(path) && isNextLiteral(path))
|
|
47
|
+
return;
|
|
48
|
+
|
|
37
49
|
print.newline();
|
|
38
50
|
maybe.markAfter(store(), path);
|
|
39
51
|
},
|
package/package.json
CHANGED