@putout/printer 11.11.0 → 11.13.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,13 @@
|
|
|
1
|
+
2024.12.31, v11.13.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 99c7207 @putout/printer: TSUnionType: always add parens when inside TSArrayType (benjamn/recast#1416)
|
|
5
|
+
|
|
6
|
+
2024.12.25, v11.12.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 516a7ae @putout/printer: IfStatement: newline when empty and last inside FunctionDeclaration
|
|
10
|
+
|
|
1
11
|
2024.12.22, v11.11.0
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {types} = require('@putout/babel');
|
|
4
|
+
|
|
3
5
|
const {markAfter} = require('../../mark');
|
|
4
6
|
const {exists, isNext} = require('../../is');
|
|
5
7
|
|
|
8
|
+
const {
|
|
9
|
+
isBlockStatement,
|
|
10
|
+
isFunctionDeclaration,
|
|
11
|
+
} = types;
|
|
12
|
+
|
|
6
13
|
const isInside = ({parentPath}) => !parentPath.parentPath.isProgram();
|
|
7
14
|
const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
|
|
8
15
|
|
|
@@ -16,6 +23,21 @@ const isInsideNestedBody = ({parentPath}) => {
|
|
|
16
23
|
const isInsideIf = (path) => path.parentPath.parentPath?.isIfStatement();
|
|
17
24
|
const isEmptyBody = (path) => !path.node.body.length;
|
|
18
25
|
|
|
26
|
+
const isLastEmptyInsideBody = (path) => {
|
|
27
|
+
const {parentPath} = path;
|
|
28
|
+
|
|
29
|
+
if (!isBlockStatement(parentPath))
|
|
30
|
+
return false;
|
|
31
|
+
|
|
32
|
+
if (!isBlockStatement(path.node.consequent))
|
|
33
|
+
return false;
|
|
34
|
+
|
|
35
|
+
if (path.node.consequent.body.length)
|
|
36
|
+
return false;
|
|
37
|
+
|
|
38
|
+
return isFunctionDeclaration(path.parentPath.parentPath);
|
|
39
|
+
};
|
|
40
|
+
|
|
19
41
|
module.exports.IfStatement = {
|
|
20
42
|
print: (path, {indent, print, maybe, write, traverse}) => {
|
|
21
43
|
const partOfAlternate = path.parentPath.get('alternate');
|
|
@@ -79,6 +101,9 @@ module.exports.IfStatement = {
|
|
|
79
101
|
|
|
80
102
|
if (path === partOfAlternate && isInside(path))
|
|
81
103
|
print.newline();
|
|
104
|
+
|
|
105
|
+
if (isLastEmptyInsideBody(path))
|
|
106
|
+
print.newline();
|
|
82
107
|
},
|
|
83
108
|
afterSatisfy: () => [isNext],
|
|
84
109
|
after: (path, {print}) => {
|
|
@@ -3,14 +3,19 @@
|
|
|
3
3
|
const {maybeParens} = require('../../maybe/maybe-parens');
|
|
4
4
|
const insideTypeDeclaration = ({parentPath}) => parentPath.isTSTypeAliasDeclaration();
|
|
5
5
|
|
|
6
|
-
module.exports.TSUnionType = maybeParens(
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
6
|
+
module.exports.TSUnionType = maybeParens({
|
|
7
|
+
condition: (path) => {
|
|
8
|
+
return path.parentPath.isTSArrayType();
|
|
9
|
+
},
|
|
10
|
+
print: (path, printer, {maxTypesInOneLine}) => {
|
|
11
|
+
const types = path.get('types');
|
|
12
|
+
const {length} = types;
|
|
13
|
+
|
|
14
|
+
if (!insideTypeDeclaration(path) || length <= maxTypesInOneLine)
|
|
15
|
+
printInOneLine(types, printer);
|
|
16
|
+
else
|
|
17
|
+
printInCoupleLines(types, printer);
|
|
18
|
+
},
|
|
14
19
|
});
|
|
15
20
|
|
|
16
21
|
function printInOneLine(types, {traverse, write}) {
|
package/package.json
CHANGED