@putout/printer 18.38.1 → 18.39.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 +7 -0
- package/README.md +1 -0
- package/lib/tokenize/expressions/call-expression/call-expression-with-max-args.js +18 -0
- package/lib/tokenize/expressions/call-expression/call-expression.js +46 -9
- package/lib/tokenize/overrides/overrides.js +1 -0
- package/lib/tokenize/type-checker/report.js +1 -1
- package/package.json +1 -2
package/ChangeLog
CHANGED
package/README.md
CHANGED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const CallExpressionWithMaxArgs = (path, {write, indent, traverse}) => {
|
|
2
|
+
const {name} = path.node.callee;
|
|
3
|
+
const args = path.get('arguments');
|
|
4
|
+
|
|
5
|
+
write(name);
|
|
6
|
+
write('(');
|
|
7
|
+
indent.inc();
|
|
8
|
+
|
|
9
|
+
for (const arg of args) {
|
|
10
|
+
write.breakline();
|
|
11
|
+
traverse(arg);
|
|
12
|
+
write(',');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
indent.dec();
|
|
16
|
+
write.breakline();
|
|
17
|
+
write(')');
|
|
18
|
+
};
|
|
@@ -1,5 +1,14 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
1
2
|
import {exists, isInsideCall} from '#is';
|
|
2
3
|
import {maybeParens} from '#maybe-parens';
|
|
4
|
+
import {createTypeChecker} from '#type-checker';
|
|
5
|
+
import {CallExpressionWithMaxArgs} from './call-expression-with-max-args.js';
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
isIdentifier,
|
|
9
|
+
isObjectExpression,
|
|
10
|
+
isArrayExpression,
|
|
11
|
+
} = types;
|
|
3
12
|
|
|
4
13
|
const {isArray} = Array;
|
|
5
14
|
|
|
@@ -12,9 +21,35 @@ const parseArgs = (path) => {
|
|
|
12
21
|
return argsPath;
|
|
13
22
|
};
|
|
14
23
|
|
|
15
|
-
|
|
24
|
+
function isMaxArgs(path, {maxArgsInOneLine}) {
|
|
25
|
+
const args = parseArgs(path);
|
|
26
|
+
|
|
27
|
+
const [first] = args;
|
|
28
|
+
|
|
29
|
+
if (isArrayExpression(first))
|
|
30
|
+
return false;
|
|
31
|
+
|
|
32
|
+
return args.length >= maxArgsInOneLine;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const isNeedsNewLine = createTypeChecker([
|
|
36
|
+
['-: -> !', tooLong],
|
|
37
|
+
['+', isInsideCall],
|
|
38
|
+
]);
|
|
39
|
+
|
|
40
|
+
export const CallExpression = maybeParens((path, printer, semantics) => {
|
|
41
|
+
if (isMaxArgs(path, semantics))
|
|
42
|
+
return CallExpressionWithMaxArgs(path, printer);
|
|
43
|
+
|
|
44
|
+
const {
|
|
45
|
+
indent,
|
|
46
|
+
print,
|
|
47
|
+
maybe,
|
|
48
|
+
traverse,
|
|
49
|
+
} = printer;
|
|
50
|
+
|
|
16
51
|
const args = parseArgs(path);
|
|
17
|
-
const
|
|
52
|
+
const needsNewline = isNeedsNewLine(path, semantics);
|
|
18
53
|
|
|
19
54
|
const callee = path.get('callee');
|
|
20
55
|
const typeParameters = path.get('typeArguments');
|
|
@@ -31,17 +66,17 @@ export const CallExpression = maybeParens((path, {indent, print, maybe, traverse
|
|
|
31
66
|
|
|
32
67
|
const n = args.length - 1;
|
|
33
68
|
|
|
34
|
-
maybe.indent.inc(
|
|
69
|
+
maybe.indent.inc(needsNewline);
|
|
35
70
|
|
|
36
71
|
for (const [i, arg] of args.entries()) {
|
|
37
|
-
const isObject =
|
|
72
|
+
const isObject = isObjectExpression(arg);
|
|
38
73
|
|
|
39
|
-
if (
|
|
74
|
+
if (needsNewline && !isObject && n)
|
|
40
75
|
print.breakline();
|
|
41
76
|
|
|
42
77
|
print(arg);
|
|
43
78
|
|
|
44
|
-
if (
|
|
79
|
+
if (needsNewline && n) {
|
|
45
80
|
print(',');
|
|
46
81
|
continue;
|
|
47
82
|
}
|
|
@@ -52,7 +87,7 @@ export const CallExpression = maybeParens((path, {indent, print, maybe, traverse
|
|
|
52
87
|
}
|
|
53
88
|
}
|
|
54
89
|
|
|
55
|
-
if (
|
|
90
|
+
if (needsNewline) {
|
|
56
91
|
indent.dec();
|
|
57
92
|
maybe.print.breakline(n);
|
|
58
93
|
}
|
|
@@ -62,9 +97,11 @@ export const CallExpression = maybeParens((path, {indent, print, maybe, traverse
|
|
|
62
97
|
|
|
63
98
|
export const OptionalCallExpression = CallExpression;
|
|
64
99
|
|
|
65
|
-
function tooLong(
|
|
100
|
+
function tooLong(path) {
|
|
101
|
+
const args = parseArgs(path);
|
|
102
|
+
|
|
66
103
|
for (const arg of args) {
|
|
67
|
-
if (
|
|
104
|
+
if (isIdentifier(arg) && arg.node.name.length > 10)
|
|
68
105
|
return true;
|
|
69
106
|
}
|
|
70
107
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "18.
|
|
3
|
+
"version": "18.39.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
|
|
@@ -86,7 +86,6 @@
|
|
|
86
86
|
"@putout/plugin-react-hooks": "^9.0.0",
|
|
87
87
|
"@supertape/operator-strip": "^1.0.0",
|
|
88
88
|
"acorn": "^8.8.2",
|
|
89
|
-
"chalk": "^5.6.2",
|
|
90
89
|
"check-dts": "^1.0.0",
|
|
91
90
|
"escover": "^6.0.0",
|
|
92
91
|
"eslint": "^10.0.0",
|