@putout/printer 1.14.2 → 1.14.3
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
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const {isLast} = require('../is');
|
|
4
4
|
|
|
5
5
|
module.exports.ForStatement = {
|
|
6
|
-
print(path, {print, maybe
|
|
6
|
+
print(path, {print, maybe}) {
|
|
7
7
|
const {
|
|
8
8
|
test,
|
|
9
9
|
update,
|
|
@@ -24,10 +24,12 @@ module.exports.ForStatement = {
|
|
|
24
24
|
print(' ');
|
|
25
25
|
print('__body');
|
|
26
26
|
} else {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const is = !path.get('body').isEmptyStatement();
|
|
28
|
+
|
|
29
|
+
maybe.print.newline(is);
|
|
30
|
+
maybe.indent.inc(is);
|
|
29
31
|
print('__body');
|
|
30
|
-
indent.dec();
|
|
32
|
+
maybe.indent.dec(is);
|
|
31
33
|
}
|
|
32
34
|
},
|
|
33
35
|
after(path, {print}) {
|
|
@@ -3,49 +3,59 @@
|
|
|
3
3
|
const {hasPrevNewline, markAfter} = require('../mark');
|
|
4
4
|
const {isFirst} = require('../is');
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
|
|
7
|
+
|
|
8
|
+
module.exports.IfStatement = {
|
|
9
|
+
before: (path, {print}) => {
|
|
8
10
|
print.linebreak();
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
indent
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
11
|
+
},
|
|
12
|
+
beforeIf: shouldAddNewlineBefore,
|
|
13
|
+
print: (path, {indent, print, maybe}) => {
|
|
14
|
+
indent();
|
|
15
|
+
print('if (');
|
|
16
|
+
print('__test');
|
|
17
|
+
print(')');
|
|
18
|
+
|
|
19
|
+
const consequent = path.get('consequent');
|
|
20
|
+
const alternate = path.get('alternate');
|
|
21
|
+
|
|
22
|
+
if (consequent.isBlockStatement()) {
|
|
23
|
+
print(' ');
|
|
24
|
+
print(consequent);
|
|
25
|
+
} else {
|
|
26
|
+
const is = !isEmptyConsequent(path);
|
|
27
|
+
|
|
28
|
+
maybe.print.newline(is);
|
|
29
|
+
maybe.indent.inc(is);
|
|
30
|
+
print(consequent);
|
|
31
|
+
maybe.indent.dec(is);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (alternate.isBlockStatement()) {
|
|
35
|
+
print(' else ');
|
|
36
|
+
print(alternate);
|
|
37
|
+
} else if (alternate.node) {
|
|
38
|
+
print.breakline();
|
|
39
|
+
print('else');
|
|
40
|
+
print.newline();
|
|
41
|
+
indent.inc();
|
|
42
|
+
print(alternate);
|
|
43
|
+
indent.dec();
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
afterIf: (path) => {
|
|
47
|
+
const next = path.getNextSibling();
|
|
48
|
+
|
|
49
|
+
if (!next.node || next.isExpressionStatement() || next.isReturnStatement())
|
|
50
|
+
return false;
|
|
51
|
+
|
|
52
|
+
return true;
|
|
53
|
+
},
|
|
54
|
+
after: (path, {print}) => {
|
|
55
|
+
print.indent();
|
|
35
56
|
print.newline();
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
indent.dec();
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const next = path.getNextSibling();
|
|
42
|
-
|
|
43
|
-
if (!next.node || next.isExpressionStatement() || next.isReturnStatement())
|
|
44
|
-
return;
|
|
45
|
-
|
|
46
|
-
print.indent();
|
|
47
|
-
print.newline();
|
|
48
|
-
markAfter(path);
|
|
57
|
+
markAfter(path);
|
|
58
|
+
},
|
|
49
59
|
};
|
|
50
60
|
|
|
51
61
|
function shouldAddNewlineBefore(path) {
|
|
@@ -35,7 +35,9 @@ module.exports = {
|
|
|
35
35
|
path.get('body').forEach(print);
|
|
36
36
|
print.newline();
|
|
37
37
|
},
|
|
38
|
-
EmptyStatement({}) {
|
|
38
|
+
EmptyStatement(path, {write}) {
|
|
39
|
+
write(';');
|
|
40
|
+
},
|
|
39
41
|
InterpreterDirective(path, {print}) {
|
|
40
42
|
print(`#!${path.node.value}`);
|
|
41
43
|
print.newline();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.14.
|
|
3
|
+
"version": "1.14.3",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",
|