@putout/printer 1.133.1 → 1.134.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
|
@@ -9,6 +9,7 @@ const {
|
|
|
9
9
|
isIdentifier,
|
|
10
10
|
isCallExpression,
|
|
11
11
|
isBooleanLiteral,
|
|
12
|
+
isNullLiteral,
|
|
12
13
|
isObjectExpression,
|
|
13
14
|
} = require('@babel/types');
|
|
14
15
|
|
|
@@ -20,13 +21,21 @@ const {
|
|
|
20
21
|
} = require('../is');
|
|
21
22
|
|
|
22
23
|
const isForOf = ({parentPath}) => parentPath.isForOfStatement();
|
|
23
|
-
|
|
24
|
+
|
|
24
25
|
const isStringAndArray = ([a, b]) => isStringLiteral(a) && isArrayExpression(b);
|
|
25
26
|
const isStringAndString = ([a, b]) => isStringLiteral(a) && isStringLiteral(b);
|
|
26
27
|
const isIdentifierAndIdentifier = ([a, b]) => isIdentifier(a) && isIdentifier(b);
|
|
27
28
|
const isInsideArray = (path) => path.parentPath.isArrayExpression();
|
|
28
29
|
const isSimpleAndCall = ([a, b]) => isSimple(a) && isCallExpression(b);
|
|
29
30
|
const isBooleanAndSimple = ([a, b]) => isBooleanLiteral(a) && isSimple(b);
|
|
31
|
+
const isNullAndSimple = ([a, b]) => isNullLiteral(a) && isSimple(b);
|
|
32
|
+
|
|
33
|
+
const isStringAndObject = (elements) => {
|
|
34
|
+
const first = elements.at(0);
|
|
35
|
+
const last = elements.at(-1);
|
|
36
|
+
|
|
37
|
+
return isStringLiteral(first) && isObjectExpression(last);
|
|
38
|
+
};
|
|
30
39
|
|
|
31
40
|
const isTwoLongStrings = ([a, b]) => {
|
|
32
41
|
const LONG_STRING = 20;
|
|
@@ -61,12 +70,12 @@ module.exports.ArrayExpression = {
|
|
|
61
70
|
},
|
|
62
71
|
print(path, {print, maybe, indent}) {
|
|
63
72
|
const elements = path.get('elements');
|
|
64
|
-
const shouldIncreaseIndent = isIncreaseIndent(path);
|
|
73
|
+
const shouldIncreaseIndent = !isIncreaseIndent(path);
|
|
65
74
|
|
|
66
75
|
print('[');
|
|
67
76
|
|
|
68
77
|
if (!isTwoLongStrings(elements))
|
|
69
|
-
maybe.indent.inc(
|
|
78
|
+
maybe.indent.inc(shouldIncreaseIndent);
|
|
70
79
|
|
|
71
80
|
const isNewLine = isNewlineBetweenElements(path, {
|
|
72
81
|
elements,
|
|
@@ -89,7 +98,7 @@ module.exports.ArrayExpression = {
|
|
|
89
98
|
}
|
|
90
99
|
|
|
91
100
|
if (!isTwoLongStrings(elements))
|
|
92
|
-
maybe.indent.dec(
|
|
101
|
+
maybe.indent.dec(shouldIncreaseIndent);
|
|
93
102
|
|
|
94
103
|
const parentElements = path.parentPath.get('elements');
|
|
95
104
|
|
|
@@ -162,7 +171,7 @@ function isIncreaseIndent(path) {
|
|
|
162
171
|
if (elements[0].isObjectExpression())
|
|
163
172
|
return true;
|
|
164
173
|
|
|
165
|
-
if (elements
|
|
174
|
+
if (isStringAndObject(elements))
|
|
166
175
|
return true;
|
|
167
176
|
|
|
168
177
|
return false;
|
|
@@ -236,6 +245,9 @@ function isNewlineBetweenElements(path, {elements}) {
|
|
|
236
245
|
if (isBooleanAndSimple(elements))
|
|
237
246
|
return false;
|
|
238
247
|
|
|
248
|
+
if (isNullAndSimple(elements))
|
|
249
|
+
return false;
|
|
250
|
+
|
|
239
251
|
if (isSimpleAndCall(elements))
|
|
240
252
|
return false;
|
|
241
253
|
|
package/package.json
CHANGED