@putout/printer 1.8.4 → 1.8.5
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
package/README.md
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {isNext} = require('../is');
|
|
3
4
|
const isFirstStatement = (path) => path.get('body.0')?.isStatement();
|
|
4
5
|
|
|
5
6
|
module.exports.BlockStatement = (path, {indent, maybe, print}) => {
|
|
@@ -26,16 +27,17 @@ module.exports.BlockStatement = (path, {indent, maybe, print}) => {
|
|
|
26
27
|
print(',');
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (shouldAddNewline) {
|
|
30
|
+
if (shouldAddNewlineAfter(path)) {
|
|
32
31
|
print.newline();
|
|
33
32
|
}
|
|
34
33
|
};
|
|
35
34
|
|
|
36
|
-
function
|
|
35
|
+
function shouldAddNewlineAfter(path) {
|
|
37
36
|
const {parentPath} = path;
|
|
38
37
|
|
|
38
|
+
if (parentPath.isStatement() && !path.node.body.length && !isNext(parentPath))
|
|
39
|
+
return false;
|
|
40
|
+
|
|
39
41
|
if (isTry(path) || /FunctionExpression/.test(path.parentPath.type))
|
|
40
42
|
return false;
|
|
41
43
|
|
|
@@ -9,13 +9,13 @@ const {
|
|
|
9
9
|
markAfter,
|
|
10
10
|
} = require('../mark');
|
|
11
11
|
|
|
12
|
+
const isParentBlock = (path) => /Program|BlockStatement/.test(path.parentPath.type);
|
|
13
|
+
|
|
12
14
|
module.exports.VariableDeclaration = (path, {maybe, print}) => {
|
|
13
15
|
if (shouldAddNewlineBefore(path))
|
|
14
16
|
print.breakline();
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
maybe.indent(isParentBlock);
|
|
18
|
+
maybe.indent(isParentBlock(path));
|
|
19
19
|
print(`${path.node.kind} `);
|
|
20
20
|
print('__declarations.0.id');
|
|
21
21
|
|
|
@@ -23,22 +23,26 @@ module.exports.VariableDeclaration = (path, {maybe, print}) => {
|
|
|
23
23
|
|
|
24
24
|
maybe.print(initPath.node, ' = ');
|
|
25
25
|
print(initPath);
|
|
26
|
-
maybe.print(isParentBlock, ';');
|
|
27
|
-
|
|
26
|
+
maybe.print(isParentBlock(path), ';');
|
|
27
|
+
let wasNewline = false;
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
if (isParentBlock(path) && isNext(path)) {
|
|
30
|
+
print.newline();
|
|
31
|
+
wasNewline = true;
|
|
32
|
+
}
|
|
30
33
|
|
|
31
|
-
if (
|
|
32
|
-
print.linebreak();
|
|
34
|
+
if (shouldAddNewlineAfter(path)) {
|
|
35
|
+
maybe.print.linebreak(wasNewline);
|
|
36
|
+
maybe.print.newline(!wasNewline);
|
|
33
37
|
markAfter(path);
|
|
34
38
|
}
|
|
35
39
|
};
|
|
36
40
|
|
|
37
41
|
function shouldAddNewlineAfter(path) {
|
|
38
|
-
if (
|
|
42
|
+
if (!isNext(path) && path.parentPath.isBlockStatement())
|
|
39
43
|
return true;
|
|
40
44
|
|
|
41
|
-
if (
|
|
45
|
+
if (isLast(path))
|
|
42
46
|
return false;
|
|
43
47
|
|
|
44
48
|
if (isCoupleLines(path))
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -61,6 +61,7 @@ module.exports.tokenize = (ast, overrides = {}) => {
|
|
|
61
61
|
const maybeIndentDec = (a) => a && indent.dec();
|
|
62
62
|
const maybeNewline = (a) => a && newline();
|
|
63
63
|
const maybeBreakline = (a) => a && breakline();
|
|
64
|
+
const maybeLinebreak = (a) => a && linebreak();
|
|
64
65
|
let i = 0;
|
|
65
66
|
const incIndent = () => ++i;
|
|
66
67
|
const decIndent = () => --i;
|
|
@@ -168,6 +169,7 @@ module.exports.tokenize = (ast, overrides = {}) => {
|
|
|
168
169
|
assign(maybePrint, {
|
|
169
170
|
newline: maybeNewline,
|
|
170
171
|
breakline: maybeBreakline,
|
|
172
|
+
linebreak: maybeLinebreak,
|
|
171
173
|
});
|
|
172
174
|
|
|
173
175
|
assign(printer.maybe, {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.5",
|
|
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",
|