@putout/printer 11.3.0 → 11.4.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
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {maybeParens} = require('../../maybe/maybe-parens');
|
|
4
4
|
const {chain, isRootOk} = require('./chain');
|
|
5
5
|
|
|
6
|
-
module.exports.LogicalExpression = {
|
|
6
|
+
module.exports.LogicalExpression = maybeParens({
|
|
7
7
|
condition(path) {
|
|
8
|
-
if (
|
|
8
|
+
if (path.parentPath.isUnaryExpression())
|
|
9
9
|
return true;
|
|
10
10
|
|
|
11
11
|
return path.parentPath.isAwaitExpression();
|
|
12
12
|
},
|
|
13
|
-
before(path, {print}) {
|
|
14
|
-
print('(');
|
|
15
|
-
},
|
|
16
13
|
print(path, {print, maybe}, semantics) {
|
|
17
14
|
print('__left');
|
|
18
15
|
|
|
@@ -26,10 +23,7 @@ module.exports.LogicalExpression = {
|
|
|
26
23
|
print.space();
|
|
27
24
|
print('__right');
|
|
28
25
|
},
|
|
29
|
-
|
|
30
|
-
print(')');
|
|
31
|
-
},
|
|
32
|
-
};
|
|
26
|
+
});
|
|
33
27
|
|
|
34
28
|
function isNewLine(path, semantics) {
|
|
35
29
|
const [root, count] = chain(path);
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const isFn = (a) => typeof a === 'function';
|
|
3
4
|
const isParens = (path) => path.node.extra?.parenthesized;
|
|
4
5
|
|
|
5
6
|
module.exports.isParens = isParens;
|
|
6
|
-
module.exports.maybeParens = (print) =>
|
|
7
|
+
module.exports.maybeParens = (print) => {
|
|
8
|
+
if (isFn(print))
|
|
9
|
+
return maybeParensPrint(print);
|
|
10
|
+
|
|
11
|
+
return maybeParensCondition(print);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const maybeParensPrint = (print) => ({
|
|
7
15
|
condition: isParens,
|
|
8
16
|
before(path, {write}) {
|
|
9
17
|
write('(');
|
|
@@ -13,3 +21,8 @@ module.exports.maybeParens = (print) => ({
|
|
|
13
21
|
write(')');
|
|
14
22
|
},
|
|
15
23
|
});
|
|
24
|
+
|
|
25
|
+
const maybeParensCondition = ({print, condition}) => ({
|
|
26
|
+
...maybeParensPrint(print),
|
|
27
|
+
condition: (path) => condition(path) || isParens(path),
|
|
28
|
+
});
|
package/package.json
CHANGED