@putout/printer 1.40.1 → 1.40.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 +5 -0
- package/lib/tokenize/comments.js +11 -4
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/lib/tokenize/comments.js
CHANGED
|
@@ -45,7 +45,7 @@ module.exports.parseLeadingComments = (path, {print, maybe}) => {
|
|
|
45
45
|
}
|
|
46
46
|
};
|
|
47
47
|
|
|
48
|
-
module.exports.parseTrailingComments = (path, {
|
|
48
|
+
module.exports.parseTrailingComments = (path, {write, maybe}) => {
|
|
49
49
|
const {trailingComments} = path.node;
|
|
50
50
|
|
|
51
51
|
if (!trailingComments || !trailingComments.length)
|
|
@@ -54,10 +54,13 @@ module.exports.parseTrailingComments = (path, {print}) => {
|
|
|
54
54
|
if (isNext(path))
|
|
55
55
|
return;
|
|
56
56
|
|
|
57
|
-
for (const {type, value} of trailingComments) {
|
|
57
|
+
for (const {type, value, loc} of trailingComments) {
|
|
58
58
|
if (type === 'CommentLine') {
|
|
59
|
-
|
|
60
|
-
|
|
59
|
+
const sameLine = isSameLine(path, loc);
|
|
60
|
+
maybe.write.space(sameLine);
|
|
61
|
+
maybe.indent(!sameLine);
|
|
62
|
+
write(`//${value}`);
|
|
63
|
+
maybe.write.newline(!sameLine);
|
|
61
64
|
|
|
62
65
|
continue;
|
|
63
66
|
}
|
|
@@ -67,3 +70,7 @@ module.exports.parseTrailingComments = (path, {print}) => {
|
|
|
67
70
|
function shouldAddNewlineBefore(path) {
|
|
68
71
|
return path.isStatement() && !isFirst(path) && !hasPrevNewline(path);
|
|
69
72
|
}
|
|
73
|
+
|
|
74
|
+
function isSameLine(path, loc) {
|
|
75
|
+
return path.node.loc.start.line === loc.start.line;
|
|
76
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.40.
|
|
3
|
+
"version": "1.40.2",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",
|