@putout/printer 1.127.0 → 1.128.1
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,3 +1,13 @@
|
|
|
1
|
+
2023.06.01, v1.128.1
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 9de6e21 @putout/printer: ArrowFunctionExpression: braces
|
|
5
|
+
|
|
6
|
+
2023.06.01, v1.128.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 118671c @putout/printer: ArrowFunctionExpression: add ability to drop braces
|
|
10
|
+
|
|
1
11
|
2023.06.01, v1.127.0
|
|
2
12
|
|
|
3
13
|
feature:
|
package/README.md
CHANGED
|
@@ -5,7 +5,9 @@ const isArg = (path) => path.parentPath.isFunction();
|
|
|
5
5
|
module.exports.AssignmentPattern = {
|
|
6
6
|
print(path, {print, maybe}) {
|
|
7
7
|
maybe.print(shouldPrint(path), '__left');
|
|
8
|
-
print(
|
|
8
|
+
print.space();
|
|
9
|
+
print('=');
|
|
10
|
+
print.space();
|
|
9
11
|
print('__right');
|
|
10
12
|
},
|
|
11
13
|
};
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
module.exports.printParams = (path, {print}) => {
|
|
4
|
-
|
|
4
|
+
printBraceOpen(path, {
|
|
5
|
+
print,
|
|
6
|
+
});
|
|
5
7
|
|
|
6
8
|
const params = path.get('params');
|
|
7
9
|
const n = params.length;
|
|
@@ -15,5 +17,34 @@ module.exports.printParams = (path, {print}) => {
|
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
|
|
18
|
-
|
|
20
|
+
printBraceClose(path, {
|
|
21
|
+
print,
|
|
22
|
+
});
|
|
19
23
|
};
|
|
24
|
+
|
|
25
|
+
function printBraceOpen(path, {print}) {
|
|
26
|
+
if (isOneArgArrow(path))
|
|
27
|
+
return print.roundBraceOpen();
|
|
28
|
+
|
|
29
|
+
return print('(');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function printBraceClose(path, {print}) {
|
|
33
|
+
if (isOneArgArrow(path))
|
|
34
|
+
return print.roundBraceClose();
|
|
35
|
+
|
|
36
|
+
print(')');
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function isOneArgArrow(path) {
|
|
40
|
+
if (path.type !== 'ArrowFunctionExpression')
|
|
41
|
+
return false;
|
|
42
|
+
|
|
43
|
+
const {params} = path.node;
|
|
44
|
+
const [param] = params;
|
|
45
|
+
|
|
46
|
+
if (params.length !== 1)
|
|
47
|
+
return false;
|
|
48
|
+
|
|
49
|
+
return param.type === 'Identifier';
|
|
50
|
+
}
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -34,6 +34,7 @@ const {
|
|
|
34
34
|
|
|
35
35
|
const isString = (a) => typeof a === 'string';
|
|
36
36
|
const {assign} = Object;
|
|
37
|
+
const callWith = (fn, a) => () => fn(a);
|
|
37
38
|
|
|
38
39
|
const traversers = {
|
|
39
40
|
...expressions,
|
|
@@ -53,6 +54,8 @@ function initFormat(format) {
|
|
|
53
54
|
space: ' ',
|
|
54
55
|
comments: true,
|
|
55
56
|
splitter: '\n',
|
|
57
|
+
roundBraceOpen: '(',
|
|
58
|
+
roundBraceClose: ')',
|
|
56
59
|
...format,
|
|
57
60
|
};
|
|
58
61
|
}
|
|
@@ -110,6 +113,16 @@ module.exports.tokenize = (ast, overrides = {}) => {
|
|
|
110
113
|
});
|
|
111
114
|
};
|
|
112
115
|
|
|
116
|
+
const roundBraceOpen = callWith(addToken, {
|
|
117
|
+
type: TYPES.ROUND_BRACE_OPEN,
|
|
118
|
+
value: format.roundBraceOpen,
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
const roundBraceClose = callWith(addToken, {
|
|
122
|
+
type: TYPES.ROUND_BRACE_Close,
|
|
123
|
+
value: format.roundBraceClose,
|
|
124
|
+
});
|
|
125
|
+
|
|
113
126
|
const linebreak = () => {
|
|
114
127
|
indent();
|
|
115
128
|
newline();
|
|
@@ -202,6 +215,8 @@ module.exports.tokenize = (ast, overrides = {}) => {
|
|
|
202
215
|
assign(print, write, {
|
|
203
216
|
space,
|
|
204
217
|
round,
|
|
218
|
+
roundBraceOpen,
|
|
219
|
+
roundBraceClose,
|
|
205
220
|
});
|
|
206
221
|
|
|
207
222
|
assign(printer, {
|
package/lib/types.js
CHANGED
package/package.json
CHANGED