@putout/printer 1.110.0 → 1.112.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
|
+
2023.05.24, v1.112.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 4c59494 @putout/printer: IfStatement -> ForOfStatement -> ExpressionStatement: newlines
|
|
5
|
+
|
|
6
|
+
2023.05.24, v1.111.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- c806c40 @putout/printer: ExpressionStatement inside IfStatement consequent when alternate exists: add "\n"
|
|
10
|
+
|
|
1
11
|
2023.05.23, v1.110.0
|
|
2
12
|
|
|
3
13
|
feature:
|
package/README.md
CHANGED
|
@@ -121,7 +121,8 @@ Default options produce:
|
|
|
121
121
|
|
|
122
122
|
```js
|
|
123
123
|
if (a > 3)
|
|
124
|
-
console.log('ok');
|
|
124
|
+
console.log('ok');
|
|
125
|
+
else
|
|
125
126
|
console.log('not ok');
|
|
126
127
|
```
|
|
127
128
|
|
|
@@ -142,7 +143,8 @@ And have minified code:
|
|
|
142
143
|
|
|
143
144
|
```js
|
|
144
145
|
if (a > 3)
|
|
145
|
-
console.log('ok');
|
|
146
|
+
console.log('ok');
|
|
147
|
+
else
|
|
146
148
|
console.log('not ok');
|
|
147
149
|
```
|
|
148
150
|
|
package/lib/tokenize/is.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {isMarkedAfter} = require('./mark');
|
|
4
|
-
|
|
5
3
|
const {
|
|
6
4
|
isStringLiteral,
|
|
7
5
|
isIdentifier,
|
|
@@ -20,9 +18,6 @@ const isNext = (path) => {
|
|
|
20
18
|
if (!next.node)
|
|
21
19
|
return false;
|
|
22
20
|
|
|
23
|
-
if (isMarkedAfter(path.get('body')))
|
|
24
|
-
return false;
|
|
25
|
-
|
|
26
21
|
return !next.isEmptyStatement();
|
|
27
22
|
};
|
|
28
23
|
|
|
@@ -12,8 +12,18 @@ const {
|
|
|
12
12
|
isCoupleLines,
|
|
13
13
|
} = require('../is');
|
|
14
14
|
|
|
15
|
+
const isBeforeElse = (path) => {
|
|
16
|
+
if (!path.parentPath.isIfStatement())
|
|
17
|
+
return false;
|
|
18
|
+
|
|
19
|
+
if (path !== path.parentPath.get('consequent'))
|
|
20
|
+
return false;
|
|
21
|
+
|
|
22
|
+
return Boolean(path.parentPath.node.alternate);
|
|
23
|
+
};
|
|
24
|
+
|
|
15
25
|
const satisfyAfter = satisfy([
|
|
16
|
-
|
|
26
|
+
isNotLastOrParentLast,
|
|
17
27
|
isParentBlock,
|
|
18
28
|
isNext,
|
|
19
29
|
isNextUp,
|
|
@@ -31,6 +41,9 @@ module.exports.ExpressionStatement = {
|
|
|
31
41
|
print('__expression');
|
|
32
42
|
print(';');
|
|
33
43
|
|
|
44
|
+
if (!isNext(path))
|
|
45
|
+
return;
|
|
46
|
+
|
|
34
47
|
if (shouldBreakline(path)) {
|
|
35
48
|
print.newline();
|
|
36
49
|
maybe.indent(isNext(path) && noTrailingComment(path));
|
|
@@ -44,6 +57,9 @@ module.exports.ExpressionStatement = {
|
|
|
44
57
|
if (hasTrailingComment(path) && isLast(path))
|
|
45
58
|
return true;
|
|
46
59
|
|
|
60
|
+
if (isBeforeElse(path))
|
|
61
|
+
return true;
|
|
62
|
+
|
|
47
63
|
return false;
|
|
48
64
|
},
|
|
49
65
|
after(path, {print, maybe, store}) {
|
|
@@ -61,17 +77,11 @@ module.exports.ExpressionStatement = {
|
|
|
61
77
|
};
|
|
62
78
|
|
|
63
79
|
function isNotLastBody(path) {
|
|
64
|
-
if (!isNext(path) && isParentBlock(path))
|
|
65
|
-
return false;
|
|
66
|
-
|
|
67
|
-
if (isLast(path) || isParentLast(path))
|
|
68
|
-
return false;
|
|
69
|
-
|
|
70
80
|
return path.parentPath.get('body') === path;
|
|
71
81
|
}
|
|
72
82
|
|
|
73
|
-
function
|
|
74
|
-
return
|
|
83
|
+
function isNotLastOrParentLast(path) {
|
|
84
|
+
return !(isLast(path) || isParentLast(path));
|
|
75
85
|
}
|
|
76
86
|
|
|
77
87
|
function isNextUp(path) {
|
|
@@ -15,6 +15,11 @@ const {
|
|
|
15
15
|
|
|
16
16
|
module.exports.ForOfStatement = {
|
|
17
17
|
beforeIf(path) {
|
|
18
|
+
const {parentPath} = path;
|
|
19
|
+
|
|
20
|
+
if (!parentPath.isBlockStatement() && parentPath.isStatement())
|
|
21
|
+
return false;
|
|
22
|
+
|
|
18
23
|
return !isFirst(path) && !hasPrevNewline(path);
|
|
19
24
|
},
|
|
20
25
|
before(path, {print}) {
|
package/package.json
CHANGED