@putout/printer 8.17.0 → 8.19.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
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2024.04.19, v8.19.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 285747d @putout/printer: ArrayExpression: SpreadAfterObject
|
|
5
|
+
|
|
6
|
+
2024.04.19, v8.18.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 8a56e08 @putout/printer: ArrayExpression: SpreadElement after ObjectExpression
|
|
10
|
+
|
|
1
11
|
2024.04.16, v8.17.0
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -7,6 +7,8 @@ const {
|
|
|
7
7
|
isIdentifierAndIdentifier,
|
|
8
8
|
isStringAndArray,
|
|
9
9
|
isSimpleAndEmptyObject,
|
|
10
|
+
isNext,
|
|
11
|
+
|
|
10
12
|
} = require('../../is');
|
|
11
13
|
|
|
12
14
|
const {
|
|
@@ -36,6 +38,19 @@ const isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
|
|
|
36
38
|
const isObjectAfterSpread = (a) => isSpreadElement(a) && isNextObject(a) && !isPrevObject(a);
|
|
37
39
|
const isObjectAfterIdentifier = (a) => isIdentifier(a) && isNextObject(a) && !isPrevObject(a);
|
|
38
40
|
const isObjectAfterSimple = (a) => isObjectAfterSpread(a) || isObjectAfterIdentifier(a);
|
|
41
|
+
const isNextSpread = (a) => a.getNextSibling().isSpreadElement();
|
|
42
|
+
|
|
43
|
+
const isNextSpreadBetweenObjects = (a) => {
|
|
44
|
+
const next = a.getNextSibling();
|
|
45
|
+
const is = next.isSpreadElement();
|
|
46
|
+
|
|
47
|
+
if (!is)
|
|
48
|
+
return true;
|
|
49
|
+
|
|
50
|
+
return next
|
|
51
|
+
.getNextSibling()
|
|
52
|
+
.isObjectExpression();
|
|
53
|
+
};
|
|
39
54
|
|
|
40
55
|
const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
|
|
41
56
|
|
|
@@ -85,6 +100,10 @@ module.exports.ArrayExpression = {
|
|
|
85
100
|
|
|
86
101
|
for (const [index, element] of elements.entries()) {
|
|
87
102
|
const is = isNewLine && isCurrentNewLine(element);
|
|
103
|
+
|
|
104
|
+
if (isSpreadAfterObject(element))
|
|
105
|
+
print.newline();
|
|
106
|
+
|
|
88
107
|
maybe.indent(is);
|
|
89
108
|
print(element);
|
|
90
109
|
|
|
@@ -96,7 +115,9 @@ module.exports.ArrayExpression = {
|
|
|
96
115
|
|
|
97
116
|
if (!is && index < n) {
|
|
98
117
|
print(',');
|
|
99
|
-
|
|
118
|
+
|
|
119
|
+
if (isNextSpreadBetweenObjects(element) || !(element.isObjectExpression() && isNextSpread(element)))
|
|
120
|
+
print.space();
|
|
100
121
|
}
|
|
101
122
|
}
|
|
102
123
|
|
|
@@ -116,7 +137,7 @@ module.exports.ArrayExpression = {
|
|
|
116
137
|
maybe.indent(elements.length && isNewLine);
|
|
117
138
|
}
|
|
118
139
|
|
|
119
|
-
if (isSimpleAndEmptyObject(elements)) {
|
|
140
|
+
if (isSimpleAndEmptyObject(elements) && !isSpreadElement(elements.at(-1))) {
|
|
120
141
|
print(',');
|
|
121
142
|
print.breakline();
|
|
122
143
|
}
|
|
@@ -144,3 +165,16 @@ module.exports.ArrayExpression = {
|
|
|
144
165
|
indent.inc();
|
|
145
166
|
},
|
|
146
167
|
};
|
|
168
|
+
|
|
169
|
+
function isSpreadAfterObject(path) {
|
|
170
|
+
if (!isSpreadElement(path))
|
|
171
|
+
return;
|
|
172
|
+
|
|
173
|
+
const prev = path.getPrevSibling();
|
|
174
|
+
const next = path.getNextSibling();
|
|
175
|
+
|
|
176
|
+
if (next.isObjectExpression())
|
|
177
|
+
return false;
|
|
178
|
+
|
|
179
|
+
return prev.isObjectExpression();
|
|
180
|
+
}
|
package/package.json
CHANGED