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