@putout/printer 8.18.0 → 8.19.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.04.19, v8.19.0
2
+
3
+ feature:
4
+ - 285747d @putout/printer: ArrayExpression: SpreadAfterObject
5
+
1
6
  2024.04.19, v8.18.0
2
7
 
3
8
  feature:
@@ -7,6 +7,8 @@ const {
7
7
  isIdentifierAndIdentifier,
8
8
  isStringAndArray,
9
9
  isSimpleAndEmptyObject,
10
+ isNext,
11
+
10
12
  } = require('../../is');
11
13
 
12
14
  const {
@@ -37,6 +39,7 @@ const isObjectAfterSpread = (a) => isSpreadElement(a) && isNextObject(a) && !isP
37
39
  const isObjectAfterIdentifier = (a) => isIdentifier(a) && isNextObject(a) && !isPrevObject(a);
38
40
  const isObjectAfterSimple = (a) => isObjectAfterSpread(a) || isObjectAfterIdentifier(a);
39
41
  const isNextSpread = (a) => a.getNextSibling().isSpreadElement();
42
+
40
43
  const isNextSpreadBetweenObjects = (a) => {
41
44
  const next = a.getNextSibling();
42
45
  const is = next.isSpreadElement();
@@ -44,7 +47,9 @@ const isNextSpreadBetweenObjects = (a) => {
44
47
  if (!is)
45
48
  return true;
46
49
 
47
- return next.getNextSibling().isObjectExpression();
50
+ return next
51
+ .getNextSibling()
52
+ .isObjectExpression();
48
53
  };
49
54
 
50
55
  const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
@@ -96,7 +101,7 @@ module.exports.ArrayExpression = {
96
101
  for (const [index, element] of elements.entries()) {
97
102
  const is = isNewLine && isCurrentNewLine(element);
98
103
 
99
- if (index && isSpreadElement(element) && !isNextSpread(element) && !isNextObject(element))
104
+ if (isSpreadAfterObject(element))
100
105
  print.newline();
101
106
 
102
107
  maybe.indent(is);
@@ -160,3 +165,16 @@ module.exports.ArrayExpression = {
160
165
  indent.inc();
161
166
  },
162
167
  };
168
+
169
+ function isSpreadAfterObject(path) {
170
+ if (!isSpreadElement(path))
171
+ return;
172
+
173
+ const prev = path.getPrevSibling();
174
+ const next = path.getNextSibling();
175
+
176
+ if (next.isObjectExpression())
177
+ return false;
178
+
179
+ return prev.isObjectExpression();
180
+ }
@@ -5,6 +5,7 @@ const {assign} = Object;
5
5
  module.exports.chain = (path) => {
6
6
  const all = [
7
7
  ...down(path),
8
+
8
9
  ...up(path),
9
10
  ];
10
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "8.18.0",
3
+ "version": "8.19.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",