@putout/printer 3.2.0 → 3.4.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/call-expression.js +0 -4
- package/lib/tokenize/expressions/function/arrow-function-expression.js +2 -3
- package/lib/tokenize/expressions/function/function-expression.js +37 -26
- package/lib/tokenize/statements/block-statement/block-statement.js +11 -1
- package/lib/tokenize/statements/do-while-statement.js +19 -9
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -7,16 +7,12 @@ function CallExpression(path, {indent, print, maybe, traverse}) {
|
|
|
7
7
|
|
|
8
8
|
const callee = path.get('callee');
|
|
9
9
|
const typeParameters = path.get('typeParameters');
|
|
10
|
-
const isFn = callee.isFunction();
|
|
11
10
|
|
|
12
|
-
maybe.write(isFn, '(');
|
|
13
11
|
traverse(callee);
|
|
14
12
|
|
|
15
13
|
if (exists(typeParameters))
|
|
16
14
|
traverse(typeParameters);
|
|
17
15
|
|
|
18
|
-
maybe.write(isFn, ')');
|
|
19
|
-
|
|
20
16
|
if (path.node.optional)
|
|
21
17
|
print('?.');
|
|
22
18
|
|
|
@@ -4,8 +4,8 @@ const {exists} = require('../../is');
|
|
|
4
4
|
const {printParams} = require('./params');
|
|
5
5
|
|
|
6
6
|
module.exports.ArrowFunctionExpression = {
|
|
7
|
-
condition(
|
|
8
|
-
return
|
|
7
|
+
condition(path) {
|
|
8
|
+
return path.node.extra?.parenthesized;
|
|
9
9
|
},
|
|
10
10
|
before(path, {write}) {
|
|
11
11
|
write('(');
|
|
@@ -21,7 +21,6 @@ module.exports.ArrowFunctionExpression = {
|
|
|
21
21
|
const {async} = path.node;
|
|
22
22
|
|
|
23
23
|
print('__typeParameters');
|
|
24
|
-
|
|
25
24
|
maybe.print(async, 'async ');
|
|
26
25
|
|
|
27
26
|
printParams(path, printer, semantics);
|
|
@@ -3,30 +3,41 @@
|
|
|
3
3
|
const {exists} = require('../../is');
|
|
4
4
|
const {printParams} = require('./params');
|
|
5
5
|
|
|
6
|
-
module.exports.FunctionExpression =
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
write(' ');
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
6
|
+
module.exports.FunctionExpression = {
|
|
7
|
+
condition(path) {
|
|
8
|
+
return path.node.extra?.parenthesized;
|
|
9
|
+
},
|
|
10
|
+
before(path, {write}) {
|
|
11
|
+
write('(');
|
|
12
|
+
},
|
|
13
|
+
print(path, printer, semantics) {
|
|
14
|
+
const {
|
|
15
|
+
print,
|
|
16
|
+
maybe,
|
|
17
|
+
write,
|
|
18
|
+
traverse,
|
|
19
|
+
} = printer;
|
|
20
|
+
|
|
21
|
+
const {node} = path;
|
|
22
|
+
const {generator, async} = node;
|
|
23
|
+
|
|
24
|
+
maybe.write(async, 'async ');
|
|
25
|
+
write('function');
|
|
26
|
+
maybe.write(generator, '*');
|
|
27
|
+
|
|
28
|
+
const id = path.get('id');
|
|
29
|
+
|
|
30
|
+
if (exists(id)) {
|
|
31
|
+
write(' ');
|
|
32
|
+
traverse(id);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
printParams(path, printer, semantics);
|
|
36
|
+
|
|
37
|
+
print.space();
|
|
38
|
+
print('__body');
|
|
39
|
+
},
|
|
40
|
+
after(path, {write}) {
|
|
41
|
+
write(')');
|
|
42
|
+
},
|
|
32
43
|
};
|
|
@@ -21,6 +21,13 @@ const isFirstStatement = (path) => path.node.body[0];
|
|
|
21
21
|
const isFirstDirective = (path) => path.node.directives?.[0];
|
|
22
22
|
const isMethodOrArrow = (path) => isArrowFunctionExpression(path) || isObjectMethod(path);
|
|
23
23
|
|
|
24
|
+
const parentIfWithoutElse = ({parentPath}) => {
|
|
25
|
+
if (!parentPath.isIfStatement())
|
|
26
|
+
return false;
|
|
27
|
+
|
|
28
|
+
return !parentPath.node.alternate;
|
|
29
|
+
};
|
|
30
|
+
|
|
24
31
|
module.exports.BlockStatement = {
|
|
25
32
|
print(path, {indent, maybe, write, traverse}, semantics) {
|
|
26
33
|
const body = path.get('body');
|
|
@@ -65,6 +72,9 @@ module.exports.BlockStatement = {
|
|
|
65
72
|
function shouldAddNewlineAfter(path) {
|
|
66
73
|
const {parentPath} = path;
|
|
67
74
|
|
|
75
|
+
if (parentPath.isDoWhileStatement())
|
|
76
|
+
return false;
|
|
77
|
+
|
|
68
78
|
if (parentPath.isBlockStatement())
|
|
69
79
|
return true;
|
|
70
80
|
|
|
@@ -74,7 +84,7 @@ function shouldAddNewlineAfter(path) {
|
|
|
74
84
|
if (insideIfWithNoBody(path))
|
|
75
85
|
return false;
|
|
76
86
|
|
|
77
|
-
if (path
|
|
87
|
+
if (parentIfWithoutElse(path) && path.find(isMethodOrArrow))
|
|
78
88
|
return true;
|
|
79
89
|
|
|
80
90
|
if (parentPath.isStatement() && !path.node.body.length && !isNext(parentPath))
|
|
@@ -1,12 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
print
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
3
|
+
const {isLast} = require('../is');
|
|
4
|
+
const notLast = (path) => !isLast(path);
|
|
5
|
+
|
|
6
|
+
module.exports.DoWhileStatement = {
|
|
7
|
+
print(path, {print, indent}) {
|
|
8
|
+
indent();
|
|
9
|
+
print('do');
|
|
10
|
+
print.space();
|
|
11
|
+
print('__body');
|
|
12
|
+
print.space();
|
|
13
|
+
print('while ');
|
|
14
|
+
print('(');
|
|
15
|
+
print('__test');
|
|
16
|
+
print(')');
|
|
17
|
+
},
|
|
18
|
+
afterSatisfy: () => [notLast],
|
|
19
|
+
after(path, {print}) {
|
|
20
|
+
print.newline();
|
|
21
|
+
},
|
|
12
22
|
};
|
package/package.json
CHANGED