@putout/printer 16.1.0 → 16.2.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 +5 -0
- package/lib/tokenize/comment/parse-leading-comments.js +0 -4
- package/lib/tokenize/typescript/interface/ts-interface-body.js +19 -3
- package/lib/tokenize/typescript/ts-property-signature/comments.js +21 -0
- package/lib/tokenize/typescript/ts-property-signature/ts-property-signature.js +9 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -4,7 +4,6 @@ const {types} = require('@putout/babel');
|
|
|
4
4
|
const {
|
|
5
5
|
hasTrailingComment,
|
|
6
6
|
satisfy,
|
|
7
|
-
isPrev,
|
|
8
7
|
} = require('../is');
|
|
9
8
|
|
|
10
9
|
const {markBefore} = require('../mark');
|
|
@@ -179,9 +178,6 @@ module.exports.parseLeadingComments = (path, printer, semantics, {currentTravers
|
|
|
179
178
|
|
|
180
179
|
print(`/*${value}*/`);
|
|
181
180
|
|
|
182
|
-
if (isTSPropertySignature(path) && !isPrev(path))
|
|
183
|
-
print.breakline();
|
|
184
|
-
|
|
185
181
|
if (path.isStatement() || path.isTSEnumMember() || looksLikeDirective || looksLikeMethod || looksLikeProp || looksLikeSwitchCase) {
|
|
186
182
|
print.newline();
|
|
187
183
|
markBefore(path);
|
|
@@ -13,22 +13,38 @@ module.exports.TSInterfaceBody = (path, printer, semantics) => {
|
|
|
13
13
|
|
|
14
14
|
write.space();
|
|
15
15
|
write('{');
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
maybe.write.newline(hasNoLeadingComments(path));
|
|
17
18
|
indent.inc();
|
|
18
19
|
|
|
19
20
|
parseComments(path, printer, semantics);
|
|
20
21
|
|
|
21
|
-
for (const item of body) {
|
|
22
|
-
|
|
22
|
+
for (const [index, item] of body.entries()) {
|
|
23
|
+
if (index || !item.node.leadingComments)
|
|
24
|
+
indent();
|
|
25
|
+
|
|
23
26
|
traverse(item);
|
|
24
27
|
}
|
|
25
28
|
|
|
26
29
|
indent.dec();
|
|
27
30
|
indent();
|
|
31
|
+
|
|
28
32
|
write('}');
|
|
29
33
|
maybe.write.newline(findTSModuleBlock(path));
|
|
30
34
|
};
|
|
31
35
|
|
|
36
|
+
function hasNoLeadingComments(path) {
|
|
37
|
+
const {body} = path.node;
|
|
38
|
+
|
|
39
|
+
if (!body.length)
|
|
40
|
+
return false;
|
|
41
|
+
|
|
42
|
+
const [first] = body;
|
|
43
|
+
const {leadingComments} = first;
|
|
44
|
+
|
|
45
|
+
return !leadingComments;
|
|
46
|
+
}
|
|
47
|
+
|
|
32
48
|
function findTSModuleBlock(path) {
|
|
33
49
|
if (path.parentPath.parentPath.isTSModuleBlock())
|
|
34
50
|
return true;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {isPrev} = require('#is');
|
|
4
|
+
const noop = () => {};
|
|
5
|
+
|
|
6
|
+
module.exports.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
|
|
7
|
+
const {print} = printer;
|
|
8
|
+
print.breakline();
|
|
9
|
+
printComment();
|
|
10
|
+
print.breakline();
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
module.exports.printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
|
|
14
|
+
const {print, maybe} = printer;
|
|
15
|
+
|
|
16
|
+
maybe.print.breakline(!isPrev(path));
|
|
17
|
+
printComment();
|
|
18
|
+
print.indent();
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
module.exports.printTrailingCommentBlock = noop;
|
|
@@ -9,9 +9,14 @@ const {
|
|
|
9
9
|
|
|
10
10
|
const {printKey} = require('../../expressions/object-expression/print-key');
|
|
11
11
|
|
|
12
|
+
const {
|
|
13
|
+
printLeadingCommentLine,
|
|
14
|
+
printLeadingCommentBlock,
|
|
15
|
+
printTrailingCommentBlock,
|
|
16
|
+
} = require('./comments');
|
|
17
|
+
|
|
12
18
|
module.exports.TSPropertySignature = (path, printer) => {
|
|
13
19
|
const {maybe, write} = printer;
|
|
14
|
-
|
|
15
20
|
const {optional, readonly} = path.node;
|
|
16
21
|
|
|
17
22
|
maybe.print(readonly, 'readonly ');
|
|
@@ -28,6 +33,9 @@ module.exports.TSPropertySignature = (path, printer) => {
|
|
|
28
33
|
if (isNext(path) && hasTrailingComment(path))
|
|
29
34
|
write.newline();
|
|
30
35
|
};
|
|
36
|
+
module.exports.TSPropertySignature.printLeadingCommentLine = printLeadingCommentLine;
|
|
37
|
+
module.exports.TSPropertySignature.printLeadingCommentBlock = printLeadingCommentBlock;
|
|
38
|
+
module.exports.TSPropertySignature.printTrailingCommentBlock = printTrailingCommentBlock;
|
|
31
39
|
|
|
32
40
|
function isTSTypeLiteralWithOneMember({parentPath}) {
|
|
33
41
|
if (!parentPath.parentPath.isTSTypeParameterInstantiation())
|
package/package.json
CHANGED