@putout/printer 8.18.0 → 8.20.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
+ 2024.04.23, v8.20.0
2
+
3
+ feature:
4
+ - 5a53f7e @putout/printer: ArrayExpression: array-object-identifier
5
+
6
+ 2024.04.19, v8.19.0
7
+
8
+ feature:
9
+ - 285747d @putout/printer: ArrayExpression: SpreadAfterObject
10
+
1
11
  2024.04.19, v8.18.0
2
12
 
3
13
  feature:
@@ -36,15 +36,25 @@ const isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
36
36
  const isObjectAfterSpread = (a) => isSpreadElement(a) && isNextObject(a) && !isPrevObject(a);
37
37
  const isObjectAfterIdentifier = (a) => isIdentifier(a) && isNextObject(a) && !isPrevObject(a);
38
38
  const isObjectAfterSimple = (a) => isObjectAfterSpread(a) || isObjectAfterIdentifier(a);
39
- const isNextSpread = (a) => a.getNextSibling().isSpreadElement();
40
- const isNextSpreadBetweenObjects = (a) => {
39
+ const isNextSimple = (a) => {
41
40
  const next = a.getNextSibling();
42
- const is = next.isSpreadElement();
41
+
42
+ if (next.isSpreadElement())
43
+ return true;
44
+
45
+ return next.isIdentifier();
46
+ };
47
+
48
+ const isNextSimpleBetweenObjects = (a) => {
49
+ const next = a.getNextSibling();
50
+ const is = next.isSpreadElement() || next.isIdentifier();
43
51
 
44
52
  if (!is)
45
53
  return true;
46
54
 
47
- return next.getNextSibling().isObjectExpression();
55
+ return next
56
+ .getNextSibling()
57
+ .isObjectExpression();
48
58
  };
49
59
 
50
60
  const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
@@ -96,7 +106,7 @@ module.exports.ArrayExpression = {
96
106
  for (const [index, element] of elements.entries()) {
97
107
  const is = isNewLine && isCurrentNewLine(element);
98
108
 
99
- if (index && isSpreadElement(element) && !isNextSpread(element) && !isNextObject(element))
109
+ if (isSimpleAfterObject(element))
100
110
  print.newline();
101
111
 
102
112
  maybe.indent(is);
@@ -111,7 +121,8 @@ module.exports.ArrayExpression = {
111
121
  if (!is && index < n) {
112
122
  print(',');
113
123
 
114
- if (isNextSpreadBetweenObjects(element) || !(element.isObjectExpression() && isNextSpread(element)))
124
+ if (isNextSimpleBetweenObjects(element) || !(element.isObjectExpression() && isNextSimple(element)))
125
+ //if (!(element.isObjectExpression() && isNextSimple(element)))
115
126
  print.space();
116
127
  }
117
128
  }
@@ -160,3 +171,16 @@ module.exports.ArrayExpression = {
160
171
  indent.inc();
161
172
  },
162
173
  };
174
+
175
+ function isSimpleAfterObject(path) {
176
+ if (!isSpreadElement(path) && !isIdentifier(path))
177
+ return;
178
+
179
+ const prev = path.getPrevSibling();
180
+ const next = path.getNextSibling();
181
+
182
+ if (next.isObjectExpression())
183
+ return false;
184
+
185
+ return prev.isObjectExpression();
186
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.18.0",
3
+ "version": "8.20.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",