@putout/printer 6.11.5 → 6.12.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
|
@@ -9,6 +9,7 @@ const isTwoStringsTupleAndParentIsArrayWithFirstArrayElement = (path) => {
|
|
|
9
9
|
|
|
10
10
|
return isParentIsArrayWithFirstArrayElement(path);
|
|
11
11
|
};
|
|
12
|
+
|
|
12
13
|
const isLotsOfElementsFirstNotObject = (path) => {
|
|
13
14
|
const {elements} = path.node;
|
|
14
15
|
const [first] = elements;
|
|
@@ -291,4 +292,3 @@ module.exports.isCurrentNewLine = (path) => {
|
|
|
291
292
|
|
|
292
293
|
return !path.isObjectExpression();
|
|
293
294
|
};
|
|
294
|
-
|
|
@@ -5,6 +5,7 @@ const {
|
|
|
5
5
|
isParentProgram,
|
|
6
6
|
isLast,
|
|
7
7
|
exists,
|
|
8
|
+
satisfy,
|
|
8
9
|
} = require('../../is');
|
|
9
10
|
|
|
10
11
|
const {
|
|
@@ -12,6 +13,8 @@ const {
|
|
|
12
13
|
isObjectMethod,
|
|
13
14
|
isFunctionDeclaration,
|
|
14
15
|
isExportDeclaration,
|
|
16
|
+
isDoWhileStatement,
|
|
17
|
+
isBlockStatement,
|
|
15
18
|
} = require('@putout/babel').types;
|
|
16
19
|
|
|
17
20
|
const {markAfter} = require('../../mark');
|
|
@@ -77,35 +80,62 @@ module.exports.BlockStatement = {
|
|
|
77
80
|
},
|
|
78
81
|
};
|
|
79
82
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
if (parentPath.isDoWhileStatement())
|
|
83
|
+
const isTopLevelWithNoNext = (path) => {
|
|
84
|
+
if (isNext(path))
|
|
84
85
|
return false;
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
return !isNext(path.parentPath) && isParentProgram(path.parentPath);
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const isInsideIfWithoutElseInsideFn = (path) => {
|
|
91
|
+
return parentIfWithoutElse(path) && path.find(isMethodOrArrow);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const isEmptyBodyNoNext = (path) => {
|
|
95
|
+
const {parentPath} = path;
|
|
96
|
+
return parentPath.isStatement() && !path.node.body.length && !isNext(parentPath);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const isLooksLikeInsideFn = ({parentPath}) => {
|
|
100
|
+
return /FunctionExpression/.test(parentPath.type);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const NEWLINE = true;
|
|
104
|
+
const NO_NEWLINE = false;
|
|
105
|
+
|
|
106
|
+
const isInsideDoWhile = ({parentPath}) => isDoWhileStatement(parentPath);
|
|
107
|
+
const isInsideBlock = ({parentPath}) => isBlockStatement(parentPath);
|
|
108
|
+
|
|
109
|
+
const isNoNewline = satisfy([
|
|
110
|
+
isInsideDoWhile,
|
|
111
|
+
isTopLevelWithNoNext,
|
|
112
|
+
insideIfWithNoBody,
|
|
113
|
+
]);
|
|
114
|
+
|
|
115
|
+
function shouldAddNewlineAfter(path) {
|
|
116
|
+
if (isInsideBlock(path))
|
|
117
|
+
return NEWLINE;
|
|
88
118
|
|
|
89
|
-
if (
|
|
90
|
-
return
|
|
119
|
+
if (isNoNewline(path))
|
|
120
|
+
return NO_NEWLINE;
|
|
91
121
|
|
|
92
|
-
if (
|
|
93
|
-
return
|
|
122
|
+
if (isInsideIfWithoutElseInsideFn(path))
|
|
123
|
+
return NEWLINE;
|
|
94
124
|
|
|
95
|
-
if (
|
|
96
|
-
return
|
|
125
|
+
if (isEmptyBodyNoNext(path))
|
|
126
|
+
return NO_NEWLINE;
|
|
97
127
|
|
|
98
|
-
if (
|
|
99
|
-
return
|
|
128
|
+
if (isTry(path))
|
|
129
|
+
return NO_NEWLINE;
|
|
100
130
|
|
|
101
|
-
if (
|
|
102
|
-
return
|
|
131
|
+
if (isLooksLikeInsideFn(path))
|
|
132
|
+
return NO_NEWLINE;
|
|
103
133
|
|
|
104
134
|
if (isLast(path))
|
|
105
|
-
return
|
|
135
|
+
return NO_NEWLINE;
|
|
106
136
|
|
|
107
137
|
if (isExportFunction(path))
|
|
108
|
-
return
|
|
138
|
+
return NO_NEWLINE;
|
|
109
139
|
|
|
110
140
|
return !isNextIfAlternate(path);
|
|
111
141
|
}
|
package/package.json
CHANGED