@putout/printer 8.27.0 → 8.28.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
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,
|
|
@@ -31,15 +31,25 @@ const isMemberExpressionCallee = ({parentPath}) => {
|
|
|
31
31
|
return likeChain(callee);
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
+
const isInsideCall = ({parentPath}) => parentPath.isCallExpression();
|
|
35
|
+
|
|
36
|
+
function isInsideNestedArrayCall({parentPath}) {
|
|
37
|
+
if (!parentPath.isArrayExpression())
|
|
38
|
+
return false;
|
|
39
|
+
|
|
40
|
+
if (!parentPath.parentPath.isArrayExpression())
|
|
41
|
+
return false;
|
|
42
|
+
|
|
43
|
+
return isInsideCall(parentPath.parentPath);
|
|
44
|
+
}
|
|
45
|
+
|
|
34
46
|
module.exports.ObjectExpression = (path, printer, semantics) => {
|
|
35
47
|
const {trailingComma} = semantics;
|
|
36
|
-
const {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
indent,
|
|
40
|
-
} = printer;
|
|
48
|
+
const {print, maybe} = printer;
|
|
49
|
+
|
|
50
|
+
const insideNestedArrayCall = isInsideNestedArrayCall(path);
|
|
41
51
|
|
|
42
|
-
indent.inc();
|
|
52
|
+
maybe.indent.inc(!insideNestedArrayCall);
|
|
43
53
|
|
|
44
54
|
const properties = path.get('properties');
|
|
45
55
|
const {length} = properties;
|
|
@@ -74,13 +84,10 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
|
|
|
74
84
|
}
|
|
75
85
|
|
|
76
86
|
maybe.indent(manyLines && noLeadingComment(property));
|
|
87
|
+
print(property);
|
|
77
88
|
|
|
78
|
-
if (property.isObjectMethod())
|
|
79
|
-
print(property);
|
|
89
|
+
if (property.isObjectMethod())
|
|
80
90
|
continue;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
print(property);
|
|
84
91
|
|
|
85
92
|
if (noTrailingComment(property) && !hasNextLeadingComment(property)) {
|
|
86
93
|
maybe.print.newline(manyLines);
|
|
@@ -88,9 +95,8 @@ module.exports.ObjectExpression = (path, printer, semantics) => {
|
|
|
88
95
|
}
|
|
89
96
|
}
|
|
90
97
|
|
|
91
|
-
indent.dec();
|
|
92
|
-
|
|
93
|
-
maybe.indent(manyLines);
|
|
98
|
+
maybe.indent.dec(!insideNestedArrayCall);
|
|
99
|
+
maybe.indent(manyLines && !insideNestedArrayCall);
|
|
94
100
|
|
|
95
101
|
print('}');
|
|
96
102
|
maybe.print(parens, ')');
|
|
@@ -129,7 +135,7 @@ function isOneLine(path) {
|
|
|
129
135
|
const {length} = path.get('properties');
|
|
130
136
|
|
|
131
137
|
if (!length)
|
|
132
|
-
return
|
|
138
|
+
return ONE_LINE;
|
|
133
139
|
|
|
134
140
|
if (notLastArgInsideCall(path))
|
|
135
141
|
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,8 +45,10 @@ 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
|
},
|
|
47
53
|
};
|
|
54
|
+
|
package/package.json
CHANGED