@putout/printer 18.0.13 → 18.0.14
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
|
@@ -17,13 +17,24 @@ 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 {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
+
|
|
35
|
+
const {isMemberExpression} = types;
|
|
24
36
|
|
|
25
37
|
const isLogical = (path) => path.get('argument').isLogicalExpression();
|
|
26
|
-
const isValue = (path) => path.get('properties.0.value').node;
|
|
27
38
|
|
|
28
39
|
const isParens = createTypeChecker([isInsideBody, isInsideExpression]);
|
|
29
40
|
const getCallee = (fn) => (a) => fn(a.get('callee'));
|
|
@@ -46,6 +57,17 @@ const isInsideTupleLike = createTypeChecker([
|
|
|
46
57
|
'+: parentPath.parentPath.node.elements.0 -> StringLiteral',
|
|
47
58
|
]);
|
|
48
59
|
|
|
60
|
+
export const isManyLines = createTypeChecker([
|
|
61
|
+
['-', hasNoProperties],
|
|
62
|
+
'-: parentPath -> ForOfStatement',
|
|
63
|
+
'+: node.properties.0 -> SpreadElement',
|
|
64
|
+
['-', notLastArgInsideCall],
|
|
65
|
+
['-', isForOf],
|
|
66
|
+
['-', isIf],
|
|
67
|
+
['+', isCoupleLines],
|
|
68
|
+
['+', hasValue],
|
|
69
|
+
]);
|
|
70
|
+
|
|
49
71
|
export const ObjectExpression = (path, printer, semantics) => {
|
|
50
72
|
const {trailingComma} = semantics;
|
|
51
73
|
const {
|
|
@@ -61,7 +83,7 @@ export const ObjectExpression = (path, printer, semantics) => {
|
|
|
61
83
|
const properties = path.get('properties');
|
|
62
84
|
const {length} = properties;
|
|
63
85
|
const parens = isParens(path);
|
|
64
|
-
const manyLines =
|
|
86
|
+
const manyLines = isManyLines(path);
|
|
65
87
|
|
|
66
88
|
maybe.print(parens, '(');
|
|
67
89
|
print('{');
|
|
@@ -125,51 +147,3 @@ const hasNextLeadingComment = (path) => {
|
|
|
125
147
|
|
|
126
148
|
return hasLeadingComment(next);
|
|
127
149
|
};
|
|
128
|
-
|
|
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