@putout/printer 18.52.4 → 18.52.5
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 +8 -0
- package/lib/tokenize/comments/parse-leading-comments.js +4 -13
- package/lib/tokenize/expressions/function/class-method/class-method.js +30 -0
- package/lib/tokenize/literals/index.js +26 -2
- package/lib/tokenize/statements/switch-statement/switch-case.js +18 -0
- package/lib/tokenize/statements/switch-statement/switch-statement.js +4 -1
- package/lib/tokenize/typescript/enum/ts-enum-member.js +18 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
2026.11.22, v18.52.5
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- d16fbe76 @putout/printer: TSEnumMember: comments: simplify
|
|
5
|
+
- 9ef70bdd @putout/printer: Directive: comments: simplify
|
|
6
|
+
- 4b778dcd @putout/printer: ClassMethod: comments: simplify
|
|
7
|
+
- a7745403 @putout/printer: SwitchStatement: comments
|
|
8
|
+
|
|
1
9
|
2026.11.22, v18.52.4
|
|
2
10
|
|
|
3
11
|
feature:
|
|
@@ -11,7 +11,6 @@ const {
|
|
|
11
11
|
isArrowFunctionExpression,
|
|
12
12
|
isVariableDeclarator,
|
|
13
13
|
isBinaryExpression,
|
|
14
|
-
isClassMethod,
|
|
15
14
|
isDecorator,
|
|
16
15
|
} = types;
|
|
17
16
|
|
|
@@ -52,14 +51,12 @@ export const parseLeadingComments = (path, printer, semantics, {currentTraverse
|
|
|
52
51
|
if (hasDecoratorsWithComments(path))
|
|
53
52
|
return;
|
|
54
53
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (!looksLikeSwitchCase && hasTrailingComment(path.getPrevSibling()))
|
|
54
|
+
if (hasTrailingComment(path.getPrevSibling()))
|
|
58
55
|
return;
|
|
59
56
|
|
|
60
57
|
const insideFn = (path.parentPath.isFunction() || path.parentPath.isTSDeclareMethod()) && !path.isTSTypeParameterDeclaration();
|
|
61
58
|
|
|
62
|
-
const isIndent = !
|
|
59
|
+
const isIndent = !insideFn;
|
|
63
60
|
|
|
64
61
|
const count = leadingComments.length - 1;
|
|
65
62
|
|
|
@@ -78,9 +75,7 @@ export const parseLeadingComments = (path, printer, semantics, {currentTraverse
|
|
|
78
75
|
if (index === count) {
|
|
79
76
|
print.newline();
|
|
80
77
|
|
|
81
|
-
if (
|
|
82
|
-
indent();
|
|
83
|
-
} else if (isBinaryExpression(path) || isDecorator(path)) {
|
|
78
|
+
if (isBinaryExpression(path) || isDecorator(path)) {
|
|
84
79
|
indent.inc();
|
|
85
80
|
indent();
|
|
86
81
|
indent.dec();
|
|
@@ -101,15 +96,11 @@ export const parseLeadingComments = (path, printer, semantics, {currentTraverse
|
|
|
101
96
|
if (type === 'CommentBlock') {
|
|
102
97
|
maybe.indent(isIndent);
|
|
103
98
|
|
|
104
|
-
const looksLikeMethod = path.isClassMethod();
|
|
105
|
-
const looksLikeDirective = path.isDirective();
|
|
106
|
-
|
|
107
99
|
print(`/*${value}*/`);
|
|
108
100
|
|
|
109
|
-
if (path.isStatement()
|
|
101
|
+
if (path.isStatement()) {
|
|
110
102
|
print.newline();
|
|
111
103
|
markBefore(path);
|
|
112
|
-
maybe.indent(looksLikeMethod || looksLikeSwitchCase);
|
|
113
104
|
}
|
|
114
105
|
|
|
115
106
|
continue;
|
|
@@ -2,6 +2,7 @@ import {
|
|
|
2
2
|
isNext,
|
|
3
3
|
hasTrailingComment,
|
|
4
4
|
} from '#is';
|
|
5
|
+
import {markBefore} from '#mark';
|
|
5
6
|
import {printReturnType} from '#return-type';
|
|
6
7
|
import {maybeDecorators} from '../../../maybe/maybe-decorators.js';
|
|
7
8
|
import {printKey} from '../../object-expression/print-key.js';
|
|
@@ -58,3 +59,32 @@ export const ClassMethod = {
|
|
|
58
59
|
};
|
|
59
60
|
|
|
60
61
|
export const ClassPrivateMethod = ClassMethod;
|
|
62
|
+
|
|
63
|
+
ClassMethod.printLeadingCommentLine = (path, printer, semantics, {index, isLast, printComment}) => {
|
|
64
|
+
const {
|
|
65
|
+
print,
|
|
66
|
+
maybe,
|
|
67
|
+
indent,
|
|
68
|
+
} = printer;
|
|
69
|
+
|
|
70
|
+
if (hasTrailingComment(path.getPrevSibling()))
|
|
71
|
+
return;
|
|
72
|
+
|
|
73
|
+
maybe.indent(Boolean(index));
|
|
74
|
+
printComment();
|
|
75
|
+
print.newline();
|
|
76
|
+
|
|
77
|
+
if (isLast)
|
|
78
|
+
indent();
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
ClassMethod.printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
|
|
82
|
+
const {indent} = printer;
|
|
83
|
+
|
|
84
|
+
if (hasTrailingComment(path.getPrevSibling()))
|
|
85
|
+
return;
|
|
86
|
+
|
|
87
|
+
printComment();
|
|
88
|
+
markBefore(path);
|
|
89
|
+
indent();
|
|
90
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {markBefore} from '#mark';
|
|
2
|
+
|
|
1
3
|
export {TemplateLiteral} from './template-literal.js';
|
|
2
4
|
export {Identifier} from './identifier.js';
|
|
3
5
|
export {Decorator} from './decorator/decorator.js';
|
|
@@ -20,11 +22,33 @@ export const NumericLiteral = (path, {write}) => {
|
|
|
20
22
|
write(raw || extra?.raw || value);
|
|
21
23
|
};
|
|
22
24
|
|
|
23
|
-
export const Directive = (path, {print
|
|
24
|
-
maybe.print.breakline(path.node.leadingComments?.length);
|
|
25
|
+
export const Directive = (path, {print}) => {
|
|
25
26
|
print('__value');
|
|
26
27
|
};
|
|
27
28
|
|
|
29
|
+
const maybeHeaderBreak = (path, print) => {
|
|
30
|
+
if (path.parentPath.isProgram() && !path.getPrevSibling().node)
|
|
31
|
+
print.newline();
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
Directive.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
|
|
35
|
+
const {print, indent} = printer;
|
|
36
|
+
|
|
37
|
+
indent();
|
|
38
|
+
printComment();
|
|
39
|
+
print.newline();
|
|
40
|
+
maybeHeaderBreak(path, print);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
Directive.printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
|
|
44
|
+
const {print, indent} = printer;
|
|
45
|
+
|
|
46
|
+
indent();
|
|
47
|
+
printComment();
|
|
48
|
+
markBefore(path);
|
|
49
|
+
maybeHeaderBreak(path, print);
|
|
50
|
+
};
|
|
51
|
+
|
|
28
52
|
export const BooleanLiteral = (path, {write}) => {
|
|
29
53
|
write(path.node.value);
|
|
30
54
|
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import {markBefore} from '#mark';
|
|
2
|
+
|
|
3
|
+
export const SwitchCase = {};
|
|
4
|
+
|
|
5
|
+
SwitchCase.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
|
|
6
|
+
const {print} = printer;
|
|
7
|
+
|
|
8
|
+
printComment();
|
|
9
|
+
print.newline();
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
SwitchCase.printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
|
|
13
|
+
const {indent} = printer;
|
|
14
|
+
|
|
15
|
+
printComment();
|
|
16
|
+
markBefore(path);
|
|
17
|
+
indent();
|
|
18
|
+
};
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
} from '#is';
|
|
7
7
|
import {parseLeadingComments} from '#comments';
|
|
8
8
|
import {createTypeChecker} from '#type-checker';
|
|
9
|
+
import {SwitchCase} from './switch-case.js';
|
|
9
10
|
import {maybeSpaceAfterKeyword} from '../return-statement/maybe-space-after-keyword.js';
|
|
10
11
|
|
|
11
12
|
const {isBlockStatement} = types;
|
|
@@ -37,7 +38,9 @@ export const SwitchStatement = {
|
|
|
37
38
|
|
|
38
39
|
indent();
|
|
39
40
|
|
|
40
|
-
parseLeadingComments(switchCase, printer, semantics
|
|
41
|
+
parseLeadingComments(switchCase, printer, semantics, {
|
|
42
|
+
currentTraverse: SwitchCase,
|
|
43
|
+
});
|
|
41
44
|
|
|
42
45
|
if (exists(test)) {
|
|
43
46
|
print('case');
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import {markBefore} from '#mark';
|
|
2
|
+
|
|
1
3
|
export const TSEnumMember = (path, {print, indent}) => {
|
|
2
4
|
const {initializer} = path.node;
|
|
3
5
|
indent();
|
|
@@ -10,3 +12,19 @@ export const TSEnumMember = (path, {print, indent}) => {
|
|
|
10
12
|
print('__initializer');
|
|
11
13
|
}
|
|
12
14
|
};
|
|
15
|
+
|
|
16
|
+
TSEnumMember.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
|
|
17
|
+
const {print, indent} = printer;
|
|
18
|
+
|
|
19
|
+
indent();
|
|
20
|
+
printComment();
|
|
21
|
+
print.newline();
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
TSEnumMember.printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
|
|
25
|
+
const {indent} = printer;
|
|
26
|
+
|
|
27
|
+
indent();
|
|
28
|
+
printComment();
|
|
29
|
+
markBefore(path);
|
|
30
|
+
};
|
package/package.json
CHANGED