@putout/printer 6.4.1 → 6.6.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.11.28, v6.6.0
2
+
3
+ fix:
4
+ - 954cda8 @putout/printer: ArrayExpression: array inside array
5
+
6
+ 2023.11.28, v6.5.0
7
+
8
+ feature:
9
+ - afa7f81 @putout/printer: ArrayExpression: array inside array
10
+
1
11
  2023.11.16, v6.4.1
2
12
 
3
13
  fix:
@@ -14,12 +14,19 @@ const {
14
14
  isCurrentNewLine,
15
15
  } = require('./new-line');
16
16
 
17
+ const {types} = require('@putout/babel');
17
18
  const {
18
19
  isObjectExpression,
19
20
  isStringLiteral,
20
- } = require('@putout/babel').types;
21
+ } = types;
21
22
 
22
23
  const isNextObject = (a) => a.getNextSibling().isObjectExpression();
24
+ const isArrayInsideArray = (path) => {
25
+ if (!path.isArrayExpression() || !path.parentPath.isArrayExpression())
26
+ return false;
27
+
28
+ return path === path.parentPath.get('elements').at(-1);
29
+ };
23
30
 
24
31
  const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
25
32
  const isInsideArray = (path) => path.parentPath.isArrayExpression();
@@ -63,7 +70,7 @@ module.exports.ArrayExpression = {
63
70
 
64
71
  print('[');
65
72
 
66
- const indented = !isTwoLongStrings(elements) || !isInsideArray(path) && isIndented(elements[0]);
73
+ const indented = !isArrayInsideArray(path) && (!isTwoLongStrings(elements) || !isInsideArray(path) && isIndented(elements[0]));
67
74
 
68
75
  if (indented)
69
76
  maybe.indent.inc(shouldIncreaseIndent);
@@ -103,7 +110,7 @@ module.exports.ArrayExpression = {
103
110
  indent.dec();
104
111
  maybe.indent(elements.length && isNewLine);
105
112
  indent.inc();
106
- } else if (!isObjectExpression(elements.at(-1))) {
113
+ } else if (!isArrayInsideArray(path) && !isObjectExpression(elements.at(-1))) {
107
114
  maybe.indent(elements.length && isNewLine);
108
115
  }
109
116
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "6.4.1",
3
+ "version": "6.6.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",