@putout/printer 18.3.0 → 18.3.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,8 @@
1
+ 2026.03.08, v18.3.1
2
+
3
+ feature:
4
+ - 00f7cc1 @putout/printer: ArrayExpression: isCommaAfterElement
5
+
1
6
  2026.03.08, v18.3.0
2
7
 
3
8
  feature:
@@ -13,4 +13,3 @@ export const afterIf = createTypeChecker([
13
13
  ['-: -> !', isStringAndIdentifier],
14
14
  ['+', isInsideOneElementArray],
15
15
  ]);
16
-
@@ -12,10 +12,11 @@ import {
12
12
  import {beforeIf} from './before-if.js';
13
13
  import {afterIf} from './after-if.js';
14
14
  import {
15
- isCommaBeforeClosingSquareBrace,
15
+ isCommaAfterElement,
16
16
  isNewlineAfterComma,
17
17
  isSpaceAfterComa,
18
18
  } from './comma.js';
19
+ import {isBreaklineBeforeClosingSquareBrace} from './breakline.js';
19
20
 
20
21
  const {isObjectExpression} = types;
21
22
 
@@ -38,6 +39,7 @@ export const ArrayExpression = {
38
39
  } = semantics;
39
40
 
40
41
  const needIndent = isNeedIndent(path);
42
+
41
43
  const multiline = isMultiLine(path, {
42
44
  maxElementsInOneLine,
43
45
  maxElementLengthInOneLine,
@@ -53,8 +55,15 @@ export const ArrayExpression = {
53
55
 
54
56
  for (const [index, element] of elements.entries()) {
55
57
  const isLast = index === n;
56
- const needsIndentBeforeElement = isIndentBeforeElement(element, {multiline});
57
- const needsComma = needsIndentBeforeElement && trailingComma || !isLast;
58
+ const needsIndentBeforeElement = isIndentBeforeElement(element, {
59
+ multiline,
60
+ });
61
+
62
+ const needsComma = isCommaAfterElement(path, {
63
+ trailingComma,
64
+ isLast,
65
+ needsIndentBeforeElement,
66
+ });
58
67
 
59
68
  if (isNewlineBeforeElement(element))
60
69
  print.newline();
@@ -81,10 +90,8 @@ export const ArrayExpression = {
81
90
  multiline,
82
91
  });
83
92
 
84
- if (isCommaBeforeClosingSquareBrace(path)) {
85
- print(',');
93
+ if (isBreaklineBeforeClosingSquareBrace(path))
86
94
  print.breakline();
87
- }
88
95
 
89
96
  print(']');
90
97
  },
@@ -107,4 +114,3 @@ const isNewlineBeforeElement = createTypeChecker([
107
114
  ['-', callWithNext(isObjectExpression)],
108
115
  ['+', callWithPrev(isObjectExpression)],
109
116
  ]);
110
-
@@ -0,0 +1,16 @@
1
+ import {types} from '@putout/babel';
2
+ import {createTypeChecker} from '#type-checker';
3
+ import {isSimpleAndNotEmptyObject} from '#is';
4
+
5
+ const {
6
+ isSpreadElement,
7
+ isCallExpression,
8
+ } = types;
9
+
10
+ const callWithLastElement = (fn) => (a) => fn(a.at(-1));
11
+
12
+ export const isBreaklineBeforeClosingSquareBrace = createTypeChecker([
13
+ ['-: -> !', isSimpleAndNotEmptyObject],
14
+ ['-: node.elements', callWithLastElement(isSpreadElement)],
15
+ ['+: node.elements -> !', callWithLastElement(isCallExpression)],
16
+ ]);
@@ -1,12 +1,12 @@
1
1
  import {types} from '@putout/babel';
2
2
  import {createTypeChecker} from '#type-checker';
3
- import {
4
- callWithNext,
5
- isSimpleAndNotEmptyObject,
6
- } from '#is';
3
+ import {callWithNext} from '#is';
4
+ import {isBreaklineBeforeClosingSquareBrace} from './breakline.js';
7
5
  import {
8
6
  isLastOption,
9
7
  isMultilineOption,
8
+ isNeedsIndentBeforeElementOption,
9
+ isTrailingCommaOption,
10
10
  } from './is.js';
11
11
 
12
12
  const {
@@ -16,12 +16,15 @@ const {
16
16
  isIdentifier,
17
17
  } = types;
18
18
 
19
- const callWithLastElement = (fn) => (a) => fn(a.at(-1));
19
+ const isCommaAfterElementByOption = createTypeChecker([
20
+ ['+: -> !', isLastOption],
21
+ ['-: -> !', isNeedsIndentBeforeElementOption],
22
+ ['+', isTrailingCommaOption],
23
+ ]);
20
24
 
21
- export const isCommaBeforeClosingSquareBrace = createTypeChecker([
22
- ['-: -> !', isSimpleAndNotEmptyObject],
23
- ['-: node.elements', callWithLastElement(isSpreadElement)],
24
- ['+: node.elements -> !', callWithLastElement(isCallExpression)],
25
+ export const isCommaAfterElement = createTypeChecker([
26
+ ['+', isCommaAfterElementByOption],
27
+ ['+', isBreaklineBeforeClosingSquareBrace],
25
28
  ]);
26
29
 
27
30
  export const isNewlineAfterComma = createTypeChecker([
@@ -2,3 +2,5 @@ export const isMultilineOption = (a, {multiline}) => multiline;
2
2
  export const isNeedsToHideIndentOption = (a, {needsToHideIndent}) => needsToHideIndent;
3
3
  export const isLastOption = (a, {isLast}) => isLast;
4
4
 
5
+ export const isTrailingCommaOption = (a, {trailingComma}) => trailingComma;
6
+ export const isNeedsIndentBeforeElementOption = (a, {needsIndentBeforeElement}) => needsIndentBeforeElement;
@@ -311,4 +311,3 @@ export const isIndentBeforeElement = createTypeChecker([
311
311
  ['+: -> SpreadElement'],
312
312
  ['+: -> !ObjectExpression'],
313
313
  ]);
314
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.3.0",
3
+ "version": "18.3.1",
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",