@putout/printer 16.1.0 → 16.3.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 +11 -0
- package/lib/tokenize/comment/parse-leading-comments.js +0 -4
- package/lib/tokenize/expressions/object-expression/object-property.js +1 -4
- package/lib/tokenize/typescript/index.js +1 -1
- package/lib/tokenize/typescript/interface/ts-interface-body.js +19 -3
- package/lib/tokenize/typescript/{ts-import-type.js → ts-import-type/ts-import-type.js} +1 -1
- 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/lib/tokenize/typescript/type/ts-type-literal.js +8 -3
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2025.12.09, v16.3.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 5c8c2ff @putout/printer: TSTypeLiteral: indent
|
|
5
|
+
- 6419576 @putout/printer: TSImportType: trailing comma
|
|
6
|
+
|
|
7
|
+
2025.12.09, v16.2.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- e0a7a89 @putout/printer: TSPropertySignature: comments: improve support
|
|
11
|
+
|
|
1
12
|
2025.12.08, v16.1.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -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);
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {types} = require('@putout/babel');
|
|
4
3
|
const {isConcatenation} = require('../binary-expression/concatenate');
|
|
5
4
|
const {isOneLine} = require('./object-expression');
|
|
6
5
|
const {printKey} = require('./print-key');
|
|
7
|
-
const {isTSImportType} = types;
|
|
8
|
-
const isInsideTSImportType = ({parentPath}) => isTSImportType(parentPath.parentPath);
|
|
9
6
|
|
|
10
7
|
module.exports.ObjectProperty = (path, printer, semantics) => {
|
|
11
8
|
const {trailingComma} = semantics;
|
|
@@ -29,7 +26,7 @@ module.exports.ObjectProperty = (path, printer, semantics) => {
|
|
|
29
26
|
traverse(value);
|
|
30
27
|
}
|
|
31
28
|
|
|
32
|
-
if (manyLines
|
|
29
|
+
if (manyLines)
|
|
33
30
|
maybe.write(!isLast || trailingComma, ',');
|
|
34
31
|
else if (!isLast && properties.length)
|
|
35
32
|
write(', ');
|
|
@@ -32,7 +32,7 @@ const {TSMethodSignature} = require('./function/ts-method-signature');
|
|
|
32
32
|
const {TSUnionType} = require('./ts-union-type/ts-union-type');
|
|
33
33
|
|
|
34
34
|
const {maybePrintTypeAnnotation} = require('../maybe/maybe-type-annotation');
|
|
35
|
-
const {TSImportType} = require('./ts-import-type');
|
|
35
|
+
const {TSImportType} = require('./ts-import-type/ts-import-type');
|
|
36
36
|
const {TSExportAssignment} = require('./ts-export-assignment/ts-export-assignment');
|
|
37
37
|
const {TSTypeReference} = require('./ts-type-reference/ts-type-reference');
|
|
38
38
|
const {TSInferType} = require('./ts-infer-type/ts-infer-type');
|
|
@@ -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;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {createImportExpression} = require('
|
|
3
|
+
const {createImportExpression} = require('../../expressions/import-expression');
|
|
4
4
|
|
|
5
5
|
module.exports.TSImportType = (path, printer) => {
|
|
6
6
|
createImportExpression(path, printer);
|
|
@@ -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())
|
|
@@ -25,10 +25,15 @@ module.exports.TSTypeLiteral = (path, {indent, traverse, write}) => {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
function isNewline(path) {
|
|
28
|
-
const
|
|
28
|
+
const {parentPath} = path;
|
|
29
|
+
|
|
30
|
+
const {length} = path.get('members');
|
|
29
31
|
|
|
30
|
-
if (
|
|
32
|
+
if (!length)
|
|
31
33
|
return false;
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
if (length > 1)
|
|
36
|
+
return true;
|
|
37
|
+
|
|
38
|
+
return !parentPath.isTSTypeParameterInstantiation();
|
|
34
39
|
}
|
package/package.json
CHANGED