@putout/printer 15.20.3 → 15.20.5
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
|
@@ -19,7 +19,8 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
|
|
|
19
19
|
braceClose = ')',
|
|
20
20
|
printSpace = print.space,
|
|
21
21
|
printAfterOpen = noop,
|
|
22
|
-
printBeforeClose = noop
|
|
22
|
+
printBeforeClose = noop,
|
|
23
|
+
} = customization;
|
|
23
24
|
|
|
24
25
|
if (typeParameters)
|
|
25
26
|
traverse(path.get('typeParameters'));
|
|
@@ -1,34 +1,27 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {types} = require('@putout/babel');
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
isAssignmentPattern,
|
|
6
|
+
isArrayExpression,
|
|
7
|
+
isObjectExpression,
|
|
8
|
+
} = types;
|
|
5
9
|
|
|
6
10
|
module.exports.calculateAssigns = (property, semantics) => {
|
|
7
|
-
const prev = property.getPrevSibling();
|
|
8
|
-
const next = property.getNextSibling();
|
|
9
|
-
|
|
10
11
|
const currentAssign = isLongAssignPattern(property, semantics);
|
|
11
|
-
const prevAssign = isLongAssignPattern(prev, semantics);
|
|
12
|
-
const nextAssign = isLongAssignPattern(next, semantics);
|
|
13
|
-
const bothLongAssigns = currentAssign && (nextAssign || prevAssign);
|
|
14
12
|
|
|
15
|
-
const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|| !isAssignmentPattern(next.node?.value));
|
|
13
|
+
const {right} = property.node.value;
|
|
14
|
+
const isArrayOrObjectRight = isArrayExpression(right) || isComplexObject(right);
|
|
15
|
+
const complexAssign = currentAssign && isArrayOrObjectRight;
|
|
19
16
|
|
|
20
17
|
return {
|
|
21
|
-
|
|
22
|
-
oneLongAssign,
|
|
18
|
+
complexAssign,
|
|
23
19
|
};
|
|
24
20
|
};
|
|
25
21
|
|
|
26
22
|
module.exports.isLongAssignPattern = isLongAssignPattern;
|
|
27
23
|
|
|
28
24
|
function isLongAssignPattern(path, semantics) {
|
|
29
|
-
if (!path.node)
|
|
30
|
-
return false;
|
|
31
|
-
|
|
32
25
|
if (!isAssignmentPattern(path.node.value))
|
|
33
26
|
return false;
|
|
34
27
|
|
|
@@ -36,3 +29,10 @@ function isLongAssignPattern(path, semantics) {
|
|
|
36
29
|
|
|
37
30
|
return path.node.key.name.length > maxPropertiesLengthInOneLine;
|
|
38
31
|
}
|
|
32
|
+
|
|
33
|
+
function isComplexObject(node) {
|
|
34
|
+
if (!isObjectExpression(node))
|
|
35
|
+
return false;
|
|
36
|
+
|
|
37
|
+
return node.properties.length;
|
|
38
|
+
}
|
|
@@ -179,12 +179,9 @@ module.exports.ObjectPattern = {
|
|
|
179
179
|
continue;
|
|
180
180
|
}
|
|
181
181
|
|
|
182
|
-
const {
|
|
183
|
-
oneLongAssign,
|
|
184
|
-
bothLongAssigns,
|
|
185
|
-
} = calculateAssigns(property, semantics);
|
|
182
|
+
const {complexAssign} = calculateAssigns(property, semantics);
|
|
186
183
|
|
|
187
|
-
if (
|
|
184
|
+
if (!complexAssign && (is || hasObject || prevAssignObject && notInsideFn)) {
|
|
188
185
|
print(',');
|
|
189
186
|
print.newline();
|
|
190
187
|
|
package/package.json
CHANGED