@putout/printer 1.149.0 → 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,8 @@
1
+ 2023.06.09, v1.150.0
2
+
3
+ feature:
4
+ - c5b6238 @putout/printer: ArrayExpression: Tuple: two strings used as argument
5
+
1
6
  2023.06.09, v1.149.0
2
7
 
3
8
  feature:
@@ -21,7 +21,8 @@ const {
21
21
  isStringAndIdentifier,
22
22
  isIdentifierAndString,
23
23
  isStringAndMember,
24
- } = require('../is');
24
+ } = require('../../is');
25
+ const MAX_ARRAY_ELEMENTS_WHEN_USED_AS_ARGUMENT = 4;
25
26
 
26
27
  const isForOf = ({parentPath}) => parentPath.isForOfStatement();
27
28
 
@@ -38,6 +39,20 @@ const isStringAndArray = ([a, b]) => {
38
39
  };
39
40
 
40
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
+ };
41
56
  const isIdentifierAndIdentifier = ([a, b]) => isIdentifier(a) && isIdentifier(b);
42
57
  const isInsideArray = (path) => path.parentPath.isArrayExpression();
43
58
 
@@ -51,7 +66,6 @@ const isSimpleAndCall = ([a, b]) => {
51
66
  const isBooleanAndSimple = ([a, b]) => isBooleanLiteral(a) && isSimple(b);
52
67
  const isNullAndSimple = ([a, b]) => isNullLiteral(a) && isSimple(b);
53
68
  const isSimpleAndObject = ([a, b]) => isSimple(a) && isObjectExpression(b);
54
-
55
69
  const isStringAndObject = (elements) => {
56
70
  const first = elements.at(0);
57
71
  const last = elements.at(-1);
@@ -165,16 +179,8 @@ function isNumbers(elements) {
165
179
  return false;
166
180
  }
167
181
 
168
- function isLastArg(path) {
169
- const {parentPath} = path;
170
-
171
- if (!parentPath.isCallExpression())
172
- return true;
173
-
174
- const args = parentPath.get('arguments');
175
- const n = args.length - 1;
176
-
177
- return path === args[n];
182
+ function isLastArg({parentPath}) {
183
+ return !parentPath.isCallExpression();
178
184
  }
179
185
 
180
186
  function isParentProperty(path) {
@@ -273,6 +279,9 @@ function isNewlineBetweenElements(path, {elements}) {
273
279
  if (isSimpleAndCall(elements))
274
280
  return false;
275
281
 
282
+ if (isShortTwoSimplesInsideCall(path, MAX_ARRAY_ELEMENTS_WHEN_USED_AS_ARGUMENT))
283
+ return false;
284
+
276
285
  if (isTwoStringsDifferentLength(elements))
277
286
  return false;
278
287
 
@@ -341,3 +350,4 @@ const isOneElementCall = (path, {elements}) => {
341
350
 
342
351
  return !isCallExpression(elements[0]);
343
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.149.0",
3
+ "version": "1.150.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",