@putout/printer 18.52.0 → 18.52.1
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/comments-printer/comments-printer.js +2 -0
- package/lib/tokenize/comments/comments-printer/is-comment-on-previous-line.js +20 -0
- package/lib/tokenize/comments/parse-leading-comments.js +0 -1
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +4 -1
- package/lib/tokenize/statements/variable-declaration/variable-declarator.js +26 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import {isCommentOnPreviousLine} from './is-comment-on-previous-line.js';
|
|
1
2
|
import {printCommentBlock} from './print-comment-block.js';
|
|
2
3
|
|
|
3
4
|
const createPrintCommentLine = (fn, value) => () => fn(`//${value}`);
|
|
@@ -60,6 +61,7 @@ export const printLeadingComments = (path, printer, semantics, {currentTraverse}
|
|
|
60
61
|
index,
|
|
61
62
|
printComment: createPrintCommentLine(print, value),
|
|
62
63
|
isLast: index === n,
|
|
64
|
+
isPreviousLine: () => isCommentOnPreviousLine(path),
|
|
63
65
|
});
|
|
64
66
|
continue;
|
|
65
67
|
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const isCommentOfPrevious = (path) => {
|
|
2
|
+
const [comment] = path.node.leadingComments;
|
|
3
|
+
const prev = path.getPrevSibling();
|
|
4
|
+
|
|
5
|
+
return prev.node.loc.start.line === comment.loc.start.line;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export const isCommentOnPreviousLine = (path) => {
|
|
9
|
+
const {
|
|
10
|
+
loc,
|
|
11
|
+
leadingComments,
|
|
12
|
+
} = path.node;
|
|
13
|
+
|
|
14
|
+
const [comment] = leadingComments;
|
|
15
|
+
|
|
16
|
+
if (isCommentOfPrevious(path))
|
|
17
|
+
return false;
|
|
18
|
+
|
|
19
|
+
return comment.loc.start.line <= loc.start.line - 1;
|
|
20
|
+
};
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
} from './after-if.js';
|
|
20
20
|
import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
|
|
21
21
|
import {beforeIf} from './before-if.js';
|
|
22
|
+
import {VariableDeclarator} from './variable-declarator.js';
|
|
22
23
|
import {
|
|
23
24
|
isInsideParentLike,
|
|
24
25
|
isNeedBreaklineAfterComma,
|
|
@@ -95,7 +96,9 @@ export const VariableDeclaration = {
|
|
|
95
96
|
write(',');
|
|
96
97
|
|
|
97
98
|
if (hasLeadingComment(next)) {
|
|
98
|
-
parseLeadingComments(next, printer, semantics
|
|
99
|
+
parseLeadingComments(next, printer, semantics, {
|
|
100
|
+
currentTraverse: VariableDeclarator,
|
|
101
|
+
});
|
|
99
102
|
continue;
|
|
100
103
|
}
|
|
101
104
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const VariableDeclarator = {};
|
|
2
|
+
|
|
3
|
+
VariableDeclarator.printLeadingCommentLine = (path, printer, semantics, {printComment, isLast, isPreviousLine}) => {
|
|
4
|
+
const {print} = printer;
|
|
5
|
+
|
|
6
|
+
if (isPreviousLine())
|
|
7
|
+
print.breakline();
|
|
8
|
+
else
|
|
9
|
+
print.space();
|
|
10
|
+
|
|
11
|
+
printComment();
|
|
12
|
+
|
|
13
|
+
if (isLast) {
|
|
14
|
+
print.breakline();
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
print.newline();
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
VariableDeclarator.printLeadingCommentBlock = (path, printer, semantics, {index}) => {
|
|
22
|
+
const {print} = printer;
|
|
23
|
+
const {value} = path.node.leadingComments[index];
|
|
24
|
+
|
|
25
|
+
print(`/*${value}*/`);
|
|
26
|
+
};
|
package/package.json
CHANGED