@putout/printer 18.31.0 → 18.33.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 +13 -0
- package/lib/tokenize/expressions/class/class-property.js +7 -5
- package/lib/tokenize/maybe/maybe-decorators.js +33 -10
- package/lib/tokenize/statements/do-while-statement/do-while-statement.js +6 -2
- package/lib/tokenize/statements/export-declaration/export-declaration.js +3 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
2026.07.11, v18.33.0
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- 1059d1f6 @putout/printer: ClassDeclaration: Decorator
|
|
5
|
+
|
|
6
|
+
feature:
|
|
7
|
+
- 7f0c9669 @putout/printer: ClassDeclaration: ClassAccessorProperty
|
|
8
|
+
|
|
9
|
+
2026.07.08, v18.32.0
|
|
10
|
+
|
|
11
|
+
feature:
|
|
12
|
+
- 77adbb66 @putout/printer: DoWhileStatement: inside LabeledStatement
|
|
13
|
+
|
|
1
14
|
2026.07.07, v18.31.0
|
|
2
15
|
|
|
3
16
|
feature:
|
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
1
2
|
import {exists} from '#is';
|
|
2
3
|
import {maybePrintTypeAnnotation} from '../../maybe/maybe-type-annotation.js';
|
|
3
4
|
import {maybeDecorators} from '../../maybe/maybe-decorators.js';
|
|
4
5
|
import {printKey} from '../object-expression/print-key.js';
|
|
5
6
|
import {printKind} from '../function/kind.js';
|
|
6
7
|
|
|
7
|
-
const
|
|
8
|
+
const {isClassAccessorProperty} = types;
|
|
9
|
+
|
|
10
|
+
const processClassProperty = maybeDecorators((path, printer) => {
|
|
8
11
|
const {node} = path;
|
|
9
12
|
const {
|
|
10
13
|
accessibility,
|
|
@@ -14,7 +17,8 @@ const processClassProperty = maybeDecorators((path, printer, semantics, {accesso
|
|
|
14
17
|
|
|
15
18
|
const {print, maybe} = printer;
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
if (isClassAccessorProperty(path))
|
|
21
|
+
print('accessor ');
|
|
18
22
|
|
|
19
23
|
const value = path.get('value');
|
|
20
24
|
|
|
@@ -50,7 +54,5 @@ export const PrivateName = (path, {print}) => {
|
|
|
50
54
|
};
|
|
51
55
|
|
|
52
56
|
export const ClassAccessorProperty = (path, printer, semantics) => {
|
|
53
|
-
processClassProperty(path, printer, semantics
|
|
54
|
-
accessor: true,
|
|
55
|
-
});
|
|
57
|
+
processClassProperty(path, printer, semantics);
|
|
56
58
|
};
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {maybeVisitor} from '#printer';
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
isExportDeclaration,
|
|
6
|
+
isClassDeclaration,
|
|
7
|
+
} = types;
|
|
8
|
+
|
|
1
9
|
const isPrevClassProperty = (path) => {
|
|
2
10
|
const prev = path.getPrevSibling();
|
|
3
11
|
|
|
@@ -8,20 +16,35 @@ const isPrevClassProperty = (path) => {
|
|
|
8
16
|
};
|
|
9
17
|
|
|
10
18
|
export const maybeDecorators = (visitor) => (path, printer, semantics, options) => {
|
|
19
|
+
if (isExportDeclaration(path.parentPath))
|
|
20
|
+
return maybeVisitor(visitor, path, printer, semantics, options);
|
|
21
|
+
|
|
22
|
+
if (isExportDeclaration(path) && isClassDeclaration(path.node.declaration)) {
|
|
23
|
+
const declaration = path.get('declaration');
|
|
24
|
+
printDecorators(declaration, printer);
|
|
25
|
+
|
|
26
|
+
return maybeVisitor(visitor, path, printer, semantics, options);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
printDecorators(path, printer);
|
|
30
|
+
maybeVisitor(visitor, path, printer, semantics, options);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
function printDecorators(path, printer) {
|
|
11
34
|
const {
|
|
12
|
-
write,
|
|
13
|
-
traverse,
|
|
14
35
|
maybe,
|
|
36
|
+
traverse,
|
|
37
|
+
write,
|
|
15
38
|
} = printer;
|
|
16
39
|
|
|
17
40
|
const {decorators} = path.node;
|
|
18
41
|
|
|
19
|
-
if (decorators)
|
|
20
|
-
|
|
21
|
-
maybe.write.breakline(isPrevClassProperty(path));
|
|
22
|
-
traverse(decorator);
|
|
23
|
-
write.breakline();
|
|
24
|
-
}
|
|
42
|
+
if (!decorators)
|
|
43
|
+
return [];
|
|
25
44
|
|
|
26
|
-
|
|
27
|
-
|
|
45
|
+
for (const decorator of path.get('decorators')) {
|
|
46
|
+
maybe.write.breakline(isPrevClassProperty(path));
|
|
47
|
+
traverse(decorator);
|
|
48
|
+
write.breakline();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -1,10 +1,14 @@
|
|
|
1
|
-
import {isLast} from '#is';
|
|
1
|
+
import {isInsideLabel, isLast} from '#is';
|
|
2
2
|
|
|
3
|
+
const not = (fn) => (...a) => !fn(...a);
|
|
3
4
|
const notLast = (path) => !isLast(path);
|
|
4
5
|
|
|
5
6
|
export const DoWhileStatement = {
|
|
6
|
-
|
|
7
|
+
beforeIf: not(isInsideLabel),
|
|
8
|
+
before: (path, {indent}) => {
|
|
7
9
|
indent();
|
|
10
|
+
},
|
|
11
|
+
print(path, {print}) {
|
|
8
12
|
print('do');
|
|
9
13
|
print.space();
|
|
10
14
|
print('__body');
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
isMarkedAfter,
|
|
13
13
|
hasPrevNewline,
|
|
14
14
|
} from '#mark';
|
|
15
|
+
import {maybeDecorators} from '../../maybe/maybe-decorators.js';
|
|
15
16
|
|
|
16
17
|
const {
|
|
17
18
|
isExportNamespaceSpecifier,
|
|
@@ -49,7 +50,7 @@ export const ExportDefaultSpecifier = (path, {print}) => {
|
|
|
49
50
|
print('__exported');
|
|
50
51
|
};
|
|
51
52
|
|
|
52
|
-
export const ExportNamedDeclaration = {
|
|
53
|
+
export const ExportNamedDeclaration = maybeDecorators({
|
|
53
54
|
beforeIf(path) {
|
|
54
55
|
const prev = path.getPrevSibling();
|
|
55
56
|
|
|
@@ -181,4 +182,4 @@ export const ExportNamedDeclaration = {
|
|
|
181
182
|
|
|
182
183
|
markAfter(path);
|
|
183
184
|
},
|
|
184
|
-
};
|
|
185
|
+
});
|
package/package.json
CHANGED