@putout/printer 15.2.0 → 15.3.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
|
@@ -22,6 +22,7 @@ const {
|
|
|
22
22
|
isVariableDeclarator,
|
|
23
23
|
isFunction,
|
|
24
24
|
isObjectPattern,
|
|
25
|
+
isForOfStatement,
|
|
25
26
|
} = types;
|
|
26
27
|
|
|
27
28
|
const isInsideFn = (path) => {
|
|
@@ -42,12 +43,24 @@ const isCoupleProperties = ({path, valuePath, property}) => {
|
|
|
42
43
|
if (exists(property.getPrevSibling()))
|
|
43
44
|
return false;
|
|
44
45
|
|
|
45
|
-
|
|
46
|
+
const properties = path.get('properties');
|
|
47
|
+
|
|
48
|
+
if (path.parentPath.isVariableDeclarator() && !hasAssign(properties))
|
|
46
49
|
return false;
|
|
47
50
|
|
|
48
51
|
return !path.parentPath.isObjectProperty();
|
|
49
52
|
};
|
|
50
53
|
|
|
54
|
+
function isInsideForOf({parentPath}) {
|
|
55
|
+
return isForOfStatement(parentPath.parentPath.parentPath);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isPrevAssign(path) {
|
|
59
|
+
const prev = path.getPrevSibling();
|
|
60
|
+
|
|
61
|
+
return isAssignmentPattern(prev.node.value);
|
|
62
|
+
}
|
|
63
|
+
|
|
51
64
|
function isPrevAssignObject(path) {
|
|
52
65
|
const prev = path.getPrevSibling();
|
|
53
66
|
|
|
@@ -59,6 +72,20 @@ function isPrevAssignObject(path) {
|
|
|
59
72
|
return isObjectExpression(right);
|
|
60
73
|
}
|
|
61
74
|
|
|
75
|
+
function isNextAssignObject(path) {
|
|
76
|
+
const next = path.getNextSibling();
|
|
77
|
+
|
|
78
|
+
if (!next.node)
|
|
79
|
+
return false;
|
|
80
|
+
|
|
81
|
+
if (!isAssignmentPattern(next.node.value))
|
|
82
|
+
return false;
|
|
83
|
+
|
|
84
|
+
const {right} = next.node.value;
|
|
85
|
+
|
|
86
|
+
return isObjectExpression(right);
|
|
87
|
+
}
|
|
88
|
+
|
|
62
89
|
module.exports.ObjectPattern = {
|
|
63
90
|
print: maybeTypeAnnotation((path, printer, semantics) => {
|
|
64
91
|
const shouldIndent = isIndent(path);
|
|
@@ -100,6 +127,7 @@ module.exports.ObjectPattern = {
|
|
|
100
127
|
}
|
|
101
128
|
|
|
102
129
|
const prevAssignObject = i && isPrevAssignObject(property);
|
|
130
|
+
const nextAssignObject = isNextAssignObject(property);
|
|
103
131
|
|
|
104
132
|
const valuePath = property.get('value');
|
|
105
133
|
const keyPath = property.get('key');
|
|
@@ -115,6 +143,9 @@ module.exports.ObjectPattern = {
|
|
|
115
143
|
maybe.indent((prevAssignObject || is) && notInsideFn);
|
|
116
144
|
maybe.print.breakline(couple);
|
|
117
145
|
|
|
146
|
+
if (!isAssign && nextAssignObject)
|
|
147
|
+
print.breakline();
|
|
148
|
+
|
|
118
149
|
printKey(property, printer);
|
|
119
150
|
|
|
120
151
|
if (!shorthand || wrongShorthand({computed, isAssign, keyPath, valuePath})) {
|
|
@@ -126,6 +157,20 @@ module.exports.ObjectPattern = {
|
|
|
126
157
|
|
|
127
158
|
maybe.print(couple, ',');
|
|
128
159
|
maybe.print.newline(couple);
|
|
160
|
+
|
|
161
|
+
const {right} = valuePath.node;
|
|
162
|
+
|
|
163
|
+
if (i && !isPrevAssign(property) && !isInsideForOf(path) && isObjectExpression(right)) {
|
|
164
|
+
print(',');
|
|
165
|
+
print.newline();
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
if (!isAssign && nextAssignObject && notInsideFn) {
|
|
171
|
+
print(',');
|
|
172
|
+
print.breakline();
|
|
173
|
+
continue;
|
|
129
174
|
}
|
|
130
175
|
|
|
131
176
|
if (is || hasObject || prevAssignObject && notInsideFn) {
|
|
@@ -142,7 +187,8 @@ module.exports.ObjectPattern = {
|
|
|
142
187
|
}
|
|
143
188
|
|
|
144
189
|
indent.dec();
|
|
145
|
-
|
|
190
|
+
|
|
191
|
+
maybe.indent(is || hasAssign(properties));
|
|
146
192
|
maybe.indent.inc(!shouldIndent);
|
|
147
193
|
print('}');
|
|
148
194
|
}),
|
package/package.json
CHANGED