@putout/printer 5.19.0 → 5.20.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-leading-comments.js +2 -3
- package/lib/tokenize/expressions/class/class-property.js +2 -1
- package/lib/tokenize/expressions/class/class.js +29 -32
- package/lib/tokenize/is.js +0 -7
- package/lib/tokenize/maybe/maybe-decorators.js +9 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {hasTrailingComment} = require('../is');
|
|
4
|
-
const {isVariableDeclarator} = require('@putout/babel').types;
|
|
5
4
|
|
|
6
5
|
const {markBefore} = require('../mark');
|
|
7
6
|
const {maybeInsideFn} = require('./maybe-inside-fn');
|
|
@@ -21,7 +20,7 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
|
|
|
21
20
|
return;
|
|
22
21
|
|
|
23
22
|
const insideFn = path.parentPath.isFunction();
|
|
24
|
-
const isProperty = path.isObjectProperty() || isVariableDeclarator(path);
|
|
23
|
+
const isProperty = path.isObjectProperty() || path.isVariableDeclarator() || path.isClassProperty();
|
|
25
24
|
const isIndent = !looksLikeSwitchCase && !path.isClassMethod() && !insideFn && !isProperty;
|
|
26
25
|
|
|
27
26
|
for (const {type, value} of leadingComments) {
|
|
@@ -33,7 +32,7 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
|
|
|
33
32
|
indent,
|
|
34
33
|
});
|
|
35
34
|
|
|
36
|
-
maybe.print.space(isProperty);
|
|
35
|
+
maybe.print.space(isProperty && !path.isClassProperty());
|
|
37
36
|
print(`//${value}`);
|
|
38
37
|
|
|
39
38
|
const isParentSwitch = path.parentPath.isSwitchCase();
|
|
@@ -5,7 +5,6 @@ const {maybePrintTypeAnnotation} = require('../../maybe/maybe-type-annotation');
|
|
|
5
5
|
const {maybeDecorators} = require('../../maybe/maybe-decorators');
|
|
6
6
|
|
|
7
7
|
const processClassProperty = maybeDecorators((path, printer, semantics, {accessor} = {}) => {
|
|
8
|
-
const {print, maybe} = printer;
|
|
9
8
|
const {node} = path;
|
|
10
9
|
const {
|
|
11
10
|
accessibility,
|
|
@@ -13,6 +12,8 @@ const processClassProperty = maybeDecorators((path, printer, semantics, {accesso
|
|
|
13
12
|
optional,
|
|
14
13
|
} = node;
|
|
15
14
|
|
|
15
|
+
const {print, maybe} = printer;
|
|
16
|
+
|
|
16
17
|
maybe.print(accessor, 'accessor ');
|
|
17
18
|
|
|
18
19
|
const value = path.get('value');
|
|
@@ -2,37 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
const {isNext} = require('../../is');
|
|
4
4
|
const {markAfter} = require('../../mark');
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
//const {maybeDecorators} = require('../../maybe-get');
|
|
6
7
|
const {maybeDeclare} = require('../../maybe/maybe-declare');
|
|
7
8
|
const {parseComments} = require('../../comment/comment');
|
|
9
|
+
const {maybeDecorators} = require('../../maybe/maybe-decorators');
|
|
8
10
|
|
|
9
11
|
const isInsideExport = ({parentPath}) => parentPath.isExportDeclaration();
|
|
10
12
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
module.exports.ClassDeclaration = {
|
|
14
|
-
print: maybeDeclare((path, printer, semantics) => {
|
|
15
|
-
const {indent} = printer;
|
|
16
|
-
indent();
|
|
17
|
-
classVisitor(path, printer, semantics);
|
|
18
|
-
}),
|
|
19
|
-
afterIf(path) {
|
|
20
|
-
if (!isNext(path))
|
|
21
|
-
return false;
|
|
22
|
-
|
|
23
|
-
return !isInsideExport(path);
|
|
24
|
-
},
|
|
25
|
-
after(path, {write}) {
|
|
26
|
-
write.newline();
|
|
27
|
-
|
|
28
|
-
if (path.node.body.body.length) {
|
|
29
|
-
write.newline();
|
|
30
|
-
markAfter(path);
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
function classVisitor(path, printer, semantics) {
|
|
13
|
+
const classVisitor = maybeDecorators((path, printer, semantics) => {
|
|
36
14
|
const {id, abstract} = path.node;
|
|
37
15
|
const {
|
|
38
16
|
print,
|
|
@@ -41,11 +19,6 @@ function classVisitor(path, printer, semantics) {
|
|
|
41
19
|
traverse,
|
|
42
20
|
} = printer;
|
|
43
21
|
|
|
44
|
-
for (const decorator of maybeDecorators(path)) {
|
|
45
|
-
traverse(decorator);
|
|
46
|
-
print.breakline();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
22
|
maybe.print(abstract, 'abstract ');
|
|
50
23
|
print('class ');
|
|
51
24
|
print('__id');
|
|
@@ -86,4 +59,28 @@ function classVisitor(path, printer, semantics) {
|
|
|
86
59
|
indent.dec();
|
|
87
60
|
maybe.indent(body.length);
|
|
88
61
|
print('}');
|
|
89
|
-
}
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
module.exports.ClassExpression = classVisitor;
|
|
65
|
+
|
|
66
|
+
module.exports.ClassDeclaration = {
|
|
67
|
+
print: maybeDeclare((path, printer, semantics) => {
|
|
68
|
+
const {indent} = printer;
|
|
69
|
+
indent();
|
|
70
|
+
classVisitor(path, printer, semantics);
|
|
71
|
+
}),
|
|
72
|
+
afterIf(path) {
|
|
73
|
+
if (!isNext(path))
|
|
74
|
+
return false;
|
|
75
|
+
|
|
76
|
+
return !isInsideExport(path);
|
|
77
|
+
},
|
|
78
|
+
after(path, {write}) {
|
|
79
|
+
write.newline();
|
|
80
|
+
|
|
81
|
+
if (path.node.body.body.length) {
|
|
82
|
+
write.newline();
|
|
83
|
+
markAfter(path);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
};
|
package/lib/tokenize/is.js
CHANGED
|
@@ -23,18 +23,11 @@ const isNext = (path) => {
|
|
|
23
23
|
return !next.isEmptyStatement();
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
-
const isPrev = (path) => {
|
|
27
|
-
const prev = path.getPrevSibling();
|
|
28
|
-
|
|
29
|
-
return prev.node;
|
|
30
|
-
};
|
|
31
|
-
|
|
32
26
|
const isNextParent = (path) => isNext(path.parentPath);
|
|
33
27
|
const isLast = (path) => isParentProgram(path) && !isNext(path);
|
|
34
28
|
|
|
35
29
|
module.exports.isFirst = (path) => path.node === path.parentPath.node.body?.[0];
|
|
36
30
|
module.exports.isPrevBody = (path) => path.getPrevSibling().isBlockStatement();
|
|
37
|
-
module.exports.isPrev = isPrev;
|
|
38
31
|
module.exports.isNext = isNext;
|
|
39
32
|
module.exports.isNextParent = isNextParent;
|
|
40
33
|
module.exports.isParentProgram = isParentProgram;
|
|
@@ -1,6 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const
|
|
3
|
+
const isPrevClassProperty = (path) => {
|
|
4
|
+
const prev = path.getPrevSibling();
|
|
5
|
+
|
|
6
|
+
if (!prev.node)
|
|
7
|
+
return false;
|
|
8
|
+
|
|
9
|
+
return prev.isClassProperty() || prev.isClassAccessorProperty();
|
|
10
|
+
};
|
|
4
11
|
|
|
5
12
|
module.exports.maybeDecorators = (visitor) => (path, printer, semantics, options) => {
|
|
6
13
|
const {
|
|
@@ -13,7 +20,7 @@ module.exports.maybeDecorators = (visitor) => (path, printer, semantics, options
|
|
|
13
20
|
|
|
14
21
|
if (decorators) {
|
|
15
22
|
for (const decorator of path.get('decorators')) {
|
|
16
|
-
maybe.write.breakline(
|
|
23
|
+
maybe.write.breakline(isPrevClassProperty(path));
|
|
17
24
|
traverse(decorator);
|
|
18
25
|
write.breakline();
|
|
19
26
|
}
|
package/package.json
CHANGED