@putout/printer 18.1.1 → 18.1.3

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,16 @@
1
+ 2026.03.06, v18.1.3
2
+
3
+ fix:
4
+ - 033b2a6 @putout/printer: ArrayExpression: maxElementLengthInOneLine
5
+
6
+ 2026.03.06, v18.1.2
7
+
8
+ feature:
9
+ - 5996fbf @putout/printer: TypeChecker: ->
10
+ - 7001376 @putout/printer: ArrayExpression: beforeIf: move out
11
+ - 2f22d1d @putout/printer: ArrayExpression: isSimpleBetweenObjects
12
+ - 50166f4 @putout/printer: ArrayExpression: isSpaceAfterComma
13
+
1
14
  2026.03.06, v18.1.1
2
15
 
3
16
  feature:
@@ -1,4 +1,5 @@
1
1
  import {types} from '@putout/babel';
2
+ import {createTypeChecker} from '#type-checker';
2
3
  import {
3
4
  isCoupleLines,
4
5
  isStringAndIdentifier,
@@ -6,6 +7,8 @@ import {
6
7
  isStringAndArray,
7
8
  isSimpleAndNotEmptyObject,
8
9
  isNextObject,
10
+ getNext,
11
+ isInsideArray,
9
12
  } from '#is';
10
13
  import {
11
14
  isIncreaseIndent,
@@ -13,14 +16,14 @@ import {
13
16
  isMultiLine,
14
17
  } from './newline.js';
15
18
  import {
16
- isInsideArray,
17
19
  isArrayInsideArray,
18
20
  isArrayIndented,
19
21
  } from './indent.js';
22
+ import {isObjectAfterSimple} from './is-object-after-simple.js';
20
23
  import {
21
- isObjectAfterSimple,
22
- isNextSimple,
23
- } from './is-object-after-simple.js';
24
+ beforeIf,
25
+ isInsideOneElementArray,
26
+ } from './before-if.js';
24
27
 
25
28
  const {
26
29
  isObjectExpression,
@@ -60,35 +63,20 @@ const isSpreadBeforeObject = (a) => {
60
63
  return prev.get('argument').isCallExpression();
61
64
  };
62
65
 
63
- const isNextSimpleBetweenObjects = (a) => {
64
- const next = a.getNextSibling();
65
- const is = next.isSpreadElement() || next.isIdentifier() || next.isCallExpression();
66
-
67
- if (!is)
68
- return true;
69
-
70
- return next
71
- .getNextSibling()
72
- .isObjectExpression();
73
- };
66
+ const isSimpleBetweenObjects = createTypeChecker([
67
+ ['+', getNext(isObjectExpression)],
68
+ ['-', isSpreadElement],
69
+ ['-', isIdentifier],
70
+ ['+: -> !', isCallExpression],
71
+ ]);
74
72
 
75
- const isInsideOneElementArray = ({parentPath}) => parentPath.node.elements.length === 1;
73
+ const isSpaceAfterComa = createTypeChecker([
74
+ getNext(isSimpleBetweenObjects),
75
+ '+: -> !ObjectExpression',
76
+ ]);
76
77
 
77
78
  export const ArrayExpression = {
78
- beforeIf(path) {
79
- const {parentPath} = path;
80
-
81
- if (!parentPath.isArrayExpression())
82
- return false;
83
-
84
- if (isCoupleLines(parentPath))
85
- return false;
86
-
87
- if (isStringAndIdentifier(path) && isInsideOneElementArray(path))
88
- return true;
89
-
90
- return isIdentifierAndIdentifier(path);
91
- },
79
+ beforeIf,
92
80
  before(path, {print}) {
93
81
  print.breakline();
94
82
  },
@@ -137,7 +125,7 @@ export const ArrayExpression = {
137
125
  if (!is && index < n) {
138
126
  print(',');
139
127
 
140
- if (isNextSimpleBetweenObjects(element) || !(element.isObjectExpression() && isNextSimple(element)))
128
+ if (isSpaceAfterComa(element))
141
129
  print.space();
142
130
  }
143
131
  }
@@ -0,0 +1,24 @@
1
+ import {createTypeChecker} from '#type-checker';
2
+ import {
3
+ isCoupleLines,
4
+ isIdentifierAndIdentifier,
5
+ isInsideArray,
6
+ isStringAndIdentifier,
7
+ } from '#is';
8
+
9
+ export const isInsideOneElementArray = ({parentPath}) => {
10
+ const {elements} = parentPath.node;
11
+ return elements.length === 1;
12
+ };
13
+
14
+ const isStringAndIdentifierInsideOneElementArray = createTypeChecker([
15
+ ['-: -> !', isStringAndIdentifier],
16
+ ['+', isInsideOneElementArray],
17
+ ]);
18
+
19
+ export const beforeIf = createTypeChecker([
20
+ ['-: -> !', isInsideArray],
21
+ ['-: parentPath ->', isCoupleLines],
22
+ isIdentifierAndIdentifier,
23
+ isStringAndIdentifierInsideOneElementArray,
24
+ ]);
@@ -1,5 +1,5 @@
1
1
  import {types} from '@putout/babel';
2
- import {isIndented} from '#is';
2
+ import {isIndented, isInsideArray} from '#is';
3
3
 
4
4
  const {
5
5
  isStringLiteral,
@@ -8,8 +8,6 @@ const {
8
8
  isTemplateLiteral,
9
9
  } = types;
10
10
 
11
- export const isInsideArray = (path) => path.parentPath.isArrayExpression();
12
-
13
11
  const isObjectAfterString = ([first, second]) => {
14
12
  if (!first || !second)
15
13
  return false;
@@ -17,9 +17,3 @@ export const isObjectAfterSimple = (a) => {
17
17
 
18
18
  return SIMPLE_TYPES.includes(type);
19
19
  };
20
-
21
- export const isNextSimple = (a) => {
22
- const {type} = a.getNextSibling();
23
-
24
- return SIMPLE_TYPES.includes(type);
25
- };
@@ -10,8 +10,8 @@ import {
10
10
  isIdentifierAndIdentifier,
11
11
  isSimpleAndNotEmptyObject,
12
12
  isInsideCall,
13
+ isInsideArray,
13
14
  } from '#is';
14
- import {isInsideArray} from './indent.js';
15
15
  import {isInsideForOf} from '../object-pattern/is.js';
16
16
 
17
17
  const isLastArg = ({parentPath}) => !parentPath.isCallExpression();
@@ -151,10 +151,13 @@ const isMoreThenMaxLiteralLength = (path, {maxElementLengthInOneLine}) => {
151
151
  return first.value.length > maxElementLengthInOneLine;
152
152
  };
153
153
 
154
- const isMoreThenMaxIdentifierLength = (path) => {
154
+ const isMoreThenMaxIdentifierLength = (path, {maxElementLengthInOneLine}) => {
155
155
  const [first] = path.node.elements;
156
156
 
157
- return isIdentifier(first);
157
+ if (!isIdentifier(first))
158
+ return false;
159
+
160
+ return first.name.length > maxElementLengthInOneLine;
158
161
  };
159
162
 
160
163
  const isMoreThenMaxElementLengthInOneLine = createTypeChecker([
@@ -16,6 +16,7 @@ const isExcludedFromChain = satisfy([
16
16
  isUnaryExpression,
17
17
  isIfStatement,
18
18
  ]);
19
+
19
20
  const hasComment = ({type}) => type === 'CommentLine';
20
21
 
21
22
  const isInsideMemberCall = (path) => {
@@ -38,10 +38,12 @@ const {
38
38
  } = types;
39
39
 
40
40
  const isLogicalArgument = (path) => isLogicalExpression(path.node.argument);
41
+
41
42
  const isParens = createTypeChecker([
42
43
  isInsideBody,
43
44
  isInsideExpression,
44
45
  ]);
46
+
45
47
  const getCallee = (fn) => (a) => fn(a.get('callee'));
46
48
 
47
49
  const isMemberExpressionCallee = createTypeChecker([
@@ -24,6 +24,7 @@ export const isInsideBlock = (path) => isBlockStatement(path.parentPath);
24
24
  export const isInsideSwitchCase = (path) => isSwitchCase(path.parentPath);
25
25
  export const isInsideBody = ({node, parentPath}) => node === parentPath.node.body;
26
26
  export const isInsideExpression = ({parentPath}) => isExpressionStatement(parentPath);
27
+ export const isInsideArray = (path) => isArrayExpression(path.parentPath);
27
28
 
28
29
  export const isInsideTSModuleBlock = ({parentPath}) => isTSModuleBlock(parentPath);
29
30
 
@@ -90,4 +90,3 @@ export const ExpressionStatement = {
90
90
  maybe.markAfter(store(), path);
91
91
  },
92
92
  };
93
-
@@ -10,7 +10,7 @@ export const parseOperation = (operation) => {
10
10
  if (!command)
11
11
  return [parsedResult, '', ''];
12
12
 
13
- const [selector, not] = command.split(' -> ');
13
+ const [selector, not] = command.split(/ ->\s?/);
14
14
 
15
15
  return [parsedResult, selector.trim(), not];
16
16
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.1.1",
3
+ "version": "18.1.3",
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",