@putout/printer 1.43.0 → 1.45.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 +10 -0
- package/lib/printer.js +1 -3
- package/lib/tokenize/comments.js +0 -2
- package/lib/tokenize/expressions/functions.js +1 -1
- package/lib/tokenize/statements/export-declarations.js +34 -2
- package/lib/tokenize/statements/index.js +2 -0
- package/lib/tokenize/typescript/index.js +20 -1
- package/lib/tokenize/typescript/ts-mapped-type.js +36 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
package/lib/printer.js
CHANGED
package/lib/tokenize/comments.js
CHANGED
|
@@ -57,6 +57,7 @@ function ArrowFunctionExpression(path, {print, maybe, write, traverse}) {
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
print(')');
|
|
60
|
+
|
|
60
61
|
const returnType = path.get('returnType');
|
|
61
62
|
|
|
62
63
|
if (exists(returnType)) {
|
|
@@ -140,4 +141,3 @@ module.exports.ClassMethod = (path, {print, maybe}) => {
|
|
|
140
141
|
print(') ');
|
|
141
142
|
print('__body');
|
|
142
143
|
};
|
|
143
|
-
|
|
@@ -1,6 +1,38 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
module.exports.
|
|
4
|
-
|
|
3
|
+
module.exports.ExportSpecifier = (path, {print}) => {
|
|
4
|
+
const {
|
|
5
|
+
local,
|
|
6
|
+
exported,
|
|
7
|
+
} = path.node;
|
|
8
|
+
|
|
9
|
+
print('__local');
|
|
10
|
+
|
|
11
|
+
if (exported.name !== local.name) {
|
|
12
|
+
print(' as ');
|
|
13
|
+
print('__exported');
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
module.exports.ExportNamedDeclaration = (path, {print, traverse, write, indent}) => {
|
|
18
|
+
const specifiers = path.get('specifiers');
|
|
19
|
+
write('export ');
|
|
20
|
+
|
|
21
|
+
if (specifiers.length) {
|
|
22
|
+
write('{');
|
|
23
|
+
indent.inc();
|
|
24
|
+
write.newline();
|
|
25
|
+
|
|
26
|
+
for (const spec of specifiers) {
|
|
27
|
+
indent();
|
|
28
|
+
traverse(spec);
|
|
29
|
+
write(',');
|
|
30
|
+
write.newline();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
indent.dec();
|
|
34
|
+
write('}');
|
|
35
|
+
}
|
|
36
|
+
|
|
5
37
|
print('__declaration');
|
|
6
38
|
};
|
|
@@ -16,12 +16,14 @@ const {SwitchStatement} = require('./switch-statement');
|
|
|
16
16
|
const {ForInStatement} = require('./for-in-statement');
|
|
17
17
|
const {ExportDefaultDeclaration} = require('./export-default-declaration');
|
|
18
18
|
const {BreakStatement} = require('./break-statement');
|
|
19
|
+
const {ExportSpecifier} = exportDeclarations;
|
|
19
20
|
|
|
20
21
|
module.exports = {
|
|
21
22
|
...importDeclarations,
|
|
22
23
|
...exportDeclarations,
|
|
23
24
|
BlockStatement,
|
|
24
25
|
ExpressionStatement,
|
|
26
|
+
ExportSpecifier,
|
|
25
27
|
ExportDefaultDeclaration,
|
|
26
28
|
VariableDeclaration,
|
|
27
29
|
IfStatement,
|
|
@@ -3,10 +3,12 @@
|
|
|
3
3
|
const {exists} = require('../is');
|
|
4
4
|
const {TSTypeLiteral} = require('./ts-type-literal');
|
|
5
5
|
const {TSTypeAliasDeclaration} = require('./ts-type-alias-declaration');
|
|
6
|
+
const {TSMappedType} = require('./ts-mapped-type');
|
|
6
7
|
|
|
7
8
|
module.exports = {
|
|
8
9
|
TSTypeLiteral,
|
|
9
10
|
TSTypeAliasDeclaration,
|
|
11
|
+
TSMappedType,
|
|
10
12
|
TSTypeParameterDeclaration(path, {print}) {
|
|
11
13
|
print('<');
|
|
12
14
|
|
|
@@ -33,8 +35,19 @@ module.exports = {
|
|
|
33
35
|
print('__elementType');
|
|
34
36
|
print('[]');
|
|
35
37
|
},
|
|
36
|
-
TSTypeParameter(path, {write}) {
|
|
38
|
+
TSTypeParameter(path, {write, traverse}) {
|
|
39
|
+
const constraint = path.get('constraint');
|
|
37
40
|
write(path.node.name);
|
|
41
|
+
|
|
42
|
+
if (exists(constraint)) {
|
|
43
|
+
write(' in ');
|
|
44
|
+
traverse(constraint);
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
TSTypeOperator(path, {write, print}) {
|
|
48
|
+
const {operator} = path.node;
|
|
49
|
+
write(`${operator} `);
|
|
50
|
+
print('__typeAnnotation');
|
|
38
51
|
},
|
|
39
52
|
TSUndefinedKeyword(path, {write}) {
|
|
40
53
|
write('undefined');
|
|
@@ -56,6 +69,12 @@ module.exports = {
|
|
|
56
69
|
TSNumberKeyword(path, {write}) {
|
|
57
70
|
write('number');
|
|
58
71
|
},
|
|
72
|
+
TSIndexedAccessType(path, {print}) {
|
|
73
|
+
print('__objectType');
|
|
74
|
+
print('[');
|
|
75
|
+
print('__indexType');
|
|
76
|
+
print(']');
|
|
77
|
+
},
|
|
59
78
|
TSStringKeyword(path, {write}) {
|
|
60
79
|
write('string');
|
|
61
80
|
},
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.TSMappedType = (path, {print, write, indent, maybe}) => {
|
|
4
|
+
const {
|
|
5
|
+
readonly,
|
|
6
|
+
optional,
|
|
7
|
+
} = path.node;
|
|
8
|
+
|
|
9
|
+
write('{');
|
|
10
|
+
write.newline();
|
|
11
|
+
indent.inc();
|
|
12
|
+
indent();
|
|
13
|
+
|
|
14
|
+
if (readonly) {
|
|
15
|
+
maybe.write(readonly === '-', '-');
|
|
16
|
+
write('readonly ');
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
write('[');
|
|
20
|
+
print('__typeParameter');
|
|
21
|
+
write(']');
|
|
22
|
+
|
|
23
|
+
if (optional) {
|
|
24
|
+
maybe.write(optional === '+', '+');
|
|
25
|
+
maybe.write(optional === '-', '-');
|
|
26
|
+
write('?');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
write(':');
|
|
30
|
+
write.space();
|
|
31
|
+
print('__typeAnnotation');
|
|
32
|
+
write(';');
|
|
33
|
+
indent.dec();
|
|
34
|
+
write.newline();
|
|
35
|
+
write('}');
|
|
36
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.45.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",
|