@putout/printer 8.46.0 → 8.47.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
+ 2024.06.06, v8.47.0
2
+
3
+ feature:
4
+ - 53c7909 @putout/printer: ArrayExpression: comma (coderaiser/putout#206)
5
+
1
6
  2024.06.06, v8.46.0
2
7
 
3
8
  feature:
@@ -6,7 +6,7 @@ const {
6
6
  isStringAndIdentifier,
7
7
  isIdentifierAndIdentifier,
8
8
  isStringAndArray,
9
- isSimpleAndEmptyObject,
9
+ isSimpleAndNotEmptyObject,
10
10
  isNextObject,
11
11
  } = require('../../is');
12
12
 
@@ -29,6 +29,7 @@ const {
29
29
  isSpreadElement,
30
30
  isStringLiteral,
31
31
  isIdentifier,
32
+ isFunction,
32
33
  } = types;
33
34
 
34
35
  const isNextString = (path) => isStringLiteral(path.getNextSibling());
@@ -44,6 +45,15 @@ const isSpreadBeforeObject = (a) => {
44
45
  if (!prev.isSpreadElement())
45
46
  return false;
46
47
 
48
+ const argCall = prev.get('argument');
49
+
50
+ if (argCall.isCallExpression()) {
51
+ const [first] = argCall.get('arguments');
52
+
53
+ if (isFunction(first))
54
+ return false;
55
+ }
56
+
47
57
  if (prev.getPrevSibling().isObjectExpression())
48
58
  return false;
49
59
 
@@ -158,7 +168,7 @@ module.exports.ArrayExpression = {
158
168
  maybe.indent(elements.length && isNewLine);
159
169
  }
160
170
 
161
- if (isSimpleAndEmptyObject(elements) && !isSpreadElement(elements.at(-1))) {
171
+ if (isSimpleAndNotEmptyObject(elements) && !isSpreadElement(elements.at(-1))) {
162
172
  print(',');
163
173
  print.breakline();
164
174
  }
@@ -21,7 +21,7 @@ const {
21
21
  isCoupleLines,
22
22
  isStringAndArray,
23
23
  isIdentifierAndIdentifier,
24
- isSimpleAndEmptyObject,
24
+ isSimpleAndNotEmptyObject,
25
25
  } = require('../../is');
26
26
 
27
27
  const {round} = Math;
@@ -62,7 +62,7 @@ module.exports.isMultiLine = (path, {elements, maxElementsInOneLine}) => {
62
62
  if (elements.length > 3 && !isObjectExpression(elements[0]))
63
63
  return MULTI_LINE;
64
64
 
65
- if (isSimpleAndEmptyObject(elements))
65
+ if (isSimpleAndNotEmptyObject(elements))
66
66
  return MULTI_LINE;
67
67
 
68
68
  if (isOneSimple(path))
@@ -67,7 +67,7 @@ function isStringAndIdentifier([a, b]) {
67
67
  return isStringLiteral(a) && isIdentifier(b);
68
68
  }
69
69
 
70
- module.exports.isSimpleAndEmptyObject = ([a, b]) => {
70
+ module.exports.isSimpleAndNotEmptyObject = ([a, b]) => {
71
71
  if (!isIdentifier(a) && !isSpreadElement(a) && !isArrayExpression(a))
72
72
  return false;
73
73
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.46.0",
3
+ "version": "8.47.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",