@putout/printer 12.24.0 → 12.25.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-trailing-comments.js +7 -2
- package/lib/tokenize/expressions/function/class-method.js +2 -2
- package/lib/tokenize/expressions/function/params.js +13 -8
- package/lib/tokenize/expressions/function/print-function-params.js +39 -0
- package/lib/tokenize/literals/index.js +1 -1
- package/lib/tokenize/typescript/ts-parameter-property/ts-parameter-property.js +17 -8
- package/package.json +1 -1
- /package/lib/tokenize/expressions/{decorator.js → decorator/decorator.js} +0 -0
package/ChangeLog
CHANGED
|
@@ -40,10 +40,15 @@ const isTrailingIsLeading = (path) => path.node.trailingComments === path.getNex
|
|
|
40
40
|
const isNewlineAfter = (path) => {
|
|
41
41
|
const {parentPath} = path;
|
|
42
42
|
|
|
43
|
+
if (isDecorator(path)) {
|
|
44
|
+
const {loc} = path.node.trailingComments[0];
|
|
45
|
+
return !isSameLine(path, loc);
|
|
46
|
+
}
|
|
47
|
+
|
|
43
48
|
if (isMemberExpression(parentPath))
|
|
44
49
|
return false;
|
|
45
50
|
|
|
46
|
-
return !isLast(path)
|
|
51
|
+
return !isLast(path);
|
|
47
52
|
};
|
|
48
53
|
|
|
49
54
|
module.exports.isTrailingIsLeading = isTrailingIsLeading;
|
|
@@ -106,7 +111,7 @@ module.exports.parseTrailingComments = (path, {write, maybe, indent}, semantics)
|
|
|
106
111
|
|
|
107
112
|
if (type === 'CommentLine') {
|
|
108
113
|
const nextLineInChain = commentOnNextLine && likeChain;
|
|
109
|
-
const shouldIndent = !sameLine &&
|
|
114
|
+
const shouldIndent = !sameLine && !commentOnNextLine;
|
|
110
115
|
|
|
111
116
|
maybe.write.breakline(commentOnNextLine);
|
|
112
117
|
maybe.write.space(sameLine);
|
|
@@ -5,10 +5,10 @@ const {
|
|
|
5
5
|
hasTrailingComment,
|
|
6
6
|
} = require('../../is');
|
|
7
7
|
|
|
8
|
-
const {printParams} = require('./params');
|
|
9
8
|
const {maybeDecorators} = require('../../maybe/maybe-decorators');
|
|
10
9
|
const {printKey} = require('../object-expression/print-key');
|
|
11
10
|
const {printKind} = require('./kind');
|
|
11
|
+
const {printFunctionParams} = require('./print-function-params');
|
|
12
12
|
|
|
13
13
|
const noTrailingCommentAndNext = (path) => {
|
|
14
14
|
if (hasTrailingComment(path))
|
|
@@ -45,7 +45,7 @@ const ClassMethod = {
|
|
|
45
45
|
|
|
46
46
|
printKind(path, printer);
|
|
47
47
|
printKey(path, printer);
|
|
48
|
-
|
|
48
|
+
printFunctionParams(path, printer, semantics);
|
|
49
49
|
|
|
50
50
|
if (returnType) {
|
|
51
51
|
print(':');
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {parseComments} = require('../../comment/comment');
|
|
4
|
-
|
|
4
|
+
const noop = () => {};
|
|
5
5
|
const parseParams = (path) => path.get('params');
|
|
6
6
|
|
|
7
7
|
module.exports.printParams = (path, printer, semantics, customization = {}) => {
|
|
8
8
|
const {extra, typeParameters} = path.node;
|
|
9
|
-
const {
|
|
10
|
-
params = parseParams(path),
|
|
11
|
-
braceOpen = '(',
|
|
12
|
-
braceClose = ')',
|
|
13
|
-
} = customization;
|
|
14
|
-
|
|
15
9
|
const {
|
|
16
10
|
print,
|
|
17
11
|
maybe,
|
|
18
12
|
traverse,
|
|
19
13
|
} = printer;
|
|
20
14
|
|
|
15
|
+
const {
|
|
16
|
+
params = parseParams(path),
|
|
17
|
+
braceOpen = '(',
|
|
18
|
+
braceClose = ')',
|
|
19
|
+
printSpace = print.space,
|
|
20
|
+
printBeforeFirst = noop,
|
|
21
|
+
printAfterLast = noop,
|
|
22
|
+
} = customization;
|
|
23
|
+
|
|
21
24
|
if (typeParameters)
|
|
22
25
|
traverse(path.get('typeParameters'));
|
|
23
26
|
|
|
@@ -27,6 +30,7 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
|
|
|
27
30
|
}, semantics);
|
|
28
31
|
|
|
29
32
|
parseComments(path, printer, semantics);
|
|
33
|
+
printBeforeFirst();
|
|
30
34
|
|
|
31
35
|
const n = params.length - 1;
|
|
32
36
|
|
|
@@ -37,12 +41,13 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
|
|
|
37
41
|
|
|
38
42
|
if (!isLast) {
|
|
39
43
|
print(',');
|
|
40
|
-
|
|
44
|
+
printSpace();
|
|
41
45
|
}
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
maybe.print(extra?.trailingComma, ',');
|
|
45
49
|
|
|
50
|
+
printAfterLast();
|
|
46
51
|
printBraceClose(path, {
|
|
47
52
|
print,
|
|
48
53
|
braceClose,
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {printParams} = require('./params');
|
|
4
|
+
|
|
5
|
+
const hasDecorators = ({decorators}) => decorators?.length;
|
|
6
|
+
|
|
7
|
+
module.exports.printFunctionParams = (path, printer, semantics) => {
|
|
8
|
+
const {print} = printer;
|
|
9
|
+
const {params} = path.node;
|
|
10
|
+
const isNewline = params.filter(hasDecorators).length;
|
|
11
|
+
const printSpace = isNewline ? print.breakline : print.space;
|
|
12
|
+
|
|
13
|
+
const printBeforeFirst = createPrint({
|
|
14
|
+
type: 'inc',
|
|
15
|
+
printer,
|
|
16
|
+
isNewline,
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
const printAfterLast = createPrint({
|
|
20
|
+
type: 'dec',
|
|
21
|
+
printer,
|
|
22
|
+
isNewline,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
printParams(path, printer, semantics, {
|
|
26
|
+
printBeforeFirst,
|
|
27
|
+
printSpace,
|
|
28
|
+
printAfterLast,
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const createPrint = ({isNewline, printer, type}) => () => {
|
|
33
|
+
if (!isNewline)
|
|
34
|
+
return;
|
|
35
|
+
|
|
36
|
+
const {indent, print} = printer;
|
|
37
|
+
indent[type]();
|
|
38
|
+
print.breakline();
|
|
39
|
+
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const {TemplateLiteral} = require('./template-literal');
|
|
4
4
|
const {Identifier} = require('./identifier');
|
|
5
5
|
|
|
6
|
-
const {Decorator} = require('../expressions/decorator');
|
|
6
|
+
const {Decorator} = require('../expressions/decorator/decorator');
|
|
7
7
|
const {StringLiteral} = require('./string-literal');
|
|
8
8
|
|
|
9
9
|
module.exports = {
|
|
@@ -1,24 +1,33 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const {hasLeadingComment} = require('../../is');
|
|
4
|
+
|
|
5
|
+
module.exports.TSParameterProperty = (path, {print, maybe, indent}) => {
|
|
4
6
|
const {
|
|
5
7
|
decorators,
|
|
6
8
|
readonly,
|
|
7
9
|
accessibility,
|
|
8
10
|
} = path.node;
|
|
9
11
|
|
|
10
|
-
const decoratorsLength = decorators?.length;
|
|
12
|
+
const decoratorsLength = decorators?.length > 1;
|
|
13
|
+
const isNewline = decoratorsLength || hasLeadingComment(path);
|
|
11
14
|
|
|
12
15
|
maybe.print.breakline(decoratorsLength);
|
|
13
16
|
|
|
14
|
-
if (decorators)
|
|
17
|
+
if (decorators) {
|
|
15
18
|
for (const decorator of path.get('decorators')) {
|
|
16
|
-
|
|
19
|
+
maybe.indent(decoratorsLength);
|
|
17
20
|
print(decorator);
|
|
18
21
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
+
|
|
23
|
+
maybe.print.breakline(decoratorsLength);
|
|
24
|
+
|
|
25
|
+
if (isNewline)
|
|
26
|
+
indent();
|
|
27
|
+
|
|
28
|
+
if (!hasLeadingComment(path))
|
|
29
|
+
print.space();
|
|
30
|
+
}
|
|
22
31
|
|
|
23
32
|
if (accessibility) {
|
|
24
33
|
print(accessibility);
|
|
@@ -31,6 +40,6 @@ module.exports.TSParameterProperty = (path, {print, maybe}) => {
|
|
|
31
40
|
}
|
|
32
41
|
|
|
33
42
|
print('__parameter');
|
|
34
|
-
maybe.print(
|
|
43
|
+
maybe.print(isNewline, ',');
|
|
35
44
|
maybe.print.breakline(decoratorsLength);
|
|
36
45
|
};
|
package/package.json
CHANGED
|
File without changes
|