@putout/printer 8.32.0 → 8.34.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,14 @@
|
|
|
1
|
+
2024.05.07, v8.34.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 8a303f5 @putout/printer: jsx: JSXOpeningElement: indent
|
|
5
|
+
|
|
6
|
+
2024.05.03, v8.33.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- c8b9948 @putout/printer: ObjectPattern: improve support of maxPropertiesLengthInOneLine
|
|
10
|
+
- 039c54d @putout/printer: ObjectPattern: indent: simplify
|
|
11
|
+
|
|
1
12
|
2024.05.03, v8.32.0
|
|
2
13
|
|
|
3
14
|
feature:
|
package/lib/tokenize/expressions/object-pattern/more-then-max-properties-length-in-one-line.js
CHANGED
|
@@ -1,11 +1,26 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
isAssignmentPattern,
|
|
5
|
+
isIdentifier,
|
|
6
|
+
} = require('@putout/babel').types;
|
|
4
7
|
|
|
5
8
|
module.exports.moreThenMaxPropertiesLengthInOneLine = (path, {maxPropertiesLengthInOneLine}) => {
|
|
6
9
|
const {properties} = path.node;
|
|
7
10
|
|
|
8
|
-
for (const {key} of properties) {
|
|
11
|
+
for (const {key, value} of properties) {
|
|
12
|
+
if (isAssignmentPattern(value)) {
|
|
13
|
+
const {left, right} = value;
|
|
14
|
+
|
|
15
|
+
if (!isIdentifier(left) || !isIdentifier(right))
|
|
16
|
+
continue;
|
|
17
|
+
|
|
18
|
+
const length = left.name.length + right.name.length;
|
|
19
|
+
|
|
20
|
+
if (length >= maxPropertiesLengthInOneLine)
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
9
24
|
if (!isIdentifier(key))
|
|
10
25
|
continue;
|
|
11
26
|
|
|
@@ -26,8 +26,18 @@ function isIndent(path) {
|
|
|
26
26
|
return !path.parentPath.isArrayPattern();
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
+
const isCoupleProperties = ({path, valuePath, property}) => {
|
|
30
|
+
if (!isCoupleLines(valuePath))
|
|
31
|
+
return false;
|
|
32
|
+
|
|
33
|
+
if (exists(property.getPrevSibling()))
|
|
34
|
+
return false;
|
|
35
|
+
|
|
36
|
+
return !path.parentPath.isObjectProperty();
|
|
37
|
+
};
|
|
38
|
+
|
|
29
39
|
module.exports.ObjectPattern = {
|
|
30
|
-
print: maybeTypeAnnotation((path, {print, maybe}, semantics) => {
|
|
40
|
+
print: maybeTypeAnnotation((path, {print, maybe, indent}, semantics) => {
|
|
31
41
|
const shouldIndent = isIndent(path);
|
|
32
42
|
const {
|
|
33
43
|
maxPropertiesInOneLine,
|
|
@@ -64,7 +74,11 @@ module.exports.ObjectPattern = {
|
|
|
64
74
|
const isAssign = valuePath.isAssignmentPattern();
|
|
65
75
|
|
|
66
76
|
const {shorthand, computed} = property.node;
|
|
67
|
-
const couple =
|
|
77
|
+
const couple = isCoupleProperties({
|
|
78
|
+
path,
|
|
79
|
+
property,
|
|
80
|
+
valuePath,
|
|
81
|
+
});
|
|
68
82
|
|
|
69
83
|
maybe.indent(is);
|
|
70
84
|
maybe.print.breakline(couple);
|
|
@@ -84,7 +98,7 @@ module.exports.ObjectPattern = {
|
|
|
84
98
|
maybe.print.newline(couple);
|
|
85
99
|
}
|
|
86
100
|
|
|
87
|
-
if (is || hasObject) {
|
|
101
|
+
if (is || hasObject && !isAssign) {
|
|
88
102
|
print(',');
|
|
89
103
|
print.newline();
|
|
90
104
|
|
|
@@ -97,9 +111,7 @@ module.exports.ObjectPattern = {
|
|
|
97
111
|
}
|
|
98
112
|
}
|
|
99
113
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
maybe.indent.dec(!shouldIndent);
|
|
114
|
+
indent.dec();
|
|
103
115
|
maybe.indent(is);
|
|
104
116
|
maybe.indent.inc(!shouldIndent);
|
|
105
117
|
print('}');
|
|
@@ -187,9 +199,7 @@ function shouldAddNewline(path, semantics) {
|
|
|
187
199
|
return parentPath.isObjectProperty();
|
|
188
200
|
}
|
|
189
201
|
|
|
190
|
-
function isFunctionParam(
|
|
191
|
-
const {parentPath} = path;
|
|
192
|
-
|
|
202
|
+
function isFunctionParam({parentPath}) {
|
|
193
203
|
if (parentPath.isFunction())
|
|
194
204
|
return true;
|
|
195
205
|
|
package/package.json
CHANGED