@putout/printer 1.148.1 → 1.150.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.09, v1.150.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- c5b6238 @putout/printer: ArrayExpression: Tuple: two strings used as argument
|
|
5
|
+
|
|
6
|
+
2023.06.09, v1.149.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 35ec229 @putout/printer: ArrayExpression: plugins: couple lines
|
|
10
|
+
|
|
1
11
|
2023.06.08, v1.148.1
|
|
2
12
|
|
|
3
13
|
feature:
|
package/lib/tokenize/expressions/{array-expression.js → array-expression/array-expression.js}
RENAMED
|
@@ -21,10 +21,13 @@ const {
|
|
|
21
21
|
isStringAndIdentifier,
|
|
22
22
|
isIdentifierAndString,
|
|
23
23
|
isStringAndMember,
|
|
24
|
-
} = require('
|
|
24
|
+
} = require('../../is');
|
|
25
|
+
const MAX_ARRAY_ELEMENTS_WHEN_USED_AS_ARGUMENT = 4;
|
|
25
26
|
|
|
26
27
|
const isForOf = ({parentPath}) => parentPath.isForOfStatement();
|
|
27
28
|
|
|
29
|
+
const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
|
|
30
|
+
|
|
28
31
|
const isStringAndArray = ([a, b]) => {
|
|
29
32
|
if (!isStringLiteral(a))
|
|
30
33
|
return false;
|
|
@@ -34,7 +37,22 @@ const isStringAndArray = ([a, b]) => {
|
|
|
34
37
|
|
|
35
38
|
return !isStringAndIdentifier(b.node.elements);
|
|
36
39
|
};
|
|
40
|
+
|
|
37
41
|
const isStringAndString = ([a, b]) => isStringLiteral(a) && isStringLiteral(b);
|
|
42
|
+
const isShortTwoSimplesInsideCall = (path, short) => {
|
|
43
|
+
const {node, parentPath} = path;
|
|
44
|
+
const {elements} = node;
|
|
45
|
+
const {length} = elements;
|
|
46
|
+
const [a, b] = elements;
|
|
47
|
+
|
|
48
|
+
if (!parentPath.isCallExpression())
|
|
49
|
+
return false;
|
|
50
|
+
|
|
51
|
+
if (!isSimple(a) || !isSimple(b))
|
|
52
|
+
return false;
|
|
53
|
+
|
|
54
|
+
return length < short;
|
|
55
|
+
};
|
|
38
56
|
const isIdentifierAndIdentifier = ([a, b]) => isIdentifier(a) && isIdentifier(b);
|
|
39
57
|
const isInsideArray = (path) => path.parentPath.isArrayExpression();
|
|
40
58
|
|
|
@@ -48,7 +66,6 @@ const isSimpleAndCall = ([a, b]) => {
|
|
|
48
66
|
const isBooleanAndSimple = ([a, b]) => isBooleanLiteral(a) && isSimple(b);
|
|
49
67
|
const isNullAndSimple = ([a, b]) => isNullLiteral(a) && isSimple(b);
|
|
50
68
|
const isSimpleAndObject = ([a, b]) => isSimple(a) && isObjectExpression(b);
|
|
51
|
-
|
|
52
69
|
const isStringAndObject = (elements) => {
|
|
53
70
|
const first = elements.at(0);
|
|
54
71
|
const last = elements.at(-1);
|
|
@@ -79,7 +96,7 @@ module.exports.ArrayExpression = {
|
|
|
79
96
|
if (isCoupleLines(parentPath))
|
|
80
97
|
return false;
|
|
81
98
|
|
|
82
|
-
if (isStringAndIdentifier(elements))
|
|
99
|
+
if (isStringAndIdentifier(elements) && isInsideOneElementArray(path))
|
|
83
100
|
return true;
|
|
84
101
|
|
|
85
102
|
return isIdentifierAndIdentifier(elements);
|
|
@@ -141,7 +158,7 @@ module.exports.ArrayExpression = {
|
|
|
141
158
|
if (isCoupleLines(parentPath))
|
|
142
159
|
return false;
|
|
143
160
|
|
|
144
|
-
if (isStringAndIdentifier(elements))
|
|
161
|
+
if (isStringAndIdentifier(elements) && isInsideOneElementArray(path))
|
|
145
162
|
return true;
|
|
146
163
|
|
|
147
164
|
return isIdentifierAndIdentifier(elements);
|
|
@@ -162,16 +179,8 @@ function isNumbers(elements) {
|
|
|
162
179
|
return false;
|
|
163
180
|
}
|
|
164
181
|
|
|
165
|
-
function isLastArg(
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (!parentPath.isCallExpression())
|
|
169
|
-
return true;
|
|
170
|
-
|
|
171
|
-
const args = parentPath.get('arguments');
|
|
172
|
-
const n = args.length - 1;
|
|
173
|
-
|
|
174
|
-
return path === args[n];
|
|
182
|
+
function isLastArg({parentPath}) {
|
|
183
|
+
return !parentPath.isCallExpression();
|
|
175
184
|
}
|
|
176
185
|
|
|
177
186
|
function isParentProperty(path) {
|
|
@@ -270,6 +279,9 @@ function isNewlineBetweenElements(path, {elements}) {
|
|
|
270
279
|
if (isSimpleAndCall(elements))
|
|
271
280
|
return false;
|
|
272
281
|
|
|
282
|
+
if (isShortTwoSimplesInsideCall(path, MAX_ARRAY_ELEMENTS_WHEN_USED_AS_ARGUMENT))
|
|
283
|
+
return false;
|
|
284
|
+
|
|
273
285
|
if (isTwoStringsDifferentLength(elements))
|
|
274
286
|
return false;
|
|
275
287
|
|
|
@@ -338,3 +350,4 @@ const isOneElementCall = (path, {elements}) => {
|
|
|
338
350
|
|
|
339
351
|
return !isCallExpression(elements[0]);
|
|
340
352
|
};
|
|
353
|
+
|
|
@@ -28,7 +28,7 @@ const {
|
|
|
28
28
|
} = require('./class-property');
|
|
29
29
|
|
|
30
30
|
const {AssignmentExpression} = require('./assignment-expression');
|
|
31
|
-
const {ArrayExpression} = require('./array-expression');
|
|
31
|
+
const {ArrayExpression} = require('./array-expression/array-expression');
|
|
32
32
|
const {ArrayPattern} = require('./array-pattern');
|
|
33
33
|
const {AssignmentPattern} = require('./assignment-pattern');
|
|
34
34
|
const {RestElement} = require('./rest-element');
|
package/package.json
CHANGED