@putout/printer 1.6.10 → 1.6.11

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.03.22, v1.6.11
2
+
3
+ feature:
4
+ - 552e272 @putout/printer: improve support of ArrayExpression
5
+
1
6
  2023.03.22, v1.6.10
2
7
 
3
8
  feature:
@@ -11,23 +11,20 @@ module.exports.ArrayExpression = (path, {print, maybe}) => {
11
11
  print('[');
12
12
  maybe.indent.inc(!elementIsObject);
13
13
 
14
- const isNewLine = !isNumbers(elements) && !isForOf(path) && isLastArg(path) && !isParentProperty(path);
14
+ const isNewLine = tooLong(path) || !isNumbers(elements) && !isForOf(path) && isLastArg(path) && !isParentProperty(path);
15
15
  const n = elements.length - 1;
16
16
 
17
17
  maybe.print(isNewLine && elements.length, '\n');
18
18
 
19
19
  for (const [index, element] of entries(elements)) {
20
20
  maybe.indent(isNewLine);
21
-
22
21
  print(element);
23
-
24
22
  maybe.print(isNewLine, ',\n');
25
23
  maybe.print(!isNewLine && index < n, ', ');
26
24
  }
27
25
 
28
26
  maybe.indent.dec(!elementIsObject);
29
27
  maybe.indent(elements.length && isNewLine);
30
-
31
28
  print(']');
32
29
  };
33
30
 
@@ -64,3 +61,17 @@ function isElementObject(path) {
64
61
 
65
62
  return elements[0].isObjectExpression();
66
63
  }
64
+
65
+ function tooLong(path) {
66
+ const elements = path.get('elements');
67
+
68
+ if (elements.length < 2)
69
+ return false;
70
+
71
+ for (const el of path.get('elements')) {
72
+ if (el.isStringLiteral() && el.node.value.length > 4)
73
+ return true;
74
+ }
75
+
76
+ return false;
77
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.6.10",
3
+ "version": "1.6.11",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",