@putout/printer 8.18.0 → 8.20.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
CHANGED
|
@@ -36,15 +36,25 @@ const isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
|
|
|
36
36
|
const isObjectAfterSpread = (a) => isSpreadElement(a) && isNextObject(a) && !isPrevObject(a);
|
|
37
37
|
const isObjectAfterIdentifier = (a) => isIdentifier(a) && isNextObject(a) && !isPrevObject(a);
|
|
38
38
|
const isObjectAfterSimple = (a) => isObjectAfterSpread(a) || isObjectAfterIdentifier(a);
|
|
39
|
-
const
|
|
40
|
-
const isNextSpreadBetweenObjects = (a) => {
|
|
39
|
+
const isNextSimple = (a) => {
|
|
41
40
|
const next = a.getNextSibling();
|
|
42
|
-
|
|
41
|
+
|
|
42
|
+
if (next.isSpreadElement())
|
|
43
|
+
return true;
|
|
44
|
+
|
|
45
|
+
return next.isIdentifier();
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const isNextSimpleBetweenObjects = (a) => {
|
|
49
|
+
const next = a.getNextSibling();
|
|
50
|
+
const is = next.isSpreadElement() || next.isIdentifier();
|
|
43
51
|
|
|
44
52
|
if (!is)
|
|
45
53
|
return true;
|
|
46
54
|
|
|
47
|
-
return next
|
|
55
|
+
return next
|
|
56
|
+
.getNextSibling()
|
|
57
|
+
.isObjectExpression();
|
|
48
58
|
};
|
|
49
59
|
|
|
50
60
|
const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
|
|
@@ -96,7 +106,7 @@ module.exports.ArrayExpression = {
|
|
|
96
106
|
for (const [index, element] of elements.entries()) {
|
|
97
107
|
const is = isNewLine && isCurrentNewLine(element);
|
|
98
108
|
|
|
99
|
-
if (
|
|
109
|
+
if (isSimpleAfterObject(element))
|
|
100
110
|
print.newline();
|
|
101
111
|
|
|
102
112
|
maybe.indent(is);
|
|
@@ -111,7 +121,8 @@ module.exports.ArrayExpression = {
|
|
|
111
121
|
if (!is && index < n) {
|
|
112
122
|
print(',');
|
|
113
123
|
|
|
114
|
-
if (
|
|
124
|
+
if (isNextSimpleBetweenObjects(element) || !(element.isObjectExpression() && isNextSimple(element)))
|
|
125
|
+
//if (!(element.isObjectExpression() && isNextSimple(element)))
|
|
115
126
|
print.space();
|
|
116
127
|
}
|
|
117
128
|
}
|
|
@@ -160,3 +171,16 @@ module.exports.ArrayExpression = {
|
|
|
160
171
|
indent.inc();
|
|
161
172
|
},
|
|
162
173
|
};
|
|
174
|
+
|
|
175
|
+
function isSimpleAfterObject(path) {
|
|
176
|
+
if (!isSpreadElement(path) && !isIdentifier(path))
|
|
177
|
+
return;
|
|
178
|
+
|
|
179
|
+
const prev = path.getPrevSibling();
|
|
180
|
+
const next = path.getNextSibling();
|
|
181
|
+
|
|
182
|
+
if (next.isObjectExpression())
|
|
183
|
+
return false;
|
|
184
|
+
|
|
185
|
+
return prev.isObjectExpression();
|
|
186
|
+
}
|
package/package.json
CHANGED