@putout/printer 1.118.0 → 1.120.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
|
+
2023.05.29, v1.120.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- da33669 @putout/printer: ObjectProperty: improve support when one line inside LogicalExpression
|
|
5
|
+
- db06c37 @putout/printer: ObjectPattern: improve RestElement support
|
|
6
|
+
|
|
7
|
+
2023.05.29, v1.119.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- 971dad5 @putout/printer: improve support of RestSpread inside ObjectPattern
|
|
11
|
+
|
|
1
12
|
2023.05.25, v1.118.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -91,7 +91,8 @@ module.exports.ObjectProperty = (path, {print, maybe}) => {
|
|
|
91
91
|
shorthand,
|
|
92
92
|
computed,
|
|
93
93
|
} = path.node;
|
|
94
|
-
|
|
94
|
+
const properties = path.parentPath.get('properties');
|
|
95
|
+
const isLast = path === properties.at(-1);
|
|
95
96
|
const manyLines = !isOneLine(path.parentPath);
|
|
96
97
|
|
|
97
98
|
maybe.print(computed, '[');
|
|
@@ -104,7 +105,10 @@ module.exports.ObjectProperty = (path, {print, maybe}) => {
|
|
|
104
105
|
print('__value');
|
|
105
106
|
}
|
|
106
107
|
|
|
107
|
-
|
|
108
|
+
if (manyLines)
|
|
109
|
+
print(',');
|
|
110
|
+
else if (!isLast && properties.length)
|
|
111
|
+
print(', ');
|
|
108
112
|
};
|
|
109
113
|
|
|
110
114
|
const ONE_LINE = true;
|
|
@@ -137,3 +141,4 @@ function isParens(path) {
|
|
|
137
141
|
|
|
138
142
|
return false;
|
|
139
143
|
}
|
|
144
|
+
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
isIdentifier,
|
|
5
|
+
isObjectPattern,
|
|
6
|
+
} = require('@babel/types');
|
|
4
7
|
|
|
5
8
|
const {
|
|
6
9
|
isForOf,
|
|
@@ -22,12 +25,15 @@ module.exports.ObjectPattern = {
|
|
|
22
25
|
const properties = path.get('properties');
|
|
23
26
|
const n = properties.length - 1;
|
|
24
27
|
const is = shouldAddNewline(path);
|
|
28
|
+
const hasObject = n && hasObjectPattern(properties);
|
|
25
29
|
|
|
26
30
|
maybe.print(is, '\n');
|
|
27
31
|
|
|
28
32
|
for (const [i, property] of properties.entries()) {
|
|
29
33
|
if (property.isRestElement()) {
|
|
34
|
+
maybe.indent(hasObject);
|
|
30
35
|
print(property);
|
|
36
|
+
maybe.print.newline(hasObject);
|
|
31
37
|
continue;
|
|
32
38
|
}
|
|
33
39
|
|
|
@@ -60,7 +66,7 @@ module.exports.ObjectPattern = {
|
|
|
60
66
|
maybe.print.newline(couple);
|
|
61
67
|
}
|
|
62
68
|
|
|
63
|
-
if (is) {
|
|
69
|
+
if (is || hasObject) {
|
|
64
70
|
print(',');
|
|
65
71
|
print.newline();
|
|
66
72
|
|
|
@@ -81,7 +87,10 @@ module.exports.ObjectPattern = {
|
|
|
81
87
|
if (!path.parentPath.isObjectProperty())
|
|
82
88
|
return false;
|
|
83
89
|
|
|
84
|
-
|
|
90
|
+
if (isOneParentProperty(path))
|
|
91
|
+
return true;
|
|
92
|
+
|
|
93
|
+
return false;
|
|
85
94
|
},
|
|
86
95
|
after(path, {print}) {
|
|
87
96
|
print.newline();
|
|
@@ -102,6 +111,15 @@ function checkLength(properties) {
|
|
|
102
111
|
return false;
|
|
103
112
|
}
|
|
104
113
|
|
|
114
|
+
function hasObjectPattern(properties) {
|
|
115
|
+
for (const property of properties) {
|
|
116
|
+
if (isObjectPattern(property.node.value))
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
|
|
105
123
|
function shouldAddNewline(path) {
|
|
106
124
|
const properties = path.get('properties');
|
|
107
125
|
const n = properties.length - 1;
|
|
@@ -114,4 +132,3 @@ function shouldAddNewline(path) {
|
|
|
114
132
|
|
|
115
133
|
return false;
|
|
116
134
|
}
|
|
117
|
-
|
package/package.json
CHANGED