@putout/printer 1.16.2 → 1.17.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,13 +3,20 @@
|
|
|
3
3
|
module.exports.BinaryExpression = BinaryExpression;
|
|
4
4
|
module.exports.LogicalExpression = BinaryExpression;
|
|
5
5
|
|
|
6
|
-
const isLogical = (path) =>
|
|
6
|
+
const isLogical = (main, path) => {
|
|
7
|
+
const is = path.isLogicalExpression();
|
|
8
|
+
|
|
9
|
+
if (!is)
|
|
10
|
+
return false;
|
|
11
|
+
|
|
12
|
+
return main.node.operator !== path.node.operator;
|
|
13
|
+
};
|
|
7
14
|
|
|
8
15
|
function BinaryExpression(path, {write, traverse, maybe}) {
|
|
9
16
|
const left = path.get('left');
|
|
10
17
|
const right = path.get('right');
|
|
11
|
-
const isLeft = isLogical(left);
|
|
12
|
-
const isRight = isLogical(right);
|
|
18
|
+
const isLeft = isLogical(path, left);
|
|
19
|
+
const isRight = isLogical(path, right);
|
|
13
20
|
|
|
14
21
|
maybe.write(isLeft, '(');
|
|
15
22
|
traverse(left);
|
|
@@ -32,21 +32,21 @@ function printUnary(path, name, {print}) {
|
|
|
32
32
|
}
|
|
33
33
|
const isWord = (a) => /delete|typeof/.test(a);
|
|
34
34
|
|
|
35
|
-
function unaryExpression(path, {
|
|
35
|
+
function unaryExpression(path, {maybe, traverse}) {
|
|
36
36
|
const {
|
|
37
37
|
prefix,
|
|
38
38
|
operator,
|
|
39
39
|
} = path.node;
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
const argPath = path.get('argument');
|
|
42
|
+
const round = argPath.isBinaryExpression();
|
|
43
43
|
|
|
44
|
-
maybe.print(
|
|
45
|
-
operator,
|
|
46
|
-
), ' ');
|
|
44
|
+
maybe.print(prefix, operator);
|
|
47
45
|
|
|
48
|
-
print('
|
|
46
|
+
maybe.print(isWord(operator), ' ');
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
48
|
+
maybe.print(round, '(');
|
|
49
|
+
traverse(argPath);
|
|
50
|
+
maybe.print(round, ')');
|
|
51
|
+
maybe.print(!prefix, operator);
|
|
52
52
|
}
|
package/lib/tokenize/is.js
CHANGED
|
@@ -15,7 +15,7 @@ const isNext = (path) => {
|
|
|
15
15
|
const isNextParent = (path) => isNext(path.parentPath);
|
|
16
16
|
const isLast = (path) => isParentProgram(path) && !isNext(path);
|
|
17
17
|
|
|
18
|
-
module.exports.isFirst = (path) => path.node === path.parentPath.node.body[0];
|
|
18
|
+
module.exports.isFirst = (path) => path.node === path.parentPath.node.body?.[0];
|
|
19
19
|
module.exports.isPrevBody = (path) => path.getPrevSibling().isBlockStatement();
|
|
20
20
|
module.exports.isNext = isNext;
|
|
21
21
|
module.exports.isNextParent = isNextParent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.17.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",
|