@putout/printer 3.4.0 → 3.6.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/tokenize/expressions/function/arrow-function-expression.js +36 -46
- package/lib/tokenize/expressions/function/function-expression.js +28 -38
- package/lib/tokenize/expressions/function/parens.js +14 -0
- package/lib/tokenize/expressions/unary-expression/unary-expressions.js +15 -21
- package/lib/tokenize/literals/identifier.js +3 -11
- package/lib/tokenize/typescript/function/ts-function-type.js +4 -8
- package/lib/tokenize/typescript/index.js +6 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -2,50 +2,40 @@
|
|
|
2
2
|
|
|
3
3
|
const {exists} = require('../../is');
|
|
4
4
|
const {printParams} = require('./params');
|
|
5
|
+
const {maybeParens} = require('./parens');
|
|
5
6
|
|
|
6
|
-
module.exports.ArrowFunctionExpression = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const insideCall = path.parentPath.isCallExpression();
|
|
42
|
-
const isJSX = body.isJSXElement();
|
|
43
|
-
|
|
44
|
-
maybe.print.space(!insideCall && isJSX);
|
|
45
|
-
maybe.print.space(!isJSX);
|
|
46
|
-
print('__body');
|
|
47
|
-
},
|
|
48
|
-
after(path, {write}) {
|
|
49
|
-
write(')');
|
|
50
|
-
},
|
|
51
|
-
};
|
|
7
|
+
module.exports.ArrowFunctionExpression = maybeParens((path, printer, semantics) => {
|
|
8
|
+
const {
|
|
9
|
+
print,
|
|
10
|
+
maybe,
|
|
11
|
+
write,
|
|
12
|
+
traverse,
|
|
13
|
+
} = printer;
|
|
14
|
+
|
|
15
|
+
const {async} = path.node;
|
|
16
|
+
|
|
17
|
+
print('__typeParameters');
|
|
18
|
+
maybe.print(async, 'async ');
|
|
19
|
+
|
|
20
|
+
printParams(path, printer, semantics);
|
|
21
|
+
|
|
22
|
+
const returnType = path.get('returnType');
|
|
23
|
+
|
|
24
|
+
if (exists(returnType)) {
|
|
25
|
+
write(':');
|
|
26
|
+
write.space();
|
|
27
|
+
traverse(returnType);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
print.space();
|
|
31
|
+
print('=>');
|
|
32
|
+
|
|
33
|
+
const body = path.get('body');
|
|
34
|
+
|
|
35
|
+
const insideCall = path.parentPath.isCallExpression();
|
|
36
|
+
const isJSX = body.isJSXElement();
|
|
37
|
+
|
|
38
|
+
maybe.print.space(!insideCall && isJSX);
|
|
39
|
+
maybe.print.space(!isJSX);
|
|
40
|
+
print('__body');
|
|
41
|
+
});
|
|
@@ -2,42 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
const {exists} = require('../../is');
|
|
4
4
|
const {printParams} = require('./params');
|
|
5
|
+
const {maybeParens} = require('./parens');
|
|
5
6
|
|
|
6
|
-
module.exports.FunctionExpression = {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
printParams(path, printer, semantics);
|
|
36
|
-
|
|
37
|
-
print.space();
|
|
38
|
-
print('__body');
|
|
39
|
-
},
|
|
40
|
-
after(path, {write}) {
|
|
41
|
-
write(')');
|
|
42
|
-
},
|
|
43
|
-
};
|
|
7
|
+
module.exports.FunctionExpression = maybeParens((path, printer, semantics) => {
|
|
8
|
+
const {
|
|
9
|
+
print,
|
|
10
|
+
maybe,
|
|
11
|
+
write,
|
|
12
|
+
traverse,
|
|
13
|
+
} = printer;
|
|
14
|
+
|
|
15
|
+
const {node} = path;
|
|
16
|
+
const {generator, async} = node;
|
|
17
|
+
|
|
18
|
+
maybe.write(async, 'async ');
|
|
19
|
+
write('function');
|
|
20
|
+
maybe.write(generator, '*');
|
|
21
|
+
|
|
22
|
+
const id = path.get('id');
|
|
23
|
+
|
|
24
|
+
if (exists(id)) {
|
|
25
|
+
write(' ');
|
|
26
|
+
traverse(id);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
printParams(path, printer, semantics);
|
|
30
|
+
|
|
31
|
+
print.space();
|
|
32
|
+
print('__body');
|
|
33
|
+
});
|
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {isLast, isNext} = require('../../is');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
|
|
5
|
+
const {maybeParens} = require('../function/parens');
|
|
6
|
+
|
|
7
|
+
const isWord = (a) => /^(delete|typeof|void|throw)$/.test(a);
|
|
8
|
+
|
|
9
|
+
const unaryExpression = maybeParens((path, printer) => {
|
|
10
|
+
const {maybe, traverse} = printer;
|
|
11
|
+
const {prefix, operator} = path.node;
|
|
12
|
+
const argPath = path.get('argument');
|
|
13
|
+
|
|
14
|
+
maybe.print(prefix, operator);
|
|
15
|
+
maybe.print(isWord(operator), ' ');
|
|
16
|
+
traverse(argPath);
|
|
17
|
+
maybe.print(!prefix, operator);
|
|
18
|
+
});
|
|
8
19
|
|
|
9
20
|
module.exports.UnaryExpression = unaryExpression;
|
|
10
21
|
module.exports.UpdateExpression = unaryExpression;
|
|
@@ -40,20 +51,3 @@ function printUnary(path, name, {print}) {
|
|
|
40
51
|
print(`${name} `);
|
|
41
52
|
print('__argument');
|
|
42
53
|
}
|
|
43
|
-
|
|
44
|
-
const isWord = (a) => /^(delete|typeof|void|throw)$/.test(a);
|
|
45
|
-
|
|
46
|
-
function unaryExpression(path, printer) {
|
|
47
|
-
const {maybe, traverse} = printer;
|
|
48
|
-
const {prefix, operator} = path.node;
|
|
49
|
-
const argPath = path.get('argument');
|
|
50
|
-
|
|
51
|
-
maybeParenOpen(path, printer);
|
|
52
|
-
|
|
53
|
-
maybe.print(prefix, operator);
|
|
54
|
-
maybe.print(isWord(operator), ' ');
|
|
55
|
-
traverse(argPath);
|
|
56
|
-
maybe.print(!prefix, operator);
|
|
57
|
-
|
|
58
|
-
maybeParenClose(path, printer);
|
|
59
|
-
}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
maybeParenOpen,
|
|
5
|
-
maybeParenClose,
|
|
6
|
-
} = require('../expressions/unary-expression/parens');
|
|
7
|
-
|
|
8
3
|
const {maybeDecorators} = require('../maybe-get');
|
|
4
|
+
const {maybeParens} = require('../expressions/function/parens');
|
|
9
5
|
|
|
10
|
-
module.exports.Identifier = (path, printer) => {
|
|
6
|
+
module.exports.Identifier = maybeParens((path, printer) => {
|
|
11
7
|
const {
|
|
12
8
|
write,
|
|
13
9
|
maybe,
|
|
@@ -20,8 +16,6 @@ module.exports.Identifier = (path, printer) => {
|
|
|
20
16
|
|
|
21
17
|
const typeAnnotation = path.get('typeAnnotation');
|
|
22
18
|
|
|
23
|
-
maybeParenOpen(path, printer);
|
|
24
|
-
|
|
25
19
|
for (const decorator of maybeDecorators(path)) {
|
|
26
20
|
traverse(decorator);
|
|
27
21
|
print(' ');
|
|
@@ -30,6 +24,4 @@ module.exports.Identifier = (path, printer) => {
|
|
|
30
24
|
write(name);
|
|
31
25
|
maybe.write(optional, '?');
|
|
32
26
|
traverse(typeAnnotation);
|
|
33
|
-
|
|
34
|
-
maybeParenClose(path, printer);
|
|
35
|
-
};
|
|
27
|
+
});
|
|
@@ -2,19 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
const {printParams} = require('../../expressions/function/params');
|
|
4
4
|
const {printReturnType} = require('./print-return-type');
|
|
5
|
-
const {
|
|
6
|
-
maybeParenOpen,
|
|
7
|
-
maybeParenClose,
|
|
8
|
-
} = require('../../expressions/unary-expression/parens');
|
|
9
5
|
|
|
10
|
-
|
|
6
|
+
const {maybeParens} = require('../../expressions/function/parens');
|
|
7
|
+
|
|
8
|
+
module.exports.TSFunctionType = maybeParens((path, printer, semantics) => {
|
|
11
9
|
const {print} = printer;
|
|
12
10
|
|
|
13
|
-
maybeParenOpen(path, printer);
|
|
14
11
|
printParams(path, printer, semantics);
|
|
15
12
|
print.space();
|
|
16
13
|
print('=>');
|
|
17
14
|
print.space();
|
|
18
15
|
printReturnType(path, printer);
|
|
19
|
-
|
|
20
|
-
};
|
|
16
|
+
});
|
|
@@ -119,6 +119,11 @@ module.exports = {
|
|
|
119
119
|
TSBooleanKeyword(path, {write}) {
|
|
120
120
|
write('boolean');
|
|
121
121
|
},
|
|
122
|
+
TSSatisfiesExpression(path, {print}) {
|
|
123
|
+
print('__expression');
|
|
124
|
+
print(' satisfies ');
|
|
125
|
+
print('__typeAnnotation');
|
|
126
|
+
},
|
|
122
127
|
TSUnionType(path, printer) {
|
|
123
128
|
const {traverse, write} = printer;
|
|
124
129
|
|
|
@@ -229,3 +234,4 @@ module.exports = {
|
|
|
229
234
|
print('this');
|
|
230
235
|
},
|
|
231
236
|
};
|
|
237
|
+
|
package/package.json
CHANGED