@putout/printer 18.47.3 → 18.47.4
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
|
@@ -3,6 +3,15 @@ import {isInsideCall} from '#is';
|
|
|
3
3
|
import {maybeParens} from '#maybe-parens';
|
|
4
4
|
import {createTypeChecker} from '#type-checker';
|
|
5
5
|
|
|
6
|
+
const isLast = (arg) => {
|
|
7
|
+
const {length} = arg.parentPath.node.arguments;
|
|
8
|
+
const n = length - 1;
|
|
9
|
+
|
|
10
|
+
return arg.key === n;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
const getFirstArg = (fn) => (path) => fn(path.get('arguments.0'));
|
|
14
|
+
|
|
6
15
|
const getMaxArgsInOneLine = (path, {maxArgsInOneLine}) => maxArgsInOneLine;
|
|
7
16
|
const firstArgIsArray = (path) => isArrayExpression(path.node?.arguments?.[0]);
|
|
8
17
|
|
|
@@ -71,27 +80,30 @@ const isBreaklineAfterArg = createTypeChecker([
|
|
|
71
80
|
]);
|
|
72
81
|
|
|
73
82
|
const isCommaAfterArg = createTypeChecker([
|
|
83
|
+
['+: -> !', isLast],
|
|
84
|
+
['+', isMemberCallee],
|
|
85
|
+
['+: parentPath', isMaxArgs],
|
|
86
|
+
['-: parentPath.node.arguments.length', '<=', 1],
|
|
87
|
+
['+: parentPath', isMultiline],
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
const isBreaklineAfterAllArgs = createTypeChecker([
|
|
74
91
|
['+', isMaxArgs],
|
|
75
|
-
['-:
|
|
76
|
-
['
|
|
92
|
+
['-: -> !', isMultiline],
|
|
93
|
+
['+: node.arguments.length', '>', 1],
|
|
94
|
+
['+', getFirstArg(isMemberCallee)],
|
|
77
95
|
]);
|
|
78
96
|
|
|
97
|
+
const isIndent = createTypeChecker([isMaxArgs, isMultiline]);
|
|
98
|
+
|
|
79
99
|
function printArgs(path, printer, semantics) {
|
|
100
|
+
const {indent, print} = printer;
|
|
80
101
|
const args = parseArgs(path);
|
|
81
|
-
const maxArgs = isMaxArgs(path, semantics);
|
|
82
|
-
const multiline = maxArgs || isMultiline(path, semantics);
|
|
83
|
-
|
|
84
|
-
const {
|
|
85
|
-
indent,
|
|
86
|
-
print,
|
|
87
|
-
maybe,
|
|
88
|
-
} = printer;
|
|
89
102
|
|
|
90
|
-
|
|
103
|
+
if (isIndent(path, semantics))
|
|
104
|
+
indent.inc();
|
|
91
105
|
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
for (const [i, arg] of args.entries()) {
|
|
106
|
+
for (const arg of args) {
|
|
95
107
|
if (isSpaceAfterArg(arg, semantics))
|
|
96
108
|
print.space();
|
|
97
109
|
|
|
@@ -100,24 +112,26 @@ function printArgs(path, printer, semantics) {
|
|
|
100
112
|
|
|
101
113
|
print(arg);
|
|
102
114
|
|
|
103
|
-
if (isCommaAfterArg(
|
|
115
|
+
if (isCommaAfterArg(arg, semantics))
|
|
104
116
|
print(',');
|
|
105
|
-
continue;
|
|
106
|
-
}
|
|
107
117
|
|
|
108
|
-
if (
|
|
109
|
-
print(',');
|
|
110
|
-
|
|
111
|
-
if (i < n)
|
|
118
|
+
if (isSpace(arg, semantics))
|
|
112
119
|
print.space();
|
|
113
120
|
}
|
|
114
121
|
|
|
115
|
-
if (
|
|
122
|
+
if (isIndent(path, semantics))
|
|
116
123
|
indent.dec();
|
|
117
|
-
|
|
118
|
-
|
|
124
|
+
|
|
125
|
+
if (isBreaklineAfterAllArgs(path, semantics))
|
|
126
|
+
print.breakline();
|
|
119
127
|
}
|
|
120
128
|
|
|
129
|
+
const isSpace = createTypeChecker([
|
|
130
|
+
['-: parentPath', isMultiline],
|
|
131
|
+
['-: parentPath', isMaxArgs],
|
|
132
|
+
['+: -> !', isLast],
|
|
133
|
+
]);
|
|
134
|
+
|
|
121
135
|
function tooLong(path) {
|
|
122
136
|
const args = parseArgs(path);
|
|
123
137
|
|
|
@@ -128,4 +142,3 @@ function tooLong(path) {
|
|
|
128
142
|
|
|
129
143
|
return false;
|
|
130
144
|
}
|
|
131
|
-
|
package/package.json
CHANGED