@putout/printer 12.27.0 → 12.28.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/expressions/function/params.js +2 -1
- package/lib/tokenize/expressions/function/print-function-params.js +55 -14
- package/lib/tokenize/typescript/index.js +2 -0
- package/lib/tokenize/typescript/ts-parameter-property/ts-parameter-property.js +0 -1
- package/lib/tokenize/typescript/ts-parenthesized-type/ts-parenthesized-type.js +7 -0
- package/package.json +2 -2
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2025.02.08, v12.28.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 306e48c @putout/printer: @putout/operate v13.0.0
|
|
5
|
+
- 240f1e8 @putout/printer: TSParenthesizedType: add
|
|
6
|
+
|
|
7
|
+
2025.02.08, v12.27.1
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- bd1a8cd @putout/printer: decorators: comments: improve
|
|
11
|
+
|
|
1
12
|
2025.02.08, v12.27.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -37,8 +37,9 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
|
|
|
37
37
|
|
|
38
38
|
for (let i = 0; i <= n; i++) {
|
|
39
39
|
const isLast = i === n;
|
|
40
|
+
const current = params[i];
|
|
40
41
|
|
|
41
|
-
traverse(
|
|
42
|
+
traverse(current);
|
|
42
43
|
|
|
43
44
|
if (!isLast) {
|
|
44
45
|
print(',');
|
|
@@ -3,36 +3,51 @@
|
|
|
3
3
|
const {printParams} = require('./params');
|
|
4
4
|
const {hasLeadingComment} = require('../../is');
|
|
5
5
|
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
6
|
+
const isAllParamsHasLeadingComments = (path) => {
|
|
7
|
+
const params = path.get('params');
|
|
8
|
+
let commentsCount = 0;
|
|
9
|
+
let decoratorsCount = 0;
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
|
|
11
|
+
for (const param of params) {
|
|
12
|
+
const decorators = param.get('decorators');
|
|
13
|
+
|
|
14
|
+
if (!decorators.length)
|
|
15
|
+
continue;
|
|
16
|
+
|
|
17
|
+
const [firstDecorator] = decorators;
|
|
18
|
+
++decoratorsCount;
|
|
19
|
+
|
|
20
|
+
if (hasLeadingComment(firstDecorator))
|
|
21
|
+
++commentsCount;
|
|
22
|
+
}
|
|
12
23
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return hasLeadingComment(firstDecorator);
|
|
24
|
+
return commentsCount === decoratorsCount;
|
|
16
25
|
};
|
|
17
26
|
|
|
18
27
|
const hasDecorators = ({decorators}) => decorators?.length;
|
|
19
28
|
|
|
20
29
|
module.exports.printFunctionParams = (path, printer, semantics) => {
|
|
21
|
-
const {print} = printer;
|
|
22
30
|
const {params} = path.node;
|
|
23
31
|
const isNewline = params.filter(hasDecorators).length;
|
|
24
|
-
const
|
|
32
|
+
const isAllHasComments = isAllParamsHasLeadingComments(path);
|
|
25
33
|
|
|
26
|
-
const
|
|
34
|
+
const printSpace = createPrintSpace({
|
|
35
|
+
isNewline,
|
|
36
|
+
printer,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const printBeforeFirst = createPrintBeforeFirst(path, {
|
|
27
40
|
type: 'inc',
|
|
28
41
|
printer,
|
|
29
42
|
isNewline,
|
|
43
|
+
isAllHasComments,
|
|
30
44
|
});
|
|
31
45
|
|
|
32
|
-
const printAfterLast =
|
|
46
|
+
const printAfterLast = createPrintAfterLast({
|
|
33
47
|
type: 'dec',
|
|
34
48
|
printer,
|
|
35
49
|
isNewline,
|
|
50
|
+
isAllHasComments,
|
|
36
51
|
});
|
|
37
52
|
|
|
38
53
|
printParams(path, printer, semantics, {
|
|
@@ -42,14 +57,40 @@ module.exports.printFunctionParams = (path, printer, semantics) => {
|
|
|
42
57
|
});
|
|
43
58
|
};
|
|
44
59
|
|
|
45
|
-
const
|
|
60
|
+
const createPrintBeforeFirst = (path, {isNewline, isAllHasComments, printer, type}) => () => {
|
|
46
61
|
if (!isNewline)
|
|
47
62
|
return;
|
|
48
63
|
|
|
49
64
|
const {indent, print} = printer;
|
|
50
65
|
|
|
51
|
-
if (!
|
|
66
|
+
if (!isAllHasComments)
|
|
52
67
|
indent[type]();
|
|
53
68
|
|
|
54
69
|
print.breakline();
|
|
70
|
+
|
|
71
|
+
const [first] = path.get('params');
|
|
72
|
+
|
|
73
|
+
if (!first.node.decorators)
|
|
74
|
+
indent();
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
const createPrintAfterLast = ({isNewline, printer, isAllHasComments, type}) => () => {
|
|
78
|
+
if (!isNewline)
|
|
79
|
+
return;
|
|
80
|
+
|
|
81
|
+
const {indent, print} = printer;
|
|
82
|
+
|
|
83
|
+
if (!isAllHasComments)
|
|
84
|
+
indent[type]();
|
|
85
|
+
|
|
86
|
+
print.breakline();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const createPrintSpace = ({isNewline, printer}) => () => {
|
|
90
|
+
const {print} = printer;
|
|
91
|
+
|
|
92
|
+
if (!isNewline)
|
|
93
|
+
return print.space();
|
|
94
|
+
|
|
95
|
+
print.breakline();
|
|
55
96
|
};
|
|
@@ -38,6 +38,7 @@ const {TSTypeReference} = require('./ts-type-reference/ts-type-reference');
|
|
|
38
38
|
const {TSInferType} = require('./ts-infer-type/ts-infer-type');
|
|
39
39
|
const {TSParameterProperty} = require('./ts-parameter-property/ts-parameter-property');
|
|
40
40
|
const {TSTypeQuery} = require('./ts-type-query/ts-type-query');
|
|
41
|
+
const {TSParenthesizedType} = require('./ts-parenthesized-type/ts-parenthesized-type');
|
|
41
42
|
|
|
42
43
|
module.exports = {
|
|
43
44
|
TSAsExpression,
|
|
@@ -171,6 +172,7 @@ module.exports = {
|
|
|
171
172
|
print('__expression');
|
|
172
173
|
print('__typeArguments');
|
|
173
174
|
},
|
|
175
|
+
TSParenthesizedType,
|
|
174
176
|
TSPropertySignature,
|
|
175
177
|
TSFunctionType,
|
|
176
178
|
TSTypePredicate(path, {print}) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "12.
|
|
3
|
+
"version": "12.28.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@putout/babel": "^3.0.0",
|
|
36
36
|
"@putout/compare": "^16.0.1",
|
|
37
|
-
"@putout/operate": "^
|
|
37
|
+
"@putout/operate": "^13.0.0",
|
|
38
38
|
"@putout/operator-json": "^2.0.0",
|
|
39
39
|
"fullstore": "^3.0.0",
|
|
40
40
|
"just-snake-case": "^3.2.0",
|