@putout/operator-parens 1.1.0 → 1.2.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/lib/parens.js +16 -10
- package/package.json +1 -1
package/lib/parens.js
CHANGED
|
@@ -6,20 +6,14 @@ const {
|
|
|
6
6
|
TSParenthesizedType,
|
|
7
7
|
} = types;
|
|
8
8
|
|
|
9
|
-
module.exports.hasParens =
|
|
10
|
-
const printer = getPrinter(path);
|
|
11
|
-
|
|
12
|
-
if (printer !== 'babel')
|
|
13
|
-
return path.node.extra?.parenthesized;
|
|
14
|
-
|
|
15
|
-
const {type} = path.parentPath;
|
|
16
|
-
|
|
17
|
-
return /^(TS)?Parenthesized(Expression|Type)?$/.test(type);
|
|
18
|
-
};
|
|
9
|
+
module.exports.hasParens = hasParens;
|
|
19
10
|
|
|
20
11
|
module.exports.addParens = (path) => {
|
|
21
12
|
const printer = getPrinter(path);
|
|
22
13
|
|
|
14
|
+
if (hasParens(path, printer))
|
|
15
|
+
return path;
|
|
16
|
+
|
|
23
17
|
if (printer !== 'babel') {
|
|
24
18
|
const {extra = {}} = path.node;
|
|
25
19
|
|
|
@@ -42,6 +36,9 @@ module.exports.addParens = (path) => {
|
|
|
42
36
|
module.exports.removeParens = (path) => {
|
|
43
37
|
const printer = getPrinter(path);
|
|
44
38
|
|
|
39
|
+
if (!hasParens(path, printer))
|
|
40
|
+
return path;
|
|
41
|
+
|
|
45
42
|
if (printer !== 'babel') {
|
|
46
43
|
path.node.extra.parenthesized = false;
|
|
47
44
|
return path;
|
|
@@ -59,3 +56,12 @@ function getPrinter(path) {
|
|
|
59
56
|
|
|
60
57
|
return programPath.node.extra.__putout_printer;
|
|
61
58
|
}
|
|
59
|
+
|
|
60
|
+
function hasParens(path, printer = getPrinter(path)) {
|
|
61
|
+
if (printer !== 'babel')
|
|
62
|
+
return path.node.extra?.parenthesized;
|
|
63
|
+
|
|
64
|
+
const {type} = path.parentPath;
|
|
65
|
+
|
|
66
|
+
return /^(TS)?Parenthesized(Expression|Type)?$/.test(type);
|
|
67
|
+
}
|
package/package.json
CHANGED