@putout/printer 1.14.3 → 1.15.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
|
@@ -3,10 +3,24 @@
|
|
|
3
3
|
module.exports.BinaryExpression = BinaryExpression;
|
|
4
4
|
module.exports.LogicalExpression = BinaryExpression;
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
const isLogical = (path) => path.isLogicalExpression();
|
|
7
|
+
|
|
8
|
+
function BinaryExpression(path, {write, traverse, maybe}) {
|
|
9
|
+
const left = path.get('left');
|
|
10
|
+
const right = path.get('right');
|
|
11
|
+
const isLeft = isLogical(left);
|
|
12
|
+
const isRight = isLogical(right);
|
|
13
|
+
|
|
14
|
+
maybe.write(isLeft, '(');
|
|
15
|
+
traverse(left);
|
|
16
|
+
maybe.write(isLeft, ')');
|
|
17
|
+
|
|
18
|
+
write.space();
|
|
19
|
+
write(path.node.operator);
|
|
20
|
+
write.space();
|
|
21
|
+
|
|
22
|
+
maybe.write(isRight, '(');
|
|
23
|
+
traverse(right);
|
|
24
|
+
maybe.write(isRight, ')');
|
|
12
25
|
}
|
|
26
|
+
|
|
@@ -63,7 +63,7 @@ function shouldBreakline(path) {
|
|
|
63
63
|
}
|
|
64
64
|
|
|
65
65
|
function shouldAddNewLineAfter(path) {
|
|
66
|
-
if (isLast(path) || isParentLast(path))
|
|
66
|
+
if (!isParentBlock(path) && (isLast(path) || isParentLast(path)))
|
|
67
67
|
return false;
|
|
68
68
|
|
|
69
69
|
if (isParentBlock(path) && !isParentProgram(path))
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {round} = Math;
|
|
4
|
+
|
|
3
5
|
const fullstore = require('fullstore');
|
|
4
6
|
const isObject = (a) => a && typeof a === 'object';
|
|
5
7
|
const babelTraverse = require('@babel/traverse').default;
|
|
@@ -76,6 +78,7 @@ module.exports.tokenize = (ast, overrides = {}) => {
|
|
|
76
78
|
const maybeNewline = (a) => a && newline();
|
|
77
79
|
const maybeBreakline = (a) => a && breakline();
|
|
78
80
|
const maybeLinebreak = (a) => a && linebreak();
|
|
81
|
+
const maybeWrite = (a, b) => a && write(b);
|
|
79
82
|
let i = 0;
|
|
80
83
|
const incIndent = () => ++i;
|
|
81
84
|
const decIndent = () => --i;
|
|
@@ -125,12 +128,14 @@ module.exports.tokenize = (ast, overrides = {}) => {
|
|
|
125
128
|
newline,
|
|
126
129
|
linebreak,
|
|
127
130
|
breakline,
|
|
131
|
+
space,
|
|
128
132
|
});
|
|
129
133
|
|
|
130
134
|
const maybe = {
|
|
131
135
|
indent: maybeIndent,
|
|
132
136
|
markBefore: maybeMarkBefore,
|
|
133
137
|
markAfter: maybeMarkAfter,
|
|
138
|
+
write: maybeWrite,
|
|
134
139
|
};
|
|
135
140
|
|
|
136
141
|
assign(maybe.indent, {
|
|
@@ -173,6 +178,7 @@ module.exports.tokenize = (ast, overrides = {}) => {
|
|
|
173
178
|
|
|
174
179
|
assign(print, write, {
|
|
175
180
|
space,
|
|
181
|
+
round,
|
|
176
182
|
});
|
|
177
183
|
|
|
178
184
|
assign(printer, {
|
|
@@ -217,14 +223,23 @@ const createPrint = (path, {traverse, write}) => (maybeLine) => {
|
|
|
217
223
|
if (maybeLine === path)
|
|
218
224
|
return null;
|
|
219
225
|
|
|
226
|
+
const computed = computePath(path, maybeLine);
|
|
227
|
+
|
|
228
|
+
if (isObject(computed))
|
|
229
|
+
return traverse(computed);
|
|
230
|
+
|
|
231
|
+
return write(computed);
|
|
232
|
+
};
|
|
233
|
+
const computePath = (path, maybeLine) => {
|
|
220
234
|
if (isString(maybeLine) && maybeLine.startsWith(GET))
|
|
221
|
-
return
|
|
235
|
+
return get(
|
|
222
236
|
path,
|
|
223
237
|
maybeLine,
|
|
224
|
-
)
|
|
238
|
+
);
|
|
225
239
|
|
|
226
240
|
if (isObject(maybeLine))
|
|
227
|
-
return
|
|
241
|
+
return maybeLine;
|
|
228
242
|
|
|
229
|
-
return
|
|
243
|
+
return maybeLine;
|
|
230
244
|
};
|
|
245
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
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",
|