@putout/printer 15.1.0 → 15.1.1
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,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {types} = require('@putout/babel');
|
|
4
|
-
|
|
5
4
|
const {wrongShorthand} = require('./wrong-shortand');
|
|
6
5
|
|
|
7
6
|
const {
|
|
@@ -15,13 +14,20 @@ const {moreThenMaxPropertiesInOneLine} = require('./more-then-max-properties-in-
|
|
|
15
14
|
const {maybeTypeAnnotation} = require('../../maybe/maybe-type-annotation');
|
|
16
15
|
const {moreThenMaxPropertiesLengthInOneLine} = require('./more-then-max-properties-length-in-one-line');
|
|
17
16
|
const {printKey} = require('../object-expression/print-key');
|
|
18
|
-
|
|
17
|
+
|
|
18
|
+
const isInsideFn = (path) => {
|
|
19
|
+
if (isFunction(path.parentPath))
|
|
20
|
+
return true;
|
|
21
|
+
|
|
22
|
+
return isFunction(path.parentPath.parentPath);
|
|
23
|
+
};
|
|
19
24
|
|
|
20
25
|
const {
|
|
21
26
|
isIdentifier,
|
|
22
27
|
isObjectPattern,
|
|
23
28
|
isAssignmentPattern,
|
|
24
29
|
isVariableDeclarator,
|
|
30
|
+
isFunction,
|
|
25
31
|
} = types;
|
|
26
32
|
|
|
27
33
|
function isIndent(path) {
|
|
@@ -67,8 +73,8 @@ module.exports.ObjectPattern = {
|
|
|
67
73
|
});
|
|
68
74
|
|
|
69
75
|
const hasObject = n && hasObjectPattern(properties);
|
|
70
|
-
|
|
71
76
|
const notInsideFn = !isInsideFn(path);
|
|
77
|
+
|
|
72
78
|
maybe.print.newline(is && notInsideFn);
|
|
73
79
|
|
|
74
80
|
for (const [i, property] of properties.entries()) {
|
|
@@ -81,6 +87,9 @@ module.exports.ObjectPattern = {
|
|
|
81
87
|
continue;
|
|
82
88
|
}
|
|
83
89
|
|
|
90
|
+
const prev = property.getPrevSibling();
|
|
91
|
+
const prevAssign = i && isAssignmentPattern(prev.node.value);
|
|
92
|
+
|
|
84
93
|
const valuePath = property.get('value');
|
|
85
94
|
const keyPath = property.get('key');
|
|
86
95
|
const isAssign = valuePath.isAssignmentPattern();
|
|
@@ -92,7 +101,7 @@ module.exports.ObjectPattern = {
|
|
|
92
101
|
valuePath,
|
|
93
102
|
});
|
|
94
103
|
|
|
95
|
-
maybe.indent(is && notInsideFn);
|
|
104
|
+
maybe.indent((prevAssign || is) && notInsideFn);
|
|
96
105
|
maybe.print.breakline(couple);
|
|
97
106
|
|
|
98
107
|
printKey(property, printer);
|
|
@@ -108,7 +117,7 @@ module.exports.ObjectPattern = {
|
|
|
108
117
|
maybe.print.newline(couple);
|
|
109
118
|
}
|
|
110
119
|
|
|
111
|
-
if (is || hasObject) {
|
|
120
|
+
if (is || hasObject || prevAssign && notInsideFn) {
|
|
112
121
|
print(',');
|
|
113
122
|
print.newline();
|
|
114
123
|
|
|
@@ -209,3 +218,4 @@ function isFunctionParam({parentPath}) {
|
|
|
209
218
|
|
|
210
219
|
return parentPath.parentPath.isFunction();
|
|
211
220
|
}
|
|
221
|
+
|
package/package.json
CHANGED