@putout/printer 1.85.0 → 1.87.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 +11 -0
- package/lib/tokenize/expressions/class.js +15 -0
- package/lib/tokenize/expressions/index.js +2 -0
- package/lib/tokenize/expressions/unary-expressions.js +1 -1
- package/lib/tokenize/statements/if-statement.js +3 -1
- package/lib/tokenize/statements/switch-statement.js +23 -10
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.05.09, v1.87.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 092bb3c @putout/printer: add support of StaticBlock
|
|
5
|
+
- 353a550 @putout/printer: improve support of SwitchStatement
|
|
6
|
+
|
|
7
|
+
2023.05.09, v1.86.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- d4e3b07 @putout/printer: ifStatement: space
|
|
11
|
+
|
|
1
12
|
2023.05.08, v1.85.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -6,6 +6,20 @@ const {markAfter} = require('../mark');
|
|
|
6
6
|
module.exports.ClassExpression = classVisitor;
|
|
7
7
|
module.exports.ClassDeclaration = classVisitor;
|
|
8
8
|
|
|
9
|
+
module.exports.StaticBlock = (path, {print, traverse}) => {
|
|
10
|
+
print('static ');
|
|
11
|
+
print('{');
|
|
12
|
+
print.breakline();
|
|
13
|
+
|
|
14
|
+
for (const child of path.get('body')) {
|
|
15
|
+
traverse(child);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
print.indent();
|
|
19
|
+
print('}');
|
|
20
|
+
print.newline();
|
|
21
|
+
};
|
|
22
|
+
|
|
9
23
|
module.exports.ClassDeclaration = (path, {print, indent, maybe, write}) => {
|
|
10
24
|
indent();
|
|
11
25
|
|
|
@@ -57,3 +71,4 @@ function classVisitor(path, {print, indent, maybe}) {
|
|
|
57
71
|
indent();
|
|
58
72
|
print('}');
|
|
59
73
|
}
|
|
74
|
+
|
|
@@ -7,6 +7,7 @@ const memberExpressions = require('./member-expressions/member-expressions');
|
|
|
7
7
|
const {
|
|
8
8
|
ClassExpression,
|
|
9
9
|
ClassDeclaration,
|
|
10
|
+
StaticBlock,
|
|
10
11
|
} = require('./class');
|
|
11
12
|
|
|
12
13
|
const {
|
|
@@ -62,6 +63,7 @@ module.exports = {
|
|
|
62
63
|
RestElement,
|
|
63
64
|
SpreadElement,
|
|
64
65
|
SequenceExpression,
|
|
66
|
+
StaticBlock,
|
|
65
67
|
TaggedTemplateExpression,
|
|
66
68
|
ThisExpression(path, {print}) {
|
|
67
69
|
print('this');
|
|
@@ -8,7 +8,9 @@ const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
|
|
|
8
8
|
module.exports.IfStatement = {
|
|
9
9
|
print: (path, {indent, print, maybe, write, traverse}) => {
|
|
10
10
|
indent();
|
|
11
|
-
print('if
|
|
11
|
+
print('if');
|
|
12
|
+
print.space();
|
|
13
|
+
print('(');
|
|
12
14
|
print('__test');
|
|
13
15
|
print(')');
|
|
14
16
|
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
isNext,
|
|
5
|
+
exists,
|
|
6
|
+
isLast,
|
|
7
|
+
} = require('../is');
|
|
4
8
|
|
|
5
9
|
module.exports.SwitchStatement = {
|
|
6
|
-
print(path, {print, maybe}) {
|
|
10
|
+
print(path, {print, maybe, indent, write, traverse}) {
|
|
11
|
+
indent();
|
|
7
12
|
print('switch');
|
|
8
|
-
print.space();
|
|
9
13
|
print('(');
|
|
10
14
|
print('__discriminant');
|
|
11
15
|
print(') {');
|
|
@@ -15,9 +19,17 @@ module.exports.SwitchStatement = {
|
|
|
15
19
|
const n = cases.length - 1;
|
|
16
20
|
|
|
17
21
|
for (const [index, switchCase] of cases.entries()) {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
22
|
+
const test = switchCase.get('test');
|
|
23
|
+
|
|
24
|
+
indent();
|
|
25
|
+
|
|
26
|
+
if (exists(test)) {
|
|
27
|
+
write('case ');
|
|
28
|
+
traverse(test);
|
|
29
|
+
} else {
|
|
30
|
+
write('default');
|
|
31
|
+
}
|
|
32
|
+
|
|
21
33
|
print(':');
|
|
22
34
|
|
|
23
35
|
const isBlock = switchCase
|
|
@@ -37,14 +49,15 @@ module.exports.SwitchStatement = {
|
|
|
37
49
|
print(consequent);
|
|
38
50
|
}
|
|
39
51
|
|
|
40
|
-
if (index < n) {
|
|
41
|
-
print.linebreak();
|
|
42
|
-
}
|
|
43
|
-
|
|
44
52
|
maybe.indent.dec(!isBlock);
|
|
53
|
+
maybe.write.linebreak(index < n);
|
|
45
54
|
}
|
|
46
55
|
|
|
56
|
+
print.indent();
|
|
47
57
|
print('}');
|
|
58
|
+
|
|
59
|
+
if (!isNext(path) && !isLast(path))
|
|
60
|
+
print.newline();
|
|
48
61
|
},
|
|
49
62
|
afterSatisfy: () => [
|
|
50
63
|
isNext,
|
package/package.json
CHANGED