@putout/printer 5.29.0 → 5.31.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
CHANGED
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {isArray} = Array;
|
|
3
4
|
const {exists} = require('../is');
|
|
4
5
|
|
|
6
|
+
const parseArgs = (path) => {
|
|
7
|
+
const argsPath = path.get('arguments');
|
|
8
|
+
|
|
9
|
+
if (!isArray(argsPath))
|
|
10
|
+
return [];
|
|
11
|
+
|
|
12
|
+
return argsPath;
|
|
13
|
+
};
|
|
14
|
+
|
|
5
15
|
function CallExpression(path, {indent, print, maybe, traverse}) {
|
|
6
|
-
const
|
|
16
|
+
const args = parseArgs(path);
|
|
17
|
+
const isParentCall = tooLong(args) && path.parentPath.isCallExpression();
|
|
7
18
|
|
|
8
19
|
const callee = path.get('callee');
|
|
9
20
|
const typeParameters = path.get('typeParameters');
|
|
@@ -18,7 +29,6 @@ function CallExpression(path, {indent, print, maybe, traverse}) {
|
|
|
18
29
|
|
|
19
30
|
print('(');
|
|
20
31
|
|
|
21
|
-
const args = path.get('arguments');
|
|
22
32
|
const n = args.length - 1;
|
|
23
33
|
|
|
24
34
|
maybe.indent.inc(isParentCall);
|
|
@@ -54,9 +64,7 @@ function CallExpression(path, {indent, print, maybe, traverse}) {
|
|
|
54
64
|
module.exports.OptionalCallExpression = CallExpression;
|
|
55
65
|
module.exports.CallExpression = CallExpression;
|
|
56
66
|
|
|
57
|
-
function tooLong(
|
|
58
|
-
const args = path.get('arguments');
|
|
59
|
-
|
|
67
|
+
function tooLong(args) {
|
|
60
68
|
for (const arg of args) {
|
|
61
69
|
if (arg.isIdentifier() && arg.node.name.length > 10)
|
|
62
70
|
return true;
|
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
const {markAfter} = require('../../mark');
|
|
4
4
|
const {exists, isNext} = require('../../is');
|
|
5
5
|
|
|
6
|
+
const isInside = ({parentPath}) => !parentPath.parentPath.isProgram();
|
|
7
|
+
|
|
6
8
|
const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
|
|
9
|
+
|
|
7
10
|
const isInsideNestedBody = ({parentPath}) => {
|
|
8
11
|
if (parentPath.type !== 'BlockStatement')
|
|
9
12
|
return false;
|
|
@@ -16,7 +19,11 @@ const isEmptyBody = (path) => !path.node.body.length;
|
|
|
16
19
|
|
|
17
20
|
module.exports.IfStatement = {
|
|
18
21
|
print: (path, {indent, print, maybe, write, traverse}) => {
|
|
19
|
-
|
|
22
|
+
const partOfAlternate = path.parentPath.get('alternate');
|
|
23
|
+
|
|
24
|
+
if (path !== partOfAlternate)
|
|
25
|
+
indent();
|
|
26
|
+
|
|
20
27
|
print('if');
|
|
21
28
|
print.space();
|
|
22
29
|
print('(');
|
|
@@ -59,6 +66,9 @@ module.exports.IfStatement = {
|
|
|
59
66
|
traverse(alternate);
|
|
60
67
|
indent.dec();
|
|
61
68
|
}
|
|
69
|
+
|
|
70
|
+
if (path === partOfAlternate && isInside(path))
|
|
71
|
+
print.newline();
|
|
62
72
|
},
|
|
63
73
|
afterSatisfy: () => [isNext],
|
|
64
74
|
after: (path, {print}) => {
|
package/package.json
CHANGED