@putout/printer 1.86.0 → 1.88.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 +14 -0
- package/lib/tokenize/expressions/index.js +2 -0
- package/lib/tokenize/statements/export-declaration/export-declaration.js +1 -0
- package/lib/tokenize/statements/switch-statement.js +23 -10
- package/lib/tokenize/statements/variable-declaration.js +2 -1
- package/lib/tokenize/typescript/index.js +11 -0
- package/lib/tokenize/typescript/ts-module-declaration.js +21 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.05.09, v1.88.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 64aa4a3 @putout/printer: add support of TSModuleDeclaration
|
|
5
|
+
|
|
6
|
+
2023.05.09, v1.87.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 092bb3c @putout/printer: add support of StaticBlock
|
|
10
|
+
- 353a550 @putout/printer: improve support of SwitchStatement
|
|
11
|
+
|
|
1
12
|
2023.05.09, v1.86.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
|
|
|
@@ -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');
|
|
@@ -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,
|
|
@@ -13,6 +13,7 @@ const {hasPrevNewline} = require('../mark');
|
|
|
13
13
|
const {isExportDeclaration} = require('@babel/types');
|
|
14
14
|
|
|
15
15
|
const isParentBlock = (path) => /Program|BlockStatement|Export/.test(path.parentPath.type);
|
|
16
|
+
const isInsideBlock = (path) => /^(Program|BlockStatement)$/.test(path.parentPath.type);
|
|
16
17
|
|
|
17
18
|
module.exports.VariableDeclaration = {
|
|
18
19
|
beforeIf: shouldAddNewlineBefore,
|
|
@@ -20,7 +21,7 @@ module.exports.VariableDeclaration = {
|
|
|
20
21
|
print.breakline();
|
|
21
22
|
},
|
|
22
23
|
print(path, {maybe, store, write, traverse}) {
|
|
23
|
-
maybe.indent(
|
|
24
|
+
maybe.indent(isInsideBlock(path));
|
|
24
25
|
write(`${path.node.kind} `);
|
|
25
26
|
|
|
26
27
|
const declarations = path.get('declarations');
|
|
@@ -8,6 +8,11 @@ const {TSConditionalType} = require('./ts-conditional-type');
|
|
|
8
8
|
const {TSTypeParameter} = require('./ts-type-parameter');
|
|
9
9
|
const {TSDeclareFunction} = require('./ts-declare-function');
|
|
10
10
|
|
|
11
|
+
const {
|
|
12
|
+
TSModuleDeclaration,
|
|
13
|
+
TSModuleBlock,
|
|
14
|
+
} = require('./ts-module-declaration');
|
|
15
|
+
|
|
11
16
|
module.exports = {
|
|
12
17
|
TSTypeLiteral,
|
|
13
18
|
TSTypeAliasDeclaration,
|
|
@@ -15,6 +20,12 @@ module.exports = {
|
|
|
15
20
|
TSMappedType,
|
|
16
21
|
TSConditionalType,
|
|
17
22
|
TSDeclareFunction,
|
|
23
|
+
TSModuleDeclaration,
|
|
24
|
+
TSModuleBlock,
|
|
25
|
+
TSTypeQuery(path, {print}) {
|
|
26
|
+
print('typeof ');
|
|
27
|
+
print('__exprName');
|
|
28
|
+
},
|
|
18
29
|
TSNeverKeyword(path, {write}) {
|
|
19
30
|
write('never');
|
|
20
31
|
},
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.TSModuleBlock = (path, {print, traverse, indent}) => {
|
|
4
|
+
print('{');
|
|
5
|
+
print.breakline();
|
|
6
|
+
indent.inc();
|
|
7
|
+
|
|
8
|
+
for (const child of path.get('body'))
|
|
9
|
+
traverse(child);
|
|
10
|
+
|
|
11
|
+
indent.dec();
|
|
12
|
+
print('}');
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
module.exports.TSModuleDeclaration = (path, {print}) => {
|
|
16
|
+
print('declare namespace ');
|
|
17
|
+
print('__id');
|
|
18
|
+
print.space();
|
|
19
|
+
print('__body');
|
|
20
|
+
};
|
|
21
|
+
|
package/package.json
CHANGED