@putout/printer 1.5.3 → 1.5.4
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 +5 -0
- package/lib/tokenize/expressions/call-expression.js +1 -1
- package/lib/tokenize/expressions/class-declaration.js +1 -1
- package/lib/tokenize/statements/expression-statement.js +3 -2
- package/lib/tokenize/statements/try-statements.js +1 -1
- package/lib/tokenize/statements/variable-declaration.js +2 -3
- package/lib/tokenize/tokenize.js +10 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -11,7 +11,7 @@ module.exports.CallExpression = (path, {indent, print, maybe}) => {
|
|
|
11
11
|
const isParentCall = toLong(path) && path.parentPath.isCallExpression();
|
|
12
12
|
|
|
13
13
|
if (shouldAddNewLine(path) && !isMarkedParentBefore(path) && !isMarkedPrevAfter(path.parentPath))
|
|
14
|
-
print.
|
|
14
|
+
print.breakline();
|
|
15
15
|
|
|
16
16
|
print(path.get('callee'));
|
|
17
17
|
print('(');
|
|
@@ -7,9 +7,9 @@ const {
|
|
|
7
7
|
} = require('../mark');
|
|
8
8
|
const {isNext} = require('../is');
|
|
9
9
|
|
|
10
|
-
module.exports.ExpressionStatement = (path, {write, indent, traverse}) => {
|
|
10
|
+
module.exports.ExpressionStatement = (path, {write, indent, traverse, print}) => {
|
|
11
11
|
if (isCoupleLinesExpression(path) && !isFirst(path) && shouldAddNewLine(path) && !isMarkedPrevAfter(path)) {
|
|
12
|
-
|
|
12
|
+
print.breakline();
|
|
13
13
|
markBefore(path);
|
|
14
14
|
}
|
|
15
15
|
|
|
@@ -62,3 +62,4 @@ function shouldAddNewLine(path) {
|
|
|
62
62
|
|
|
63
63
|
return true;
|
|
64
64
|
}
|
|
65
|
+
|
|
@@ -13,7 +13,7 @@ const isNextAssign = (path) => {
|
|
|
13
13
|
|
|
14
14
|
module.exports.VariableDeclaration = (path, {maybe, print}) => {
|
|
15
15
|
if (!isFirst(path) && shouldAddNewLine(path) && !hasPrevNewline(path))
|
|
16
|
-
print.
|
|
16
|
+
print.breakline();
|
|
17
17
|
|
|
18
18
|
const isParentBlock = /Program|BlockStatement/.test(path.parentPath.type);
|
|
19
19
|
|
|
@@ -31,8 +31,7 @@ module.exports.VariableDeclaration = (path, {maybe, print}) => {
|
|
|
31
31
|
const is = isNext(path) && isCoupleLines(path) && !isNextAssign(path);
|
|
32
32
|
|
|
33
33
|
if (is) {
|
|
34
|
-
print.
|
|
35
|
-
print.newline();
|
|
34
|
+
print.linebreak();
|
|
36
35
|
markAfter(path);
|
|
37
36
|
}
|
|
38
37
|
};
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -37,7 +37,7 @@ module.exports.tokenize = (ast) => {
|
|
|
37
37
|
const maybeIndentInc = (a) => a && indent.inc();
|
|
38
38
|
const maybeIndentDec = (a) => a && indent.dec();
|
|
39
39
|
const maybeNewline = (a) => a && newline();
|
|
40
|
-
const
|
|
40
|
+
const maybeBreakline = (a) => a && breakline();
|
|
41
41
|
|
|
42
42
|
let i = 0;
|
|
43
43
|
const incIndent = () => ++i;
|
|
@@ -55,6 +55,13 @@ module.exports.tokenize = (ast) => {
|
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
const linebreak = () => {
|
|
58
|
+
tokens.push({
|
|
59
|
+
type: TYPES.NEWLINE,
|
|
60
|
+
value: `${printIndent(i)}\n`,
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const breakline = () => {
|
|
58
65
|
tokens.push({
|
|
59
66
|
type: TYPES.NEWLINE,
|
|
60
67
|
value: `\n${printIndent(i)}`,
|
|
@@ -72,6 +79,7 @@ module.exports.tokenize = (ast) => {
|
|
|
72
79
|
indent,
|
|
73
80
|
newline,
|
|
74
81
|
linebreak,
|
|
82
|
+
breakline,
|
|
75
83
|
});
|
|
76
84
|
const print = (maybeLine) => {
|
|
77
85
|
if (isString(maybeLine))
|
|
@@ -98,7 +106,7 @@ module.exports.tokenize = (ast) => {
|
|
|
98
106
|
assign(print, write);
|
|
99
107
|
assign(maybePrint, {
|
|
100
108
|
newline: maybeNewline,
|
|
101
|
-
|
|
109
|
+
breakline: maybeBreakline,
|
|
102
110
|
});
|
|
103
111
|
|
|
104
112
|
const printer = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
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",
|