@putout/printer 8.19.0 → 8.20.1

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.24, v8.20.1
2
+
3
+ feature:
4
+ - 4551754 @putout/printer: ArrayExpression: CallExpression, ObjectExpression
5
+
6
+ 2024.04.23, v8.20.0
7
+
8
+ feature:
9
+ - 5a53f7e @putout/printer: ArrayExpression: array-object-identifier
10
+
1
11
  2024.04.19, v8.19.0
2
12
 
3
13
  feature:
@@ -7,8 +7,6 @@ const {
7
7
  isIdentifierAndIdentifier,
8
8
  isStringAndArray,
9
9
  isSimpleAndEmptyObject,
10
- isNext,
11
-
12
10
  } = require('../../is');
13
11
 
14
12
  const {
@@ -38,11 +36,36 @@ const isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
38
36
  const isObjectAfterSpread = (a) => isSpreadElement(a) && isNextObject(a) && !isPrevObject(a);
39
37
  const isObjectAfterIdentifier = (a) => isIdentifier(a) && isNextObject(a) && !isPrevObject(a);
40
38
  const isObjectAfterSimple = (a) => isObjectAfterSpread(a) || isObjectAfterIdentifier(a);
41
- const isNextSpread = (a) => a.getNextSibling().isSpreadElement();
42
39
 
43
- const isNextSpreadBetweenObjects = (a) => {
40
+ const isSpreadBeforeObject = (a) => {
41
+ if (!a.isObjectExpression())
42
+ return false;
43
+
44
+ const prev = a.getPrevSibling();
45
+
46
+ if (!prev.isSpreadElement())
47
+ return false;
48
+
49
+ if (prev.getPrevSibling().isObjectExpression())
50
+ return false;
51
+
52
+ return prev
53
+ .get('argument')
54
+ .isCallExpression();
55
+ };
56
+
57
+ const isNextSimple = (a) => {
58
+ const next = a.getNextSibling();
59
+
60
+ if (next.isSpreadElement())
61
+ return true;
62
+
63
+ return next.isIdentifier();
64
+ };
65
+
66
+ const isNextSimpleBetweenObjects = (a) => {
44
67
  const next = a.getNextSibling();
45
- const is = next.isSpreadElement();
68
+ const is = next.isSpreadElement() || next.isIdentifier();
46
69
 
47
70
  if (!is)
48
71
  return true;
@@ -101,7 +124,7 @@ module.exports.ArrayExpression = {
101
124
  for (const [index, element] of elements.entries()) {
102
125
  const is = isNewLine && isCurrentNewLine(element);
103
126
 
104
- if (isSpreadAfterObject(element))
127
+ if (isSimpleAfterObject(element))
105
128
  print.newline();
106
129
 
107
130
  maybe.indent(is);
@@ -110,13 +133,13 @@ module.exports.ArrayExpression = {
110
133
  if (index < n || trailingComma)
111
134
  maybe.print(is, ',');
112
135
 
113
- maybe.print.newline(is && !isNextObject(element));
136
+ maybe.print.newline((is || isSpreadBeforeObject(element)) && !isNextObject(element));
114
137
  maybe.print.space(is && isObjectAfterSimple(element));
115
138
 
116
139
  if (!is && index < n) {
117
140
  print(',');
118
141
 
119
- if (isNextSpreadBetweenObjects(element) || !(element.isObjectExpression() && isNextSpread(element)))
142
+ if (isNextSimpleBetweenObjects(element) || !(element.isObjectExpression() && isNextSimple(element)))
120
143
  print.space();
121
144
  }
122
145
  }
@@ -166,8 +189,8 @@ module.exports.ArrayExpression = {
166
189
  },
167
190
  };
168
191
 
169
- function isSpreadAfterObject(path) {
170
- if (!isSpreadElement(path))
192
+ function isSimpleAfterObject(path) {
193
+ if (!isSpreadElement(path) && !isIdentifier(path))
171
194
  return;
172
195
 
173
196
  const prev = path.getPrevSibling();
@@ -5,7 +5,6 @@ const {assign} = Object;
5
5
  module.exports.chain = (path) => {
6
6
  const all = [
7
7
  ...down(path),
8
-
9
8
  ...up(path),
10
9
  ];
11
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.19.0",
3
+ "version": "8.20.1",
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",