@putout/printer 18.35.0 → 18.37.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 +12 -0
- package/lib/tokenize/comments/comments-printer/comments-printer.js +0 -1
- package/lib/tokenize/expressions/function/print-function-params.js +5 -4
- package/lib/tokenize/is.js +8 -0
- package/lib/tokenize/maybe/maybe-decorators.js +23 -2
- package/lib/tokenize/statements/import-declaration/import-declaration.js +4 -0
- package/lib/tokenize/typescript/ts-parameter-property/ts-parameter-property.js +13 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
2026.07.12, v18.37.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 960728cc @putout/printer: ImportSpecifier: importKind
|
|
5
|
+
|
|
6
|
+
2026.07.12, v18.36.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- c1c2897c @putout/printer: TSParameterProperty: simplify
|
|
10
|
+
- e888f538 @putout/printer: MaybeDecorators: simplify
|
|
11
|
+
- 72941d94 @putout/printer: TSParameterProperty: Decorator
|
|
12
|
+
|
|
1
13
|
2026.07.12, v18.35.0
|
|
2
14
|
|
|
3
15
|
feature:
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
hasLeadingComment,
|
|
3
|
+
hasDecorators,
|
|
4
|
+
} from '#is';
|
|
2
5
|
import {printParams} from '#print-params';
|
|
3
6
|
|
|
4
7
|
const isAllParamsHasLeadingComments = (path) => {
|
|
@@ -22,10 +25,8 @@ const isAllParamsHasLeadingComments = (path) => {
|
|
|
22
25
|
return commentsCount === decoratorsCount;
|
|
23
26
|
};
|
|
24
27
|
|
|
25
|
-
const hasDecorators = ({decorators}) => decorators?.length;
|
|
26
|
-
|
|
27
28
|
export const printFunctionParams = (path, printer, semantics) => {
|
|
28
|
-
const
|
|
29
|
+
const params = path.get('params');
|
|
29
30
|
const isNewline = params.filter(hasDecorators).length;
|
|
30
31
|
const isAllHasComments = isAllParamsHasLeadingComments(path);
|
|
31
32
|
|
package/lib/tokenize/is.js
CHANGED
|
@@ -200,6 +200,14 @@ export const hasTrailingComment = (path) => {
|
|
|
200
200
|
return node.trailingComments?.length;
|
|
201
201
|
};
|
|
202
202
|
|
|
203
|
+
export const hasDecorators = (path) => {
|
|
204
|
+
const {decorators} = path.node;
|
|
205
|
+
|
|
206
|
+
if (!decorators)
|
|
207
|
+
return false;
|
|
208
|
+
|
|
209
|
+
return decorators.length;
|
|
210
|
+
};
|
|
203
211
|
export const hasLeadingComment = (path) => path.node?.leadingComments?.length;
|
|
204
212
|
|
|
205
213
|
export const noTrailingComment = (path) => !path.node.trailingComments?.length;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
+
import {createTypeChecker} from '#type-checker';
|
|
2
3
|
import {maybeVisitor} from '#printer';
|
|
4
|
+
import {hasDecorators, callWithPrev} from '#is';
|
|
3
5
|
|
|
4
6
|
const {
|
|
5
7
|
isExportDeclaration,
|
|
@@ -15,12 +17,31 @@ const isPrevClassProperty = (path) => {
|
|
|
15
17
|
return prev.isClassProperty() || prev.isClassAccessorProperty();
|
|
16
18
|
};
|
|
17
19
|
|
|
20
|
+
const callWithDeclaration = (fn) => (path) => fn(path.get('declaration'));
|
|
21
|
+
|
|
22
|
+
const isNewline = createTypeChecker([
|
|
23
|
+
['-: -> !', callWithPrev(isExportDeclaration)],
|
|
24
|
+
['+', callWithDeclaration(hasDecorators)],
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const isExportWithClass = createTypeChecker([
|
|
28
|
+
['-: -> !ExportNamedDeclaration'],
|
|
29
|
+
['+', callWithDeclaration(isClassDeclaration)],
|
|
30
|
+
]);
|
|
31
|
+
|
|
18
32
|
export const maybeDecorators = (visitor) => (path, printer, semantics, options) => {
|
|
19
|
-
|
|
33
|
+
const {parentPath} = path;
|
|
34
|
+
const {print} = printer;
|
|
35
|
+
|
|
36
|
+
if (isExportDeclaration(parentPath))
|
|
20
37
|
return maybeVisitor(visitor, path, printer, semantics, options);
|
|
21
38
|
|
|
22
|
-
if (
|
|
39
|
+
if (isExportWithClass(path)) {
|
|
23
40
|
const declaration = path.get('declaration');
|
|
41
|
+
|
|
42
|
+
if (isNewline(path))
|
|
43
|
+
print.newline();
|
|
44
|
+
|
|
24
45
|
printDecorators(declaration, printer);
|
|
25
46
|
|
|
26
47
|
return maybeVisitor(visitor, path, printer, semantics, options);
|
|
@@ -65,6 +65,10 @@ export const ImportDeclaration = {
|
|
|
65
65
|
maybe.write.breakline(importsCount >= maxSpecifiersInOneLine);
|
|
66
66
|
|
|
67
67
|
wasSpecifier = true;
|
|
68
|
+
|
|
69
|
+
if (spec.node.importKind === 'type')
|
|
70
|
+
write('type ');
|
|
71
|
+
|
|
68
72
|
traverse(spec.get('imported'));
|
|
69
73
|
|
|
70
74
|
if (imported.name !== local.name) {
|
|
@@ -1,4 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
hasLeadingComment,
|
|
3
|
+
hasTrailingComment,
|
|
4
|
+
} from '#is';
|
|
5
|
+
import {createTypeChecker} from '#type-checker';
|
|
6
|
+
|
|
7
|
+
const callWithLastDecorator = (fn) => (path) => fn(path.get('decorators').at(-1));
|
|
8
|
+
|
|
9
|
+
const isIndent = createTypeChecker([
|
|
10
|
+
['-', hasLeadingComment],
|
|
11
|
+
['+', callWithLastDecorator(hasTrailingComment)],
|
|
12
|
+
]);
|
|
2
13
|
|
|
3
14
|
export const TSParameterProperty = (path, {print, maybe, indent}) => {
|
|
4
15
|
const {
|
|
@@ -19,7 +30,7 @@ export const TSParameterProperty = (path, {print, maybe, indent}) => {
|
|
|
19
30
|
|
|
20
31
|
maybe.print.breakline(decoratorsLength);
|
|
21
32
|
|
|
22
|
-
if (
|
|
33
|
+
if (isIndent(path))
|
|
23
34
|
indent();
|
|
24
35
|
else
|
|
25
36
|
print(' ');
|
package/package.json
CHANGED