@putout/printer 8.27.0 → 8.29.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,16 @@
|
|
|
1
|
+
2024.05.02, v8.29.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 3286498 @putout/printer: ObjectExpression inside ArrayExpression tuple
|
|
5
|
+
|
|
6
|
+
2024.05.02, v8.28.0
|
|
7
|
+
|
|
8
|
+
fix:
|
|
9
|
+
- b1fd34d @putout/printer: tsTypeAliasDeclaration: indent
|
|
10
|
+
|
|
11
|
+
feature:
|
|
12
|
+
- ac26e2e @putout/printer: ArrayExpression: inside nested array call
|
|
13
|
+
|
|
1
14
|
2024.05.02, v8.27.0
|
|
2
15
|
|
|
3
16
|
feature:
|
package/lib/printer.d.ts
CHANGED
|
@@ -24,8 +24,8 @@ type Traverse = (input: types.Node) => void;
|
|
|
24
24
|
|
|
25
25
|
declare function MaybeIndent(condition: boolean): void;
|
|
26
26
|
declare namespace MaybeIndent {
|
|
27
|
-
type inc = () => void;
|
|
28
|
-
type dec = () => void;
|
|
27
|
+
type inc = (condition: boolean) => void;
|
|
28
|
+
type dec = (condition: boolean) => void;
|
|
29
29
|
|
|
30
30
|
export {
|
|
31
31
|
inc,
|
|
@@ -13,6 +13,7 @@ const {
|
|
|
13
13
|
|
|
14
14
|
const {parseComments} = require('../../comment/comment');
|
|
15
15
|
const {likeChain} = require('../member-expression/member-expressions');
|
|
16
|
+
const {isStringLiteral} = require('@putout/babel').types;
|
|
16
17
|
|
|
17
18
|
const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
|
|
18
19
|
const isLogical = (path) => path.get('argument').isLogicalExpression();
|
|
@@ -31,6 +32,25 @@ const isMemberExpressionCallee = ({parentPath}) => {
|
|
|
31
32
|
return likeChain(callee);
|
|
32
33
|
};
|
|
33
34
|
|
|
35
|
+
const isInsideCall = ({parentPath}) => parentPath.isCallExpression();
|
|
36
|
+
|
|
37
|
+
function isInsideNestedArrayCall({parentPath}) {
|
|
38
|
+
if (!parentPath.isArrayExpression())
|
|
39
|
+
return false;
|
|
40
|
+
|
|
41
|
+
if (!parentPath.parentPath.isArrayExpression())
|
|
42
|
+
return false;
|
|
43
|
+
|
|
44
|
+
return isInsideCall(parentPath.parentPath);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function isInsideNestedTuple({parentPath}) {
|
|
48
|
+
const {elements} = parentPath.parentPath.node;
|
|
49
|
+
const [first] = elements;
|
|
50
|
+
|
|
51
|
+
return isStringLiteral(first);
|
|
52
|
+
}
|
|
53
|
+
|
|
34
54
|
module.exports.ObjectExpression = (path, printer, semantics) => {
|
|
35
55
|
const {trailingComma} = semantics;
|
|
36
56
|
const {
|
|
@@ -39,7 +59,9 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
|
|
|
39
59
|
indent,
|
|
40
60
|
} = printer;
|
|
41
61
|
|
|
42
|
-
|
|
62
|
+
const insideNestedArrayCall = isInsideNestedArrayCall(path);
|
|
63
|
+
|
|
64
|
+
maybe.indent.inc(!insideNestedArrayCall);
|
|
43
65
|
|
|
44
66
|
const properties = path.get('properties');
|
|
45
67
|
const {length} = properties;
|
|
@@ -74,13 +96,10 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
|
|
|
74
96
|
}
|
|
75
97
|
|
|
76
98
|
maybe.indent(manyLines && noLeadingComment(property));
|
|
99
|
+
print(property);
|
|
77
100
|
|
|
78
|
-
if (property.isObjectMethod())
|
|
79
|
-
print(property);
|
|
101
|
+
if (property.isObjectMethod())
|
|
80
102
|
continue;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
print(property);
|
|
84
103
|
|
|
85
104
|
if (noTrailingComment(property) && !hasNextLeadingComment(property)) {
|
|
86
105
|
maybe.print.newline(manyLines);
|
|
@@ -88,9 +107,14 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
|
|
|
88
107
|
}
|
|
89
108
|
}
|
|
90
109
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
110
|
+
if (!insideNestedArrayCall) {
|
|
111
|
+
indent.dec();
|
|
112
|
+
maybe.indent(manyLines);
|
|
113
|
+
} else if (isInsideNestedTuple(path)) {
|
|
114
|
+
indent.dec();
|
|
115
|
+
indent();
|
|
116
|
+
indent.inc();
|
|
117
|
+
}
|
|
94
118
|
|
|
95
119
|
print('}');
|
|
96
120
|
maybe.print(parens, ')');
|
|
@@ -129,7 +153,7 @@ function isOneLine(path) {
|
|
|
129
153
|
const {length} = path.get('properties');
|
|
130
154
|
|
|
131
155
|
if (!length)
|
|
132
|
-
return
|
|
156
|
+
return ONE_LINE;
|
|
133
157
|
|
|
134
158
|
if (notLastArgInsideCall(path))
|
|
135
159
|
return ONE_LINE;
|
|
@@ -9,8 +9,13 @@ const {
|
|
|
9
9
|
const {markAfter} = require('../../mark');
|
|
10
10
|
const {maybeDeclare} = require('../../maybe/maybe-declare');
|
|
11
11
|
const isNextType = (a) => a.getNextSibling().isTSTypeAliasDeclaration();
|
|
12
|
+
const isNextExport = (a) => a.getNextSibling().isExportDeclaration();
|
|
12
13
|
|
|
13
14
|
module.exports.TSTypeAliasDeclaration = {
|
|
15
|
+
beforeIf: (path) => !path.parentPath.isExportDeclaration(),
|
|
16
|
+
before: (path, {indent}) => {
|
|
17
|
+
indent();
|
|
18
|
+
},
|
|
14
19
|
print: maybeDeclare((path, {print, maybe, store}) => {
|
|
15
20
|
const typeAnnotation = path.get('typeAnnotation');
|
|
16
21
|
const isConditional = typeAnnotation.isTSConditionalType();
|
|
@@ -40,7 +45,8 @@ module.exports.TSTypeAliasDeclaration = {
|
|
|
40
45
|
|
|
41
46
|
return !isNextType(path);
|
|
42
47
|
},
|
|
43
|
-
after(path, {print}) {
|
|
48
|
+
after(path, {print, maybe}) {
|
|
49
|
+
maybe.indent(isNextExport(path));
|
|
44
50
|
print.newline();
|
|
45
51
|
markAfter(path);
|
|
46
52
|
},
|
package/package.json
CHANGED