@putout/printer 2.27.0 → 2.29.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
|
+
2023.06.19, v2.29.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- feb7c6a @putout/printer: ArrayExpression: String/String: tuple
|
|
5
|
+
|
|
6
|
+
2023.06.19, v2.28.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 10230c2 @putout/printer: ObjectExpression inside ArrayExpression: newline
|
|
10
|
+
|
|
1
11
|
2023.06.19, v2.27.0
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -10,8 +10,13 @@ const {
|
|
|
10
10
|
const {
|
|
11
11
|
isNewlineBetweenElements,
|
|
12
12
|
isIncreaseIndent,
|
|
13
|
+
isCurrentNewLine,
|
|
13
14
|
} = require('./new-line');
|
|
14
15
|
|
|
16
|
+
const {isObjectExpression} = require('@babel/types');
|
|
17
|
+
|
|
18
|
+
const isNextObject = (a) => a.getNextSibling().isObjectExpression();
|
|
19
|
+
|
|
15
20
|
const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
|
|
16
21
|
const isInsideArray = (path) => path.parentPath.isArrayExpression();
|
|
17
22
|
|
|
@@ -63,19 +68,22 @@ module.exports.ArrayExpression = {
|
|
|
63
68
|
maybe.print.newline(isNewLine && elements.length);
|
|
64
69
|
|
|
65
70
|
for (const [index, element] of elements.entries()) {
|
|
66
|
-
|
|
71
|
+
const is = isNewLine && isCurrentNewLine(element);
|
|
72
|
+
maybe.indent(is);
|
|
67
73
|
print(element);
|
|
68
|
-
maybe.print(
|
|
69
|
-
maybe.print.newline(
|
|
74
|
+
maybe.print(is, ',');
|
|
75
|
+
maybe.print.newline(is && !isNextObject(element));
|
|
76
|
+
maybe.print.space(element.isSpreadElement() && isNextObject(element));
|
|
70
77
|
|
|
71
|
-
if (!
|
|
78
|
+
if (!is && index < n) {
|
|
72
79
|
print(',');
|
|
73
80
|
print.space();
|
|
74
81
|
}
|
|
75
82
|
}
|
|
76
83
|
|
|
77
|
-
if (!isTwoLongStrings(elements))
|
|
84
|
+
if (!isTwoLongStrings(elements)) {
|
|
78
85
|
maybe.indent.dec(shouldIncreaseIndent);
|
|
86
|
+
}
|
|
79
87
|
|
|
80
88
|
const parentElements = path.parentPath.get('elements');
|
|
81
89
|
|
|
@@ -83,7 +91,7 @@ module.exports.ArrayExpression = {
|
|
|
83
91
|
indent.dec();
|
|
84
92
|
maybe.indent(elements.length && isNewLine);
|
|
85
93
|
indent.inc();
|
|
86
|
-
} else {
|
|
94
|
+
} else if (!isObjectExpression(elements.at(-1))) {
|
|
87
95
|
maybe.indent(elements.length && isNewLine);
|
|
88
96
|
}
|
|
89
97
|
|
|
@@ -84,6 +84,9 @@ module.exports.isNewlineBetweenElements = (path, {elements, maxElementsInOneLine
|
|
|
84
84
|
if (isTwoStringsDifferentLength(elements))
|
|
85
85
|
return ONE_LINE;
|
|
86
86
|
|
|
87
|
+
if (isShortTwoSimplesInsideObjectProperty(path, maxElementsInOneLine))
|
|
88
|
+
return ONE_LINE;
|
|
89
|
+
|
|
87
90
|
if (isStringAndArray(elements))
|
|
88
91
|
return ONE_LINE;
|
|
89
92
|
|
|
@@ -128,6 +131,30 @@ const isShortTwoSimplesInsideCall = (path, short) => {
|
|
|
128
131
|
return length < short;
|
|
129
132
|
};
|
|
130
133
|
|
|
134
|
+
const isShortTwoSimplesInsideObjectProperty = (path, short) => {
|
|
135
|
+
const {node, parentPath} = path;
|
|
136
|
+
|
|
137
|
+
const {elements} = node;
|
|
138
|
+
const {length} = elements;
|
|
139
|
+
const [a, b] = elements;
|
|
140
|
+
|
|
141
|
+
if (length > 2)
|
|
142
|
+
return false;
|
|
143
|
+
|
|
144
|
+
if (!parentPath.isObjectProperty())
|
|
145
|
+
return false;
|
|
146
|
+
|
|
147
|
+
if (!isStringLiteral(a) || !isStringLiteral(b))
|
|
148
|
+
return false;
|
|
149
|
+
|
|
150
|
+
if (looksLikeTuple(a, b))
|
|
151
|
+
return false;
|
|
152
|
+
|
|
153
|
+
return length < short;
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const looksLikeTuple = (a, b) => b.value.length + 5 <= a.value.length * 2;
|
|
157
|
+
|
|
131
158
|
function isOneSimple(path) {
|
|
132
159
|
const elements = path.get('elements');
|
|
133
160
|
|
|
@@ -226,6 +253,9 @@ function isIncreaseIndent(path) {
|
|
|
226
253
|
if (elements[0].isObjectExpression())
|
|
227
254
|
return true;
|
|
228
255
|
|
|
256
|
+
if (isSpreadElement(elements[1]))
|
|
257
|
+
return false;
|
|
258
|
+
|
|
229
259
|
return isStringAndObject(elements);
|
|
230
260
|
}
|
|
231
261
|
|
|
@@ -242,3 +272,10 @@ const isStringAndObject = (elements) => {
|
|
|
242
272
|
|
|
243
273
|
return isStringLiteral(first) && isObjectExpression(last);
|
|
244
274
|
};
|
|
275
|
+
|
|
276
|
+
module.exports.isCurrentNewLine = (path) => {
|
|
277
|
+
if (path.isSpreadElement())
|
|
278
|
+
return true;
|
|
279
|
+
|
|
280
|
+
return !path.isObjectExpression();
|
|
281
|
+
};
|
package/package.json
CHANGED