@putout/printer 13.3.0 → 13.4.1
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 +10 -0
- package/lib/tokenize/expressions/array-expression/array-expression.js +1 -1
- package/lib/tokenize/expressions/object-expression/is-third-object-inside-array.js +4 -8
- package/lib/tokenize/expressions/object-expression/object-expression.js +0 -4
- package/lib/tokenize/is.js +16 -5
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -135,7 +135,7 @@ module.exports.ArrayExpression = {
|
|
|
135
135
|
maybe.print(is, ',');
|
|
136
136
|
|
|
137
137
|
if (!(isObjectExpression(element) && isObjectProperty(path.parentPath)))
|
|
138
|
-
maybe.print.newline((is || isSpreadBeforeObject(element)) && !isNextObject(element));
|
|
138
|
+
maybe.print.newline((is || isSpreadBeforeObject(element)) && !isNextObject(element) && !isObjectExpression(element));
|
|
139
139
|
|
|
140
140
|
maybe.print.space(is && isObjectAfterSimple(element));
|
|
141
141
|
|
|
@@ -4,18 +4,14 @@ const {types} = require('@putout/babel');
|
|
|
4
4
|
const {
|
|
5
5
|
isArrayExpression,
|
|
6
6
|
isCallExpression,
|
|
7
|
+
isIdentifier,
|
|
7
8
|
} = types;
|
|
8
9
|
|
|
9
|
-
module.exports.isThirdObjectInsideArray = (
|
|
10
|
-
const {parentPath} = path;
|
|
11
|
-
|
|
10
|
+
module.exports.isThirdObjectInsideArray = ({parentPath}) => {
|
|
12
11
|
if (!isArrayExpression(parentPath))
|
|
13
12
|
return false;
|
|
14
13
|
|
|
15
|
-
const [, second
|
|
16
|
-
|
|
17
|
-
if (!isCallExpression(second))
|
|
18
|
-
return false;
|
|
14
|
+
const [, second] = parentPath.node.elements;
|
|
19
15
|
|
|
20
|
-
return
|
|
16
|
+
return isCallExpression(second) && !!isIdentifier(second);
|
|
21
17
|
};
|
|
@@ -53,10 +53,6 @@ function isInsideNestedArrayCall({parentPath}) {
|
|
|
53
53
|
|
|
54
54
|
function isInsideNestedTuple({parentPath}) {
|
|
55
55
|
const {elements} = parentPath.parentPath.node;
|
|
56
|
-
|
|
57
|
-
if (!elements)
|
|
58
|
-
return false;
|
|
59
|
-
|
|
60
56
|
const [first] = elements;
|
|
61
57
|
|
|
62
58
|
return isStringLiteral(first);
|
package/lib/tokenize/is.js
CHANGED
|
@@ -78,8 +78,21 @@ function isStringAndIdentifier([a, b]) {
|
|
|
78
78
|
return isStringLiteral(a) && isIdentifier(b);
|
|
79
79
|
}
|
|
80
80
|
|
|
81
|
+
const checkObject = (elements) => {
|
|
82
|
+
let a = elements.at(-1);
|
|
83
|
+
|
|
84
|
+
if (!isObjectExpression(a))
|
|
85
|
+
a = elements.at(-2);
|
|
86
|
+
|
|
87
|
+
if (!isObjectExpression(a))
|
|
88
|
+
return false;
|
|
89
|
+
|
|
90
|
+
return a.node.properties.length;
|
|
91
|
+
};
|
|
92
|
+
|
|
81
93
|
module.exports.isSimpleAndNotEmptyObject = (elements) => {
|
|
82
|
-
const [a
|
|
94
|
+
const [a] = elements;
|
|
95
|
+
|
|
83
96
|
const simpleTypes = [
|
|
84
97
|
'Identifier',
|
|
85
98
|
'SpreadElement',
|
|
@@ -91,10 +104,7 @@ module.exports.isSimpleAndNotEmptyObject = (elements) => {
|
|
|
91
104
|
if (a && !simpleTypes.includes(a.type))
|
|
92
105
|
return false;
|
|
93
106
|
|
|
94
|
-
|
|
95
|
-
return false;
|
|
96
|
-
|
|
97
|
-
return b.node.properties.length;
|
|
107
|
+
return checkObject(elements);
|
|
98
108
|
};
|
|
99
109
|
|
|
100
110
|
module.exports.isIdentifierAndIdentifier = ([a, b]) => {
|
|
@@ -168,3 +178,4 @@ module.exports.hasLeadingComment = (path) => path.node?.leadingComments?.length;
|
|
|
168
178
|
|
|
169
179
|
module.exports.noTrailingComment = (path) => !path.node.trailingComments?.length;
|
|
170
180
|
module.exports.noLeadingComment = (path) => !path.node.leadingComments?.length;
|
|
181
|
+
|
package/package.json
CHANGED