@putout/printer 15.3.2 → 15.5.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,13 @@
1
+ 2025.06.19, v15.5.0
2
+
3
+ feature:
4
+ - c73f1da @putout/printer: ArrayExpression: maxElementLengthInOneLine: add
5
+
6
+ 2025.06.18, v15.4.0
7
+
8
+ feature:
9
+ - 3317e10 @putout/printer: Identifier: typeAnnotation: do not print inside SequenceExpression, MemberExpression
10
+
1
11
  2025.06.14, v15.3.2
2
12
 
3
13
  fix:
package/README.md CHANGED
@@ -96,6 +96,7 @@ print(ast, {
96
96
  comments: true,
97
97
  maxSpecifiersInOneLine: 2,
98
98
  maxElementsInOneLine: 3,
99
+ maxElementLengthInOneLine: 10,
99
100
  maxLogicalsInOneLine: 3,
100
101
  maxVariablesInOneLine: 4,
101
102
  maxTypesInOneLine: 3,
@@ -102,6 +102,7 @@ module.exports.ArrayExpression = {
102
102
  const {
103
103
  maxElementsInOneLine,
104
104
  trailingComma,
105
+ maxElementLengthInOneLine,
105
106
  } = semantics;
106
107
 
107
108
  const elements = path.get('elements');
@@ -116,6 +117,7 @@ module.exports.ArrayExpression = {
116
117
  const isNewLine = isMultiLine(path, {
117
118
  elements,
118
119
  maxElementsInOneLine,
120
+ maxElementLengthInOneLine,
119
121
  });
120
122
 
121
123
  const n = elements.length - 1;
@@ -23,6 +23,7 @@ const {
23
23
  isNullLiteral,
24
24
  isStringLiteral,
25
25
  isSpreadElement,
26
+ isIdentifier,
26
27
  } = types;
27
28
 
28
29
  const {round} = Math;
@@ -59,9 +60,24 @@ const isSiblingIsArray = (path) => {
59
60
  .isArrayExpression();
60
61
  };
61
62
 
62
- module.exports.isMultiLine = (path, {elements, maxElementsInOneLine}) => {
63
+ function isMaxElementLengthInOneLine(elements, maxElementLengthInOneLine) {
64
+ if (elements.length > 1)
65
+ return false;
66
+
63
67
  const [first] = elements;
64
68
 
69
+ if (!isIdentifier(first))
70
+ return false;
71
+
72
+ return first.node.name.length < maxElementLengthInOneLine;
73
+ }
74
+
75
+ module.exports.isMultiLine = (path, {elements, maxElementsInOneLine, maxElementLengthInOneLine}) => {
76
+ const [first] = elements;
77
+
78
+ if (isMaxElementLengthInOneLine(elements, maxElementLengthInOneLine))
79
+ return ONE_LINE;
80
+
65
81
  if (elements.length > maxElementsInOneLine && isStringLiteral(first))
66
82
  return MULTI_LINE;
67
83
 
@@ -1,5 +1,11 @@
1
1
  'use strict';
2
2
 
3
+ const {types} = require('@putout/babel');
4
+ const {
5
+ isMemberExpression,
6
+ isSequenceExpression,
7
+ } = types;
8
+
3
9
  module.exports.maybePrintTypeAnnotation = maybePrintTypeAnnotation;
4
10
 
5
11
  module.exports.maybeTypeAnnotation = (visit) => (path, printer, semantics) => {
@@ -9,9 +15,17 @@ module.exports.maybeTypeAnnotation = (visit) => (path, printer, semantics) => {
9
15
  };
10
16
 
11
17
  function maybePrintTypeAnnotation(path, printer) {
12
- const {typeAnnotation} = path.node;
18
+ const {parentPath, node} = path;
19
+
20
+ const {typeAnnotation} = node;
13
21
  const {write, traverse} = printer;
14
22
 
23
+ if (isSequenceExpression(parentPath))
24
+ return;
25
+
26
+ if (isMemberExpression(parentPath))
27
+ return;
28
+
15
29
  if (typeAnnotation) {
16
30
  write(':');
17
31
  write.space();
@@ -35,6 +35,7 @@ const initSemantics = (format, semantics = {}) => ({
35
35
  maxPropertiesLengthInOneLine: 15,
36
36
  maxSpecifiersInOneLine: 2,
37
37
  maxElementsInOneLine: 5,
38
+ maxElementLengthInOneLine: 10,
38
39
  maxLogicalsInOneLine: 3,
39
40
  maxVariablesInOneLine: 4,
40
41
  maxTypesInOneLine: 3,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "15.3.2",
3
+ "version": "15.5.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",