@putout/printer 8.26.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 +13 -0
- package/lib/printer.d.ts +2 -2
- package/lib/tokenize/expressions/array-expression/array-expression.js +15 -1
- package/lib/tokenize/expressions/object-expression/object-expression.js +21 -15
- package/lib/tokenize/is.js +1 -1
- package/lib/tokenize/typescript/type/ts-type-alias-declaration.js +8 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
2024.05.02, v8.28.0
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- b1fd34d @putout/printer: tsTypeAliasDeclaration: indent
|
|
5
|
+
|
|
6
|
+
feature:
|
|
7
|
+
- ac26e2e @putout/printer: ArrayExpression: inside nested array call
|
|
8
|
+
|
|
9
|
+
2024.05.02, v8.27.0
|
|
10
|
+
|
|
11
|
+
feature:
|
|
12
|
+
- 20b3eac @putout/printer: ArrayExpression: nested array: space
|
|
13
|
+
|
|
1
14
|
2024.05.01, v8.26.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,
|
|
@@ -26,6 +26,7 @@ const {
|
|
|
26
26
|
isSpreadElement,
|
|
27
27
|
isStringLiteral,
|
|
28
28
|
isIdentifier,
|
|
29
|
+
isArrayExpression,
|
|
29
30
|
} = types;
|
|
30
31
|
|
|
31
32
|
const isNextString = (path) => isStringLiteral(path.getNextSibling());
|
|
@@ -35,7 +36,20 @@ const isNextObject = (a) => a.getNextSibling().isObjectExpression();
|
|
|
35
36
|
const isPrevObject = (a) => a.getPrevSibling().isObjectExpression();
|
|
36
37
|
const isObjectAfterSpread = (a) => isSpreadElement(a) && isNextObject(a) && !isPrevObject(a);
|
|
37
38
|
const isObjectAfterIdentifier = (a) => isIdentifier(a) && isNextObject(a) && !isPrevObject(a);
|
|
38
|
-
|
|
39
|
+
|
|
40
|
+
const isObjectAfterArray = (a) => {
|
|
41
|
+
if (!isArrayExpression(a))
|
|
42
|
+
return false;
|
|
43
|
+
|
|
44
|
+
return isNextObject(a);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const isObjectAfterSimple = (a) => {
|
|
48
|
+
if (isObjectAfterArray(a))
|
|
49
|
+
return true;
|
|
50
|
+
|
|
51
|
+
return isObjectAfterSpread(a) || isObjectAfterIdentifier(a);
|
|
52
|
+
};
|
|
39
53
|
|
|
40
54
|
const isSpreadBeforeObject = (a) => {
|
|
41
55
|
if (!a.isObjectExpression())
|
|
@@ -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;
|
package/lib/tokenize/is.js
CHANGED
|
@@ -64,7 +64,7 @@ function isStringAndIdentifier([a, b]) {
|
|
|
64
64
|
}
|
|
65
65
|
|
|
66
66
|
module.exports.isSimpleAndEmptyObject = ([a, b]) => {
|
|
67
|
-
if (!isIdentifier(a) && !isSpreadElement(a))
|
|
67
|
+
if (!isIdentifier(a) && !isSpreadElement(a) && !isArrayExpression(a))
|
|
68
68
|
return false;
|
|
69
69
|
|
|
70
70
|
if (!isObjectExpression(b))
|
|
@@ -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