@putout/printer 1.126.0 → 1.128.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 +11 -0
- package/README.md +2 -0
- package/lib/tokenize/expressions/functions/params.js +23 -2
- package/lib/tokenize/statements/do-while-statement.js +12 -0
- package/lib/tokenize/statements/{if-statement.js → if-statement/if-statement.js} +2 -2
- package/lib/tokenize/statements/index.js +3 -1
- package/lib/tokenize/tokenize.js +15 -0
- package/lib/types.js +2 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.06.01, v1.128.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 118671c @putout/printer: ArrowFunctionExpression: add ability to drop braces
|
|
5
|
+
|
|
6
|
+
2023.06.01, v1.127.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- e2ad1fe @putout/printer: DoWhileStatement: add support
|
|
10
|
+
- 5ed5799 @putout/printer: IfStatement: alternate: space
|
|
11
|
+
|
|
1
12
|
2023.06.01, v1.126.0
|
|
2
13
|
|
|
3
14
|
feature:
|
package/README.md
CHANGED
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const isOneArgArrow = (path) => {
|
|
4
|
+
if (path.type !== 'ArrowFunctionExpression')
|
|
5
|
+
return false;
|
|
6
|
+
|
|
7
|
+
return path.node.params.length === 1;
|
|
8
|
+
};
|
|
9
|
+
|
|
3
10
|
module.exports.printParams = (path, {print}) => {
|
|
4
|
-
print
|
|
11
|
+
printBraceOpen(path, {print});
|
|
5
12
|
|
|
6
13
|
const params = path.get('params');
|
|
7
14
|
const n = params.length;
|
|
@@ -15,5 +22,19 @@ module.exports.printParams = (path, {print}) => {
|
|
|
15
22
|
}
|
|
16
23
|
}
|
|
17
24
|
|
|
18
|
-
print
|
|
25
|
+
printBraceClose(path, {print});
|
|
19
26
|
};
|
|
27
|
+
|
|
28
|
+
function printBraceOpen(path, {print}) {
|
|
29
|
+
if (isOneArgArrow(path))
|
|
30
|
+
return print.roundBraceOpen();
|
|
31
|
+
|
|
32
|
+
return print('(');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function printBraceClose(path, {print}) {
|
|
36
|
+
if (isOneArgArrow(path))
|
|
37
|
+
return print.roundBraceClose();
|
|
38
|
+
|
|
39
|
+
print(')');
|
|
40
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {markAfter} = require('
|
|
4
|
-
const {exists} = require('
|
|
3
|
+
const {markAfter} = require('../../mark');
|
|
4
|
+
const {exists} = require('../../is');
|
|
5
5
|
|
|
6
6
|
const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
|
|
7
7
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
const {ExpressionStatement} = require('./expression-statement');
|
|
4
4
|
const {VariableDeclaration} = require('./variable-declaration/variable-declaration');
|
|
5
|
-
const {IfStatement} = require('./if-statement');
|
|
5
|
+
const {IfStatement} = require('./if-statement/if-statement');
|
|
6
6
|
const {ForOfStatement} = require('./for-of-statement');
|
|
7
7
|
const {BlockStatement} = require('./block-statement');
|
|
8
8
|
const {ReturnStatement} = require('./return-statement/return-statement');
|
|
@@ -18,6 +18,7 @@ const {SwitchStatement} = require('./switch-statement');
|
|
|
18
18
|
const {ForInStatement} = require('./for-in-statement');
|
|
19
19
|
const {ExportDefaultDeclaration} = require('./export-declaration/export-default-declaration');
|
|
20
20
|
const {BreakStatement} = require('./break-statement');
|
|
21
|
+
const {DoWhileStatement} = require('./do-while-statement');
|
|
21
22
|
|
|
22
23
|
const {
|
|
23
24
|
ExportNamespaceSpecifier,
|
|
@@ -28,6 +29,7 @@ module.exports = {
|
|
|
28
29
|
...importDeclarations,
|
|
29
30
|
...exportDeclarations,
|
|
30
31
|
BlockStatement,
|
|
32
|
+
DoWhileStatement,
|
|
31
33
|
ExpressionStatement,
|
|
32
34
|
ExportSpecifier,
|
|
33
35
|
ExportNamespaceSpecifier,
|
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