@putout/printer 2.10.0 → 2.12.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 +11 -0
- package/lib/tokenize/comments.js +1 -1
- package/lib/tokenize/expressions/array-expression/array-expression.js +6 -251
- package/lib/tokenize/expressions/array-expression/new-line.js +239 -0
- package/lib/tokenize/is.js +17 -1
- package/lib/tokenize/statements/block-statement/block-statement.js +1 -3
- package/lib/tokenize/typescript/ts-declare-function.js +3 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.06.13, v2.12.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- a264001 @putout/printer: ArrayExpression: newline
|
|
5
|
+
- cbe69f6 @putout/printer: BlockStatement
|
|
6
|
+
|
|
7
|
+
2023.06.13, v2.11.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- e7a9a98 @putout/printer: TSDeclare: add support of declare
|
|
11
|
+
|
|
1
12
|
2023.06.13, v2.10.0
|
|
2
13
|
|
|
3
14
|
feature:
|
package/lib/tokenize/comments.js
CHANGED
|
@@ -104,7 +104,7 @@ module.exports.parseComments = (path, {write}, semantics) => {
|
|
|
104
104
|
};
|
|
105
105
|
|
|
106
106
|
function isSameLine(path, loc) {
|
|
107
|
-
return path.node.loc
|
|
107
|
+
return path.node.loc?.start.line === loc.start.line || path.node.loc?.end.line === loc.end.line;
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
function maybeInsideFn(insideFn, {print, indent}) {
|
|
@@ -1,84 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {round} = Math;
|
|
4
|
-
|
|
5
|
-
const {
|
|
6
|
-
isObjectProperty,
|
|
7
|
-
isStringLiteral,
|
|
8
|
-
isArrayExpression,
|
|
9
|
-
isIdentifier,
|
|
10
|
-
isCallExpression,
|
|
11
|
-
isBooleanLiteral,
|
|
12
|
-
isNullLiteral,
|
|
13
|
-
isObjectExpression,
|
|
14
|
-
isAwaitExpression,
|
|
15
|
-
} = require('@babel/types');
|
|
16
|
-
|
|
17
|
-
const {isSimple} = require('@putout/operate');
|
|
18
|
-
|
|
19
3
|
const {
|
|
20
4
|
isCoupleLines,
|
|
21
5
|
isStringAndIdentifier,
|
|
22
|
-
|
|
23
|
-
|
|
6
|
+
isIdentifierAndIdentifier,
|
|
7
|
+
isStringAndArray,
|
|
24
8
|
} = require('../../is');
|
|
25
9
|
|
|
26
|
-
const
|
|
10
|
+
const {
|
|
11
|
+
isNewlineBetweenElements,
|
|
12
|
+
isIncreaseIndent,
|
|
13
|
+
} = require('./new-line');
|
|
27
14
|
|
|
28
15
|
const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
|
|
29
|
-
|
|
30
|
-
const isStringAndArray = ([a, b]) => {
|
|
31
|
-
if (!isStringLiteral(a))
|
|
32
|
-
return false;
|
|
33
|
-
|
|
34
|
-
if (!isArrayExpression(b))
|
|
35
|
-
return false;
|
|
36
|
-
|
|
37
|
-
return !isStringAndIdentifier(b.node.elements);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
const isStringAndString = ([a, b]) => isStringLiteral(a) && isStringLiteral(b);
|
|
41
|
-
|
|
42
|
-
const isShortTwoSimplesInsideCall = (path, short) => {
|
|
43
|
-
const {
|
|
44
|
-
node,
|
|
45
|
-
parentPath,
|
|
46
|
-
} = path;
|
|
47
|
-
|
|
48
|
-
const {elements} = node;
|
|
49
|
-
const {length} = elements;
|
|
50
|
-
const [a, b] = elements;
|
|
51
|
-
|
|
52
|
-
if (!parentPath.isCallExpression())
|
|
53
|
-
return false;
|
|
54
|
-
|
|
55
|
-
if (!isStringLiteral(a) || !isStringLiteral(b))
|
|
56
|
-
return false;
|
|
57
|
-
|
|
58
|
-
return length < short;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
const isIdentifierAndIdentifier = ([a, b]) => isIdentifier(a) && isIdentifier(b);
|
|
62
16
|
const isInsideArray = (path) => path.parentPath.isArrayExpression();
|
|
63
17
|
|
|
64
|
-
const isSimpleAndCall = ([a, b]) => {
|
|
65
|
-
if (!isSimple(a))
|
|
66
|
-
return;
|
|
67
|
-
|
|
68
|
-
return isCallExpression(b) || isAwaitExpression(b);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
const isBooleanAndSimple = ([a, b]) => isBooleanLiteral(a) && isSimple(b);
|
|
72
|
-
const isNullAndSimple = ([a, b]) => isNullLiteral(a) && isSimple(b);
|
|
73
|
-
const isSimpleAndObject = ([a, b]) => isSimple(a) && isObjectExpression(b);
|
|
74
|
-
|
|
75
|
-
const isStringAndObject = (elements) => {
|
|
76
|
-
const first = elements.at(0);
|
|
77
|
-
const last = elements.at(-1);
|
|
78
|
-
|
|
79
|
-
return isStringLiteral(first) && isObjectExpression(last);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
18
|
const isTwoLongStrings = ([a, b]) => {
|
|
83
19
|
const LONG_STRING = 20;
|
|
84
20
|
|
|
@@ -177,184 +113,3 @@ module.exports.ArrayExpression = {
|
|
|
177
113
|
indent.inc();
|
|
178
114
|
},
|
|
179
115
|
};
|
|
180
|
-
|
|
181
|
-
function isNumbers(elements) {
|
|
182
|
-
for (const element of elements) {
|
|
183
|
-
if (element.isNumericLiteral())
|
|
184
|
-
return true;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function isLastArg({parentPath}) {
|
|
191
|
-
return !parentPath.isCallExpression();
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function isParentProperty(path) {
|
|
195
|
-
return path.find(isObjectProperty);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
function isIncreaseIndent(path) {
|
|
199
|
-
const elements = path.get('elements');
|
|
200
|
-
|
|
201
|
-
if (!elements.length)
|
|
202
|
-
return false;
|
|
203
|
-
|
|
204
|
-
if (isInsideCallLoop(path))
|
|
205
|
-
return false;
|
|
206
|
-
|
|
207
|
-
if (elements[0].isObjectExpression())
|
|
208
|
-
return true;
|
|
209
|
-
|
|
210
|
-
if (isStringAndObject(elements))
|
|
211
|
-
return true;
|
|
212
|
-
|
|
213
|
-
return false;
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
function tooLong(path) {
|
|
217
|
-
const elements = path.get('elements');
|
|
218
|
-
|
|
219
|
-
if (elements.length < 2)
|
|
220
|
-
return false;
|
|
221
|
-
|
|
222
|
-
for (const el of path.get('elements')) {
|
|
223
|
-
if (el.isStringLiteral() && el.node.value.length > 4)
|
|
224
|
-
return true;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function isCallInsideArrow(path) {
|
|
231
|
-
const {parentPath} = path;
|
|
232
|
-
|
|
233
|
-
if (!parentPath.isCallExpression())
|
|
234
|
-
return false;
|
|
235
|
-
|
|
236
|
-
if (!parentPath.parentPath.isFunction())
|
|
237
|
-
return false;
|
|
238
|
-
|
|
239
|
-
return path.node.elements.length < 4;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
function isOneSimple(path) {
|
|
243
|
-
const elements = path.get('elements');
|
|
244
|
-
|
|
245
|
-
if (elements.length !== 1)
|
|
246
|
-
return false;
|
|
247
|
-
|
|
248
|
-
const [first] = elements;
|
|
249
|
-
|
|
250
|
-
if (first.isIdentifier() && first.node.name.length < 5)
|
|
251
|
-
return true;
|
|
252
|
-
|
|
253
|
-
if (first.isCallExpression())
|
|
254
|
-
return false;
|
|
255
|
-
|
|
256
|
-
return first.isMemberExpression();
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
function isNewlineBetweenElements(path, {elements, maxElementsInOneLine}) {
|
|
260
|
-
if (elements.length > 3 && !isObjectExpression(elements[0]))
|
|
261
|
-
return true;
|
|
262
|
-
|
|
263
|
-
if (isOneSimple(path))
|
|
264
|
-
return false;
|
|
265
|
-
|
|
266
|
-
if (elements.length === 2 && isIdentifierAndIdentifier(elements))
|
|
267
|
-
return false;
|
|
268
|
-
|
|
269
|
-
if (isCallInsideArrow(path))
|
|
270
|
-
return false;
|
|
271
|
-
|
|
272
|
-
if (isOneElementCall(path, {elements}))
|
|
273
|
-
return false;
|
|
274
|
-
|
|
275
|
-
if (isIncreaseIndent(path))
|
|
276
|
-
return false;
|
|
277
|
-
|
|
278
|
-
if (isInsideLoop(path))
|
|
279
|
-
return false;
|
|
280
|
-
|
|
281
|
-
if (isBooleanAndSimple(elements))
|
|
282
|
-
return false;
|
|
283
|
-
|
|
284
|
-
if (isNullAndSimple(elements))
|
|
285
|
-
return false;
|
|
286
|
-
|
|
287
|
-
if (isSimpleAndCall(elements))
|
|
288
|
-
return false;
|
|
289
|
-
|
|
290
|
-
if (isShortTwoSimplesInsideCall(path, maxElementsInOneLine))
|
|
291
|
-
return false;
|
|
292
|
-
|
|
293
|
-
if (isTwoStringsDifferentLength(elements))
|
|
294
|
-
return false;
|
|
295
|
-
|
|
296
|
-
if (isStringAndArray(elements))
|
|
297
|
-
return false;
|
|
298
|
-
|
|
299
|
-
if (isStringAndMember(elements))
|
|
300
|
-
return false;
|
|
301
|
-
|
|
302
|
-
if (isStringAndIdentifier(elements))
|
|
303
|
-
return false;
|
|
304
|
-
|
|
305
|
-
if (isIdentifierAndString(elements))
|
|
306
|
-
return false;
|
|
307
|
-
|
|
308
|
-
if (isSimpleAndObject(elements))
|
|
309
|
-
return false;
|
|
310
|
-
|
|
311
|
-
if (isStringAndString(elements) && path.parentPath.isArrayExpression() && isArrayExpression(path.parentPath.node.elements[0]))
|
|
312
|
-
return false;
|
|
313
|
-
|
|
314
|
-
if (tooLong(path) || isCoupleLines(path) || !isNumbers(elements) && !isForOf(path) && isLastArg(path) && !isParentProperty(path))
|
|
315
|
-
return true;
|
|
316
|
-
|
|
317
|
-
return false;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
function isTwoStringsDifferentLength(strings) {
|
|
321
|
-
const [a, b] = strings;
|
|
322
|
-
|
|
323
|
-
if (strings.length > 2)
|
|
324
|
-
return false;
|
|
325
|
-
|
|
326
|
-
if (!a?.isStringLiteral() || !b?.isStringLiteral())
|
|
327
|
-
return false;
|
|
328
|
-
|
|
329
|
-
const aLength = a.node.value.length;
|
|
330
|
-
const bLength = b.node.value.length;
|
|
331
|
-
|
|
332
|
-
return round(bLength / aLength) > 2;
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function isInsideCallLoop(path) {
|
|
336
|
-
if (!path.parentPath.isCallExpression())
|
|
337
|
-
return false;
|
|
338
|
-
|
|
339
|
-
if (!path.parentPath.parentPath.isForOfStatement())
|
|
340
|
-
return false;
|
|
341
|
-
|
|
342
|
-
return true;
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
function isInsideLoop(path) {
|
|
346
|
-
if (!path.parentPath.isForOfStatement())
|
|
347
|
-
return false;
|
|
348
|
-
|
|
349
|
-
return true;
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
const isOneElementCall = (path, {elements}) => {
|
|
353
|
-
if (!path.parentPath.isCallExpression())
|
|
354
|
-
return false;
|
|
355
|
-
|
|
356
|
-
if (elements.length !== 1)
|
|
357
|
-
return false;
|
|
358
|
-
|
|
359
|
-
return !isCallExpression(elements[0]);
|
|
360
|
-
};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {isSimple} = require('@putout/operate');
|
|
4
|
+
const {
|
|
5
|
+
isObjectExpression,
|
|
6
|
+
isArrayExpression,
|
|
7
|
+
isObjectProperty,
|
|
8
|
+
isCallExpression,
|
|
9
|
+
isAwaitExpression,
|
|
10
|
+
isBooleanLiteral,
|
|
11
|
+
isNullLiteral,
|
|
12
|
+
isStringLiteral,
|
|
13
|
+
|
|
14
|
+
} = require('@babel/types');
|
|
15
|
+
const {
|
|
16
|
+
isStringAndMember,
|
|
17
|
+
isStringAndIdentifier,
|
|
18
|
+
isIdentifierAndString,
|
|
19
|
+
isCoupleLines,
|
|
20
|
+
isStringAndArray,
|
|
21
|
+
isIdentifierAndIdentifier,
|
|
22
|
+
|
|
23
|
+
} = require('../../is');
|
|
24
|
+
|
|
25
|
+
const {round} = Math;
|
|
26
|
+
|
|
27
|
+
const isSimpleAndCall = ([a, b]) => {
|
|
28
|
+
if (!isSimple(a))
|
|
29
|
+
return;
|
|
30
|
+
|
|
31
|
+
return isCallExpression(b) || isAwaitExpression(b);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const isBooleanAndSimple = ([a, b]) => isBooleanLiteral(a) && isSimple(b);
|
|
35
|
+
const isNullAndSimple = ([a, b]) => isNullLiteral(a) && isSimple(b);
|
|
36
|
+
const isSimpleAndObject = ([a, b]) => isSimple(a) && isObjectExpression(b);
|
|
37
|
+
const ONE_LINE = false;
|
|
38
|
+
const MULTI_LINE = true;
|
|
39
|
+
|
|
40
|
+
module.exports.isNewlineBetweenElements = (path, {elements, maxElementsInOneLine}) => {
|
|
41
|
+
if (elements.length > 3 && !isObjectExpression(elements[0]))
|
|
42
|
+
return MULTI_LINE;
|
|
43
|
+
|
|
44
|
+
if (isOneSimple(path))
|
|
45
|
+
return ONE_LINE;
|
|
46
|
+
|
|
47
|
+
if (elements.length === 2 && isIdentifierAndIdentifier(elements))
|
|
48
|
+
return ONE_LINE;
|
|
49
|
+
|
|
50
|
+
if (isCallInsideArrow(path))
|
|
51
|
+
return ONE_LINE;
|
|
52
|
+
|
|
53
|
+
if (isIncreaseIndent(path))
|
|
54
|
+
return ONE_LINE;
|
|
55
|
+
|
|
56
|
+
if (isInsideLoop(path))
|
|
57
|
+
return ONE_LINE;
|
|
58
|
+
|
|
59
|
+
if (isBooleanAndSimple(elements))
|
|
60
|
+
return ONE_LINE;
|
|
61
|
+
|
|
62
|
+
if (isNullAndSimple(elements))
|
|
63
|
+
return ONE_LINE;
|
|
64
|
+
|
|
65
|
+
if (isSimpleAndCall(elements))
|
|
66
|
+
return ONE_LINE;
|
|
67
|
+
|
|
68
|
+
if (isShortTwoSimplesInsideCall(path, maxElementsInOneLine))
|
|
69
|
+
return ONE_LINE;
|
|
70
|
+
|
|
71
|
+
if (isTwoStringsDifferentLength(elements))
|
|
72
|
+
return ONE_LINE;
|
|
73
|
+
|
|
74
|
+
if (isStringAndArray(elements))
|
|
75
|
+
return ONE_LINE;
|
|
76
|
+
|
|
77
|
+
if (isStringAndMember(elements))
|
|
78
|
+
return ONE_LINE;
|
|
79
|
+
|
|
80
|
+
if (isStringAndIdentifier(elements))
|
|
81
|
+
return ONE_LINE;
|
|
82
|
+
|
|
83
|
+
if (isIdentifierAndString(elements))
|
|
84
|
+
return ONE_LINE;
|
|
85
|
+
|
|
86
|
+
if (isSimpleAndObject(elements))
|
|
87
|
+
return ONE_LINE;
|
|
88
|
+
|
|
89
|
+
if (isStringAndString(elements) && path.parentPath.isArrayExpression() && isArrayExpression(path.parentPath.node.elements[0]))
|
|
90
|
+
return ONE_LINE;
|
|
91
|
+
|
|
92
|
+
if (tooLong(path) || isCoupleLines(path) || !isNumbers(elements) && !isForOf(path) && isLastArg(path) && !isParentProperty(path))
|
|
93
|
+
return MULTI_LINE;
|
|
94
|
+
|
|
95
|
+
return ONE_LINE;
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const isForOf = ({parentPath}) => parentPath.isForOfStatement();
|
|
99
|
+
|
|
100
|
+
const isStringAndString = ([a, b]) => isStringLiteral(a) && isStringLiteral(b);
|
|
101
|
+
|
|
102
|
+
const isShortTwoSimplesInsideCall = (path, short) => {
|
|
103
|
+
const {
|
|
104
|
+
node,
|
|
105
|
+
parentPath,
|
|
106
|
+
} = path;
|
|
107
|
+
|
|
108
|
+
const {elements} = node;
|
|
109
|
+
const {length} = elements;
|
|
110
|
+
const [a, b] = elements;
|
|
111
|
+
|
|
112
|
+
if (!parentPath.isCallExpression())
|
|
113
|
+
return false;
|
|
114
|
+
|
|
115
|
+
if (!isStringLiteral(a) || !isStringLiteral(b))
|
|
116
|
+
return false;
|
|
117
|
+
|
|
118
|
+
return length < short;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
function isOneSimple(path) {
|
|
122
|
+
const elements = path.get('elements');
|
|
123
|
+
|
|
124
|
+
if (elements.length !== 1)
|
|
125
|
+
return false;
|
|
126
|
+
|
|
127
|
+
const [first] = elements;
|
|
128
|
+
|
|
129
|
+
if (first.isIdentifier() && first.node.name.length < 5)
|
|
130
|
+
return true;
|
|
131
|
+
|
|
132
|
+
if (!first.isIdentifier() && isSimple(first))
|
|
133
|
+
return true;
|
|
134
|
+
|
|
135
|
+
if (first.isCallExpression())
|
|
136
|
+
return false;
|
|
137
|
+
|
|
138
|
+
return first.isMemberExpression();
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
function isTwoStringsDifferentLength(strings) {
|
|
142
|
+
const [a, b] = strings;
|
|
143
|
+
|
|
144
|
+
if (strings.length > 2)
|
|
145
|
+
return false;
|
|
146
|
+
|
|
147
|
+
if (!a?.isStringLiteral() || !b?.isStringLiteral())
|
|
148
|
+
return false;
|
|
149
|
+
|
|
150
|
+
const aLength = a.node.value.length;
|
|
151
|
+
const bLength = b.node.value.length;
|
|
152
|
+
|
|
153
|
+
return round(bLength / aLength) > 2;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function isInsideLoop(path) {
|
|
157
|
+
if (!path.parentPath.isForOfStatement())
|
|
158
|
+
return false;
|
|
159
|
+
|
|
160
|
+
return true;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
function tooLong(path) {
|
|
164
|
+
const elements = path.get('elements');
|
|
165
|
+
|
|
166
|
+
if (elements.length < 2)
|
|
167
|
+
return false;
|
|
168
|
+
|
|
169
|
+
for (const el of path.get('elements')) {
|
|
170
|
+
if (el.isStringLiteral() && el.node.value.length > 4)
|
|
171
|
+
return true;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function isCallInsideArrow(path) {
|
|
178
|
+
const {parentPath} = path;
|
|
179
|
+
|
|
180
|
+
if (!parentPath.isCallExpression())
|
|
181
|
+
return false;
|
|
182
|
+
|
|
183
|
+
if (!parentPath.parentPath.isFunction())
|
|
184
|
+
return false;
|
|
185
|
+
|
|
186
|
+
return path.node.elements.length < 4;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
function isNumbers(elements) {
|
|
190
|
+
for (const element of elements) {
|
|
191
|
+
if (element.isNumericLiteral())
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
return false;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function isLastArg({parentPath}) {
|
|
199
|
+
return !parentPath.isCallExpression();
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function isParentProperty(path) {
|
|
203
|
+
return path.find(isObjectProperty);
|
|
204
|
+
}
|
|
205
|
+
module.exports.isIncreaseIndent = isIncreaseIndent;
|
|
206
|
+
function isIncreaseIndent(path) {
|
|
207
|
+
const elements = path.get('elements');
|
|
208
|
+
|
|
209
|
+
if (!elements.length)
|
|
210
|
+
return false;
|
|
211
|
+
|
|
212
|
+
if (isInsideCallLoop(path))
|
|
213
|
+
return false;
|
|
214
|
+
|
|
215
|
+
if (elements[0].isObjectExpression())
|
|
216
|
+
return true;
|
|
217
|
+
|
|
218
|
+
if (isStringAndObject(elements))
|
|
219
|
+
return true;
|
|
220
|
+
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function isInsideCallLoop(path) {
|
|
225
|
+
if (!path.parentPath.isCallExpression())
|
|
226
|
+
return false;
|
|
227
|
+
|
|
228
|
+
if (!path.parentPath.parentPath.isForOfStatement())
|
|
229
|
+
return false;
|
|
230
|
+
|
|
231
|
+
return true;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
const isStringAndObject = (elements) => {
|
|
235
|
+
const first = elements.at(0);
|
|
236
|
+
const last = elements.at(-1);
|
|
237
|
+
|
|
238
|
+
return isStringLiteral(first) && isObjectExpression(last);
|
|
239
|
+
};
|
package/lib/tokenize/is.js
CHANGED
|
@@ -8,6 +8,8 @@ const {
|
|
|
8
8
|
isForOfStatement,
|
|
9
9
|
isVariableDeclaration,
|
|
10
10
|
isMemberExpression,
|
|
11
|
+
isArrayExpression,
|
|
12
|
+
|
|
11
13
|
} = require('@babel/types');
|
|
12
14
|
|
|
13
15
|
const isParentProgram = (path) => path.parentPath?.isProgram();
|
|
@@ -43,9 +45,23 @@ function isCoupleLines(path) {
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
module.exports.exists = (a) => a.node;
|
|
46
|
-
module.exports.isStringAndIdentifier =
|
|
48
|
+
module.exports.isStringAndIdentifier = isStringAndIdentifier;
|
|
49
|
+
function isStringAndIdentifier([a, b]) {
|
|
50
|
+
return isStringLiteral(a) && isIdentifier(b);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports.isIdentifierAndIdentifier = ([a, b]) => isIdentifier(a) && isIdentifier(b);
|
|
47
54
|
module.exports.isStringAndMember = ([a, b]) => isStringLiteral(a) && isMemberExpression(b);
|
|
48
55
|
module.exports.isIdentifierAndString = ([a, b]) => isIdentifier(a) && isStringLiteral(b);
|
|
56
|
+
module.exports.isStringAndArray = ([a, b]) => {
|
|
57
|
+
if (!isStringLiteral(a))
|
|
58
|
+
return false;
|
|
59
|
+
|
|
60
|
+
if (!isArrayExpression(b))
|
|
61
|
+
return false;
|
|
62
|
+
|
|
63
|
+
return !isStringAndIdentifier(b.node.elements);
|
|
64
|
+
};
|
|
49
65
|
|
|
50
66
|
const isIfOrStatement = (a) => isIfStatement(a) || isStatement(a);
|
|
51
67
|
const isForOfOrStatement = (a) => isForOfStatement(a) || isStatement(a);
|
package/package.json
CHANGED