@putout/printer 8.31.0 → 8.33.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 +11 -0
- package/lib/tokenize/expressions/array-expression/is-object-after-simple.js +0 -1
- package/lib/tokenize/expressions/object-pattern/more-then-max-properties-length-in-one-line.js +18 -2
- package/lib/tokenize/expressions/object-pattern/object-pattern.js +33 -8
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2024.05.03, v8.33.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- c8b9948 @putout/printer: ObjectPattern: improve support of maxPropertiesLengthInOneLine
|
|
5
|
+
- 039c54d @putout/printer: ObjectPattern: indent: simplify
|
|
6
|
+
|
|
7
|
+
2024.05.03, v8.32.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- 4c10986 @putout/printer: ObjectPattern: used as Function param
|
|
11
|
+
|
|
1
12
|
2024.05.03, v8.31.0
|
|
2
13
|
|
|
3
14
|
feature:
|
package/lib/tokenize/expressions/object-pattern/more-then-max-properties-length-in-one-line.js
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
isAssignmentPattern,
|
|
5
|
+
isIdentifier,
|
|
6
|
+
} = require('@putout/babel').types;
|
|
4
7
|
|
|
5
8
|
module.exports.moreThenMaxPropertiesLengthInOneLine = (path, {maxPropertiesLengthInOneLine}) => {
|
|
6
9
|
const {properties} = path.node;
|
|
7
10
|
|
|
8
|
-
for (const {key} of properties) {
|
|
11
|
+
for (const {key, value} of properties) {
|
|
12
|
+
if (isAssignmentPattern(value)) {
|
|
13
|
+
const {left, right} = value;
|
|
14
|
+
|
|
15
|
+
if (!isIdentifier(left) || !isIdentifier(right))
|
|
16
|
+
continue;
|
|
17
|
+
|
|
18
|
+
const length = left.name.length + right.name.length;
|
|
19
|
+
|
|
20
|
+
if (length >= maxPropertiesLengthInOneLine)
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
9
24
|
if (!isIdentifier(key))
|
|
10
25
|
continue;
|
|
11
26
|
|
|
@@ -17,3 +32,4 @@ module.exports.moreThenMaxPropertiesLengthInOneLine = (path, {maxPropertiesLengt
|
|
|
17
32
|
|
|
18
33
|
return false;
|
|
19
34
|
};
|
|
35
|
+
|
|
@@ -26,8 +26,18 @@ function isIndent(path) {
|
|
|
26
26
|
return !path.parentPath.isArrayPattern();
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
const isCoupleProperties = ({path, valuePath, property}) => {
|
|
30
|
+
if (!isCoupleLines(valuePath))
|
|
31
|
+
return false;
|
|
32
|
+
|
|
33
|
+
if (exists(property.getPrevSibling()))
|
|
34
|
+
return false;
|
|
35
|
+
|
|
36
|
+
return !path.parentPath.isObjectProperty();
|
|
37
|
+
};
|
|
38
|
+
|
|
29
39
|
module.exports.ObjectPattern = {
|
|
30
|
-
print: maybeTypeAnnotation((path, {print, maybe}, semantics) => {
|
|
40
|
+
print: maybeTypeAnnotation((path, {print, maybe, indent}, semantics) => {
|
|
31
41
|
const shouldIndent = isIndent(path);
|
|
32
42
|
const {
|
|
33
43
|
maxPropertiesInOneLine,
|
|
@@ -64,7 +74,11 @@ module.exports.ObjectPattern = {
|
|
|
64
74
|
const isAssign = valuePath.isAssignmentPattern();
|
|
65
75
|
|
|
66
76
|
const {shorthand, computed} = property.node;
|
|
67
|
-
const couple =
|
|
77
|
+
const couple = isCoupleProperties({
|
|
78
|
+
path,
|
|
79
|
+
property,
|
|
80
|
+
valuePath,
|
|
81
|
+
});
|
|
68
82
|
|
|
69
83
|
maybe.indent(is);
|
|
70
84
|
maybe.print.breakline(couple);
|
|
@@ -84,7 +98,7 @@ module.exports.ObjectPattern = {
|
|
|
84
98
|
maybe.print.newline(couple);
|
|
85
99
|
}
|
|
86
100
|
|
|
87
|
-
if (is || hasObject) {
|
|
101
|
+
if (is || hasObject && !isAssign) {
|
|
88
102
|
print(',');
|
|
89
103
|
print.newline();
|
|
90
104
|
|
|
@@ -97,9 +111,7 @@ module.exports.ObjectPattern = {
|
|
|
97
111
|
}
|
|
98
112
|
}
|
|
99
113
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
maybe.indent.dec(!shouldIndent);
|
|
114
|
+
indent.dec();
|
|
103
115
|
maybe.indent(is);
|
|
104
116
|
maybe.indent.inc(!shouldIndent);
|
|
105
117
|
print('}');
|
|
@@ -173,14 +185,27 @@ function shouldAddNewline(path, semantics) {
|
|
|
173
185
|
maxPropertiesInOneLine,
|
|
174
186
|
});
|
|
175
187
|
|
|
188
|
+
const fnParam = isFunctionParam(path);
|
|
189
|
+
|
|
176
190
|
if (moreCount && !moreLength)
|
|
177
191
|
return ONE_LINE;
|
|
178
192
|
|
|
179
|
-
if (!
|
|
193
|
+
if (!fnParam && n && !isForOf(path) && checkLength(properties))
|
|
180
194
|
return COUPLE_LINES;
|
|
181
195
|
|
|
182
|
-
if (hasAssign(properties))
|
|
196
|
+
if (!fnParam && hasAssign(properties))
|
|
183
197
|
return COUPLE_LINES;
|
|
184
198
|
|
|
185
199
|
return parentPath.isObjectProperty();
|
|
186
200
|
}
|
|
201
|
+
|
|
202
|
+
function isFunctionParam({parentPath}) {
|
|
203
|
+
if (parentPath.isFunction())
|
|
204
|
+
return true;
|
|
205
|
+
|
|
206
|
+
if (!parentPath.isAssignmentPattern())
|
|
207
|
+
return false;
|
|
208
|
+
|
|
209
|
+
return parentPath.parentPath.isFunction();
|
|
210
|
+
}
|
|
211
|
+
|
package/package.json
CHANGED