@putout/printer 18.2.1 → 18.2.2

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,9 @@
1
+ 2026.03.07, v18.2.2
2
+
3
+ feature:
4
+ - 7633d10 @putout/printer: ArrayExpression: isSimpleAfterObject
5
+ - c57048d @putout/printer: ArrayExpression: isCurrentNewLine: simplify
6
+
1
7
  2026.03.07, v18.2.1
2
8
 
3
9
  fix:
@@ -9,6 +9,7 @@ import {
9
9
  isNextObject,
10
10
  callWithNext,
11
11
  isInsideArray,
12
+ callWithPrev,
12
13
  } from '#is';
13
14
  import {
14
15
  isIncreaseIndent,
@@ -96,17 +97,18 @@ export const ArrayExpression = {
96
97
 
97
98
  maybe.indent.inc(indented && shouldIncreaseIndent);
98
99
 
99
- const isNewLine = isMultiLine(path, {
100
+ const needsNewline = isMultiLine(path, {
100
101
  maxElementsInOneLine,
101
102
  maxElementLengthInOneLine,
102
103
  });
103
104
 
104
105
  const n = elements.length - 1;
105
106
 
106
- maybe.print.newline(isNewLine && elements.length);
107
+ if (needsNewline)
108
+ print.newline();
107
109
 
108
110
  for (const [index, element] of elements.entries()) {
109
- const is = isNewLine && isCurrentNewLine(element);
111
+ const is = needsNewline && isCurrentNewLine(element);
110
112
 
111
113
  if (isSimpleAfterObject(element))
112
114
  print.newline();
@@ -139,10 +141,10 @@ export const ArrayExpression = {
139
141
  const isHideIdent = !isAroundStrings(path) || parentCountTwo;
140
142
 
141
143
  maybe.indent.dec(isHideIdent);
142
- maybe.indent(elements.length && isNewLine);
144
+ maybe.indent(elements.length && needsNewline);
143
145
  maybe.indent.inc(isHideIdent);
144
146
  } else if (!isArrayInsideArray(path) && !isObjectExpression(elements.at(-1))) {
145
- maybe.indent(elements.length && isNewLine);
147
+ maybe.indent(elements.length && needsNewline);
146
148
  }
147
149
 
148
150
  if (isSimpleAndNotEmptyObject(path) && !isSpreadElement(elements.at(-1)) && !isCallExpression(elements.at(-1))) {
@@ -173,15 +175,15 @@ export const ArrayExpression = {
173
175
  },
174
176
  };
175
177
 
176
- function isSimpleAfterObject(path) {
177
- if (!isSpreadElement(path) && !isIdentifier(path) && !isCallExpression(path))
178
- return;
179
-
180
- const prev = path.getPrevSibling();
181
- const next = path.getNextSibling();
182
-
183
- if (next.isObjectExpression())
184
- return false;
185
-
186
- return prev.isObjectExpression();
187
- }
178
+ const isSimple = createTypeChecker([
179
+ '-: -> SpreadElement',
180
+ '-: -> Identifier',
181
+ '+: -> !CallExpression',
182
+ ]);
183
+
184
+ const isSimpleAfterObject = createTypeChecker([
185
+ ['-', isSimple],
186
+ ['-', callWithNext(isObjectExpression)],
187
+ ['+', callWithPrev(isObjectExpression)],
188
+ ]);
189
+
@@ -338,9 +338,8 @@ const isStringAndObject = (elements) => {
338
338
  return isStringLiteral(first) && isObjectExpression(last);
339
339
  };
340
340
 
341
- export const isCurrentNewLine = (path) => {
342
- if (path.isSpreadElement())
343
- return true;
344
-
345
- return !path.isObjectExpression();
346
- };
341
+ export const isCurrentNewLine = createTypeChecker([
342
+ '+: -> SpreadElement',
343
+ '+: -> !ObjectExpression',
344
+ ]);
345
+
@@ -31,6 +31,7 @@ export const isInsideTSModuleBlock = ({parentPath}) => isTSModuleBlock(parentPat
31
31
  export const isInsideCall = ({parentPath}) => parentPath.isCallExpression();
32
32
  export const isInsideReturn = ({parentPath}) => parentPath.isReturnStatement();
33
33
  export const callWithNext = (fn) => (path) => fn(path.getNextSibling());
34
+ export const callWithPrev = (fn) => (path) => fn(path.getPrevSibling());
34
35
  export const callWithParent = (fn) => (path) => fn(path.parentPath);
35
36
 
36
37
  export const isNext = (path) => {
@@ -90,4 +90,3 @@ export const ExpressionStatement = {
90
90
  maybe.markAfter(store(), path);
91
91
  },
92
92
  };
93
-
@@ -37,4 +37,3 @@ export const instrument = (typeNames, fn, overrides = {}) => {
37
37
  };
38
38
 
39
39
  export const getCoverage = () => Coverage;
40
-
@@ -12,6 +12,7 @@ export const createTypeChecker = (typeNames, overrides = {}) => {
12
12
  const {
13
13
  instrumentCoverage = _instrument,
14
14
  } = overrides;
15
+
15
16
  const tuples = parseTypeNames(typeNames);
16
17
  const typeChecker = (path, options) => {
17
18
  for (const [index, [operation, typeName]] of tuples.entries()) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.2.1",
3
+ "version": "18.2.2",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",