@putout/printer 12.26.0 → 12.27.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 +10 -0
- package/lib/tokenize/comment/parse-leading-comments.js +8 -6
- package/lib/tokenize/expressions/function/params.js +3 -1
- package/lib/tokenize/expressions/function/print-function-params.js +63 -6
- package/lib/tokenize/typescript/ts-parameter-property/ts-parameter-property.js +0 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -20,6 +20,7 @@ const {
|
|
|
20
20
|
isClassBody,
|
|
21
21
|
isBinaryExpression,
|
|
22
22
|
isClassMethod,
|
|
23
|
+
isDecorator,
|
|
23
24
|
} = types;
|
|
24
25
|
|
|
25
26
|
const isProperty = satisfy([
|
|
@@ -42,13 +43,14 @@ const isInsideVar = (path) => {
|
|
|
42
43
|
return isVariableDeclarator(parentPath.parentPath);
|
|
43
44
|
};
|
|
44
45
|
|
|
45
|
-
const
|
|
46
|
-
|
|
46
|
+
const hasDecoratorsWithComments = (path) => {
|
|
47
|
+
if (isDecorator(path))
|
|
48
|
+
return false;
|
|
47
49
|
|
|
48
|
-
if (path.node.decorators
|
|
50
|
+
if (path.node.decorators)
|
|
49
51
|
return true;
|
|
50
52
|
|
|
51
|
-
return parentPath.node
|
|
53
|
+
return path?.parentPath.node?.decorators;
|
|
52
54
|
};
|
|
53
55
|
|
|
54
56
|
function isCommentOfPrevious(path) {
|
|
@@ -97,7 +99,7 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
|
|
|
97
99
|
if (!leadingComments?.length)
|
|
98
100
|
return;
|
|
99
101
|
|
|
100
|
-
if (
|
|
102
|
+
if (hasDecoratorsWithComments(path))
|
|
101
103
|
return;
|
|
102
104
|
|
|
103
105
|
const looksLikeSwitchCase = path.isSwitchCase();
|
|
@@ -139,7 +141,7 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
|
|
|
139
141
|
|
|
140
142
|
if (isClassMethod(path)) {
|
|
141
143
|
indent();
|
|
142
|
-
} else if (isBinaryExpression(path)) {
|
|
144
|
+
} else if (isBinaryExpression(path) || isDecorator(path)) {
|
|
143
145
|
indent.inc();
|
|
144
146
|
indent();
|
|
145
147
|
indent.dec();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {parseComments} = require('../../comment/comment');
|
|
4
|
+
|
|
4
5
|
const noop = () => {};
|
|
5
6
|
const parseParams = (path) => path.get('params');
|
|
6
7
|
|
|
@@ -36,8 +37,9 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
|
|
|
36
37
|
|
|
37
38
|
for (let i = 0; i <= n; i++) {
|
|
38
39
|
const isLast = i === n;
|
|
40
|
+
const current = params[i];
|
|
39
41
|
|
|
40
|
-
traverse(
|
|
42
|
+
traverse(current);
|
|
41
43
|
|
|
42
44
|
if (!isLast) {
|
|
43
45
|
print(',');
|
|
@@ -1,25 +1,53 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {printParams} = require('./params');
|
|
4
|
+
const {hasLeadingComment} = require('../../is');
|
|
5
|
+
|
|
6
|
+
const isAllParamsHasLeadingComments = (path) => {
|
|
7
|
+
const params = path.get('params');
|
|
8
|
+
let commentsCount = 0;
|
|
9
|
+
let decoratorsCount = 0;
|
|
10
|
+
|
|
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
|
+
}
|
|
23
|
+
|
|
24
|
+
return commentsCount === decoratorsCount;
|
|
25
|
+
};
|
|
4
26
|
|
|
5
27
|
const hasDecorators = ({decorators}) => decorators?.length;
|
|
6
28
|
|
|
7
29
|
module.exports.printFunctionParams = (path, printer, semantics) => {
|
|
8
|
-
const {print} = printer;
|
|
9
30
|
const {params} = path.node;
|
|
10
31
|
const isNewline = params.filter(hasDecorators).length;
|
|
11
|
-
const
|
|
32
|
+
const isAllHasComments = isAllParamsHasLeadingComments(path);
|
|
12
33
|
|
|
13
|
-
const
|
|
34
|
+
const printSpace = createPrintSpace({
|
|
35
|
+
isNewline,
|
|
36
|
+
printer,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const printBeforeFirst = createPrintBeforeFirst(path, {
|
|
14
40
|
type: 'inc',
|
|
15
41
|
printer,
|
|
16
42
|
isNewline,
|
|
43
|
+
isAllHasComments,
|
|
17
44
|
});
|
|
18
45
|
|
|
19
|
-
const printAfterLast =
|
|
46
|
+
const printAfterLast = createPrintAfterLast({
|
|
20
47
|
type: 'dec',
|
|
21
48
|
printer,
|
|
22
49
|
isNewline,
|
|
50
|
+
isAllHasComments,
|
|
23
51
|
});
|
|
24
52
|
|
|
25
53
|
printParams(path, printer, semantics, {
|
|
@@ -29,11 +57,40 @@ module.exports.printFunctionParams = (path, printer, semantics) => {
|
|
|
29
57
|
});
|
|
30
58
|
};
|
|
31
59
|
|
|
32
|
-
const
|
|
60
|
+
const createPrintBeforeFirst = (path, {isNewline, isAllHasComments, printer, type}) => () => {
|
|
33
61
|
if (!isNewline)
|
|
34
62
|
return;
|
|
35
63
|
|
|
36
64
|
const {indent, print} = printer;
|
|
37
|
-
|
|
65
|
+
|
|
66
|
+
if (!isAllHasComments)
|
|
67
|
+
indent[type]();
|
|
68
|
+
|
|
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
|
+
|
|
38
95
|
print.breakline();
|
|
39
96
|
};
|
package/package.json
CHANGED