@putout/printer 18.0.13 → 18.0.15
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,15 @@
|
|
|
1
|
+
2026.03.06, v18.0.15
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 22d510e @putout/printer: ObjectExpression: isLogicalArgument
|
|
5
|
+
|
|
6
|
+
2026.03.06, v18.0.14
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 69fe928 @putout/printer: ObjectExpression: isManyLines: merge
|
|
10
|
+
- 5066c76 @putout/printer: isOneLine -> isManyLines
|
|
11
|
+
- 050d709 @putout/printer: ObjectExpression: isOneline: simplify
|
|
12
|
+
|
|
1
13
|
2026.03.05, v18.0.13
|
|
2
14
|
|
|
3
15
|
feature:
|
|
@@ -17,14 +17,27 @@ import {parseComments} from '../../comment/comment.js';
|
|
|
17
17
|
import {isInsideTuple} from './is-inside-tuple.js';
|
|
18
18
|
import {isLooksLikeChain} from '../member-expression/is-looks-like-chain.js';
|
|
19
19
|
|
|
20
|
+
const notLastArgInsideCall = (path) => {
|
|
21
|
+
const {parentPath} = path;
|
|
22
|
+
|
|
23
|
+
if (!parentPath.isCallExpression())
|
|
24
|
+
return false;
|
|
25
|
+
|
|
26
|
+
if (isCoupleLines(path))
|
|
27
|
+
return false;
|
|
28
|
+
|
|
29
|
+
return path !== parentPath.get('arguments').at(-1);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const hasNoProperties = (path) => !path.node.properties.length;
|
|
33
|
+
const hasValue = (path) => path.node.properties[0].value;
|
|
34
|
+
|
|
20
35
|
const {
|
|
21
|
-
isSpreadElement,
|
|
22
36
|
isMemberExpression,
|
|
37
|
+
isLogicalExpression,
|
|
23
38
|
} = types;
|
|
24
39
|
|
|
25
|
-
const
|
|
26
|
-
const isValue = (path) => path.get('properties.0.value').node;
|
|
27
|
-
|
|
40
|
+
const isLogicalArgument = (path) => isLogicalExpression(path.node.argument);
|
|
28
41
|
const isParens = createTypeChecker([isInsideBody, isInsideExpression]);
|
|
29
42
|
const getCallee = (fn) => (a) => fn(a.get('callee'));
|
|
30
43
|
|
|
@@ -46,6 +59,17 @@ const isInsideTupleLike = createTypeChecker([
|
|
|
46
59
|
'+: parentPath.parentPath.node.elements.0 -> StringLiteral',
|
|
47
60
|
]);
|
|
48
61
|
|
|
62
|
+
export const isManyLines = createTypeChecker([
|
|
63
|
+
['-', hasNoProperties],
|
|
64
|
+
'-: parentPath -> ForOfStatement',
|
|
65
|
+
'+: node.properties.0 -> SpreadElement',
|
|
66
|
+
['-', notLastArgInsideCall],
|
|
67
|
+
['-', isForOf],
|
|
68
|
+
['-', isIf],
|
|
69
|
+
['+', isCoupleLines],
|
|
70
|
+
['+', hasValue],
|
|
71
|
+
]);
|
|
72
|
+
|
|
49
73
|
export const ObjectExpression = (path, printer, semantics) => {
|
|
50
74
|
const {trailingComma} = semantics;
|
|
51
75
|
const {
|
|
@@ -61,7 +85,7 @@ export const ObjectExpression = (path, printer, semantics) => {
|
|
|
61
85
|
const properties = path.get('properties');
|
|
62
86
|
const {length} = properties;
|
|
63
87
|
const parens = isParens(path);
|
|
64
|
-
const manyLines =
|
|
88
|
+
const manyLines = isManyLines(path);
|
|
65
89
|
|
|
66
90
|
maybe.print(parens, '(');
|
|
67
91
|
print('{');
|
|
@@ -75,7 +99,7 @@ export const ObjectExpression = (path, printer, semantics) => {
|
|
|
75
99
|
|
|
76
100
|
for (const [index, property] of properties.entries()) {
|
|
77
101
|
if (property.isSpreadElement()) {
|
|
78
|
-
const logical =
|
|
102
|
+
const logical = isLogicalArgument(property);
|
|
79
103
|
|
|
80
104
|
if (noLeadingComment(property))
|
|
81
105
|
maybe.indent(length > 1 || logical || manyLines);
|
|
@@ -126,50 +150,3 @@ const hasNextLeadingComment = (path) => {
|
|
|
126
150
|
return hasLeadingComment(next);
|
|
127
151
|
};
|
|
128
152
|
|
|
129
|
-
const notLastArgInsideCall = (path) => {
|
|
130
|
-
const {parentPath} = path;
|
|
131
|
-
|
|
132
|
-
if (!parentPath.isCallExpression())
|
|
133
|
-
return false;
|
|
134
|
-
|
|
135
|
-
if (isCoupleLines(path))
|
|
136
|
-
return false;
|
|
137
|
-
|
|
138
|
-
return path !== parentPath.get('arguments').at(-1);
|
|
139
|
-
};
|
|
140
|
-
|
|
141
|
-
const ONE_LINE = true;
|
|
142
|
-
const MANY_LINES = false;
|
|
143
|
-
|
|
144
|
-
const isFirstSpread = (path) => {
|
|
145
|
-
const [first] = path.get('properties');
|
|
146
|
-
|
|
147
|
-
if (!isSpreadElement(first))
|
|
148
|
-
return false;
|
|
149
|
-
|
|
150
|
-
return !path.parentPath.isForOfStatement();
|
|
151
|
-
};
|
|
152
|
-
|
|
153
|
-
export function isOneLine(path) {
|
|
154
|
-
const {length} = path.get('properties');
|
|
155
|
-
|
|
156
|
-
if (!length)
|
|
157
|
-
return ONE_LINE;
|
|
158
|
-
|
|
159
|
-
if (isFirstSpread(path))
|
|
160
|
-
return MANY_LINES;
|
|
161
|
-
|
|
162
|
-
if (notLastArgInsideCall(path))
|
|
163
|
-
return ONE_LINE;
|
|
164
|
-
|
|
165
|
-
if (isForOf(path))
|
|
166
|
-
return ONE_LINE;
|
|
167
|
-
|
|
168
|
-
if (isIf(path))
|
|
169
|
-
return ONE_LINE;
|
|
170
|
-
|
|
171
|
-
if (isCoupleLines(path))
|
|
172
|
-
return MANY_LINES;
|
|
173
|
-
|
|
174
|
-
return !isValue(path);
|
|
175
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import {isConcatenation} from '../binary-expression/concatenate.js';
|
|
2
|
-
import {
|
|
2
|
+
import {isManyLines} from './object-expression.js';
|
|
3
3
|
import {printKey} from './print-key.js';
|
|
4
4
|
|
|
5
5
|
export const ObjectProperty = (path, printer, semantics) => {
|
|
@@ -14,7 +14,7 @@ export const ObjectProperty = (path, printer, semantics) => {
|
|
|
14
14
|
const value = path.get('value');
|
|
15
15
|
const properties = path.parentPath.get('properties');
|
|
16
16
|
const isLast = path === properties.at(-1);
|
|
17
|
-
const manyLines =
|
|
17
|
+
const manyLines = isManyLines(path.parentPath);
|
|
18
18
|
|
|
19
19
|
printKey(path, printer);
|
|
20
20
|
|
package/package.json
CHANGED