@putout/printer 7.4.0 → 8.0.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 +14 -0
- package/README.md +2 -5
- package/lib/printer.d.ts +1 -2
- package/lib/tokenize/expressions/function/params.js +8 -8
- package/lib/tokenize/overrides.js +1 -2
- package/lib/tokenize/statements/return-statement/maybe-space-after-keyword.js +2 -2
- package/lib/tokenize/statements/return-statement/return-statement.js +4 -4
- package/lib/tokenize/tokenize.js +0 -13
- package/package.json +6 -6
package/ChangeLog
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
2024.01.19, v8.0.1
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- e664254 @putout/printer: putout v35.0.0
|
|
5
|
+
- c61b526 @putout/printer: @putout/plugin-minify v7.1.1
|
|
6
|
+
- 9bc0a84 @putout/printer: @putout/operator-json v2.0.0
|
|
7
|
+
- 85f79d1 @putout/printer: c8 v9.1.0
|
|
8
|
+
|
|
9
|
+
2024.01.09, v8.0.0
|
|
10
|
+
|
|
11
|
+
feature:
|
|
12
|
+
- 7bfc136 @putout/printer: format.roundBraceOpen/roundBraceClose -> semantics.roundBraces (#4)
|
|
13
|
+
- d235aee @putout/printer: @putout/plugin-react-hooks v6.0.0
|
|
14
|
+
|
|
1
15
|
2023.12.18, v7.4.0
|
|
2
16
|
|
|
3
17
|
feature:
|
package/README.md
CHANGED
|
@@ -89,8 +89,6 @@ print(ast, {
|
|
|
89
89
|
newline: '\n',
|
|
90
90
|
space: ' ',
|
|
91
91
|
splitter: '\n',
|
|
92
|
-
roundBraceOpen: '(',
|
|
93
|
-
roundBraceClose: ')',
|
|
94
92
|
quote: `'`,
|
|
95
93
|
endOfFile: '\n',
|
|
96
94
|
},
|
|
@@ -103,6 +101,7 @@ print(ast, {
|
|
|
103
101
|
trailingComma: true,
|
|
104
102
|
encodeSingleQuote: true,
|
|
105
103
|
encodeDoubleQuote: false,
|
|
104
|
+
roundBraces: true,
|
|
106
105
|
},
|
|
107
106
|
visitors: {
|
|
108
107
|
AssignmentPattern(path, {print}) {
|
|
@@ -128,8 +127,6 @@ const overrides = {
|
|
|
128
127
|
newline: '\n',
|
|
129
128
|
space: ' ',
|
|
130
129
|
splitter: '\n',
|
|
131
|
-
roundBraceOpen: '(',
|
|
132
|
-
roundBraceClose: ')',
|
|
133
130
|
endOfFile: '\n',
|
|
134
131
|
},
|
|
135
132
|
};
|
|
@@ -139,7 +136,6 @@ const overrides = {
|
|
|
139
136
|
- `newline` - symbol used for line separation;
|
|
140
137
|
- `space` - default symbol used for space character;
|
|
141
138
|
- `splitter` - mandatory symbol that used inside of statements like this:
|
|
142
|
-
- `roundBraceOpen` and `roundBraceClose` symbols to output braces in a single argument arrow function expressions: `(a) => {}`.
|
|
143
139
|
|
|
144
140
|
Default options produce:
|
|
145
141
|
|
|
@@ -176,6 +172,7 @@ Options used to configure logic of output, similar to ESLint rules:
|
|
|
176
172
|
- ✅ `maxElementsInOneLine` - count of `ArrayExpression` and `ArrayPattern` elements placed in one line.
|
|
177
173
|
- ✅ `maxVariablesInOneLine` - count of `VariableDeclarators` in one line.
|
|
178
174
|
- ✅ `maxPropertiesInOneLine` - count of `ObjectProperties` in one line.
|
|
175
|
+
- ✅ `roundBraces` - to output braces in a single argument arrow function expressions: `(a) => {}` or not `a => {}`.
|
|
179
176
|
|
|
180
177
|
## Visitors API
|
|
181
178
|
|
package/lib/printer.d.ts
CHANGED
|
@@ -5,12 +5,11 @@ interface Format {
|
|
|
5
5
|
newline: string;
|
|
6
6
|
space: string;
|
|
7
7
|
splitter: string;
|
|
8
|
-
roundBraceOpen: string;
|
|
9
|
-
roundBraceClose: string;
|
|
10
8
|
quote: string;
|
|
11
9
|
}
|
|
12
10
|
|
|
13
11
|
interface Semantics {
|
|
12
|
+
roundBraces: boolean;
|
|
14
13
|
comments: boolean;
|
|
15
14
|
maxPropertiesInOneLine: number;
|
|
16
15
|
maxSpecifiersInOneLine: number;
|
|
@@ -21,7 +21,7 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
|
|
|
21
21
|
printBraceOpen(path, {
|
|
22
22
|
print,
|
|
23
23
|
braceOpen,
|
|
24
|
-
});
|
|
24
|
+
}, semantics);
|
|
25
25
|
|
|
26
26
|
parseComments(path, printer, semantics);
|
|
27
27
|
|
|
@@ -41,19 +41,19 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
|
|
|
41
41
|
printBraceClose(path, {
|
|
42
42
|
print,
|
|
43
43
|
braceClose,
|
|
44
|
-
});
|
|
44
|
+
}, semantics);
|
|
45
45
|
};
|
|
46
46
|
|
|
47
|
-
function printBraceOpen(path, {print, braceOpen}) {
|
|
48
|
-
if (isOneArgArrow(path))
|
|
49
|
-
return
|
|
47
|
+
function printBraceOpen(path, {print, braceOpen}, semantics) {
|
|
48
|
+
if (isOneArgArrow(path) && !semantics.roundBraces)
|
|
49
|
+
return;
|
|
50
50
|
|
|
51
51
|
return print(braceOpen);
|
|
52
52
|
}
|
|
53
53
|
|
|
54
|
-
function printBraceClose(path, {print, braceClose}) {
|
|
55
|
-
if (isOneArgArrow(path))
|
|
56
|
-
return
|
|
54
|
+
function printBraceClose(path, {print, braceClose}, semantics) {
|
|
55
|
+
if (isOneArgArrow(path) && !semantics.roundBraces)
|
|
56
|
+
return;
|
|
57
57
|
|
|
58
58
|
print(braceClose);
|
|
59
59
|
}
|
|
@@ -20,8 +20,6 @@ function initFormat(format) {
|
|
|
20
20
|
newline: '\n',
|
|
21
21
|
space: ' ',
|
|
22
22
|
splitter: '\n',
|
|
23
|
-
roundBraceOpen: '(',
|
|
24
|
-
roundBraceClose: ')',
|
|
25
23
|
quote: `'`,
|
|
26
24
|
endOfFile: '\n',
|
|
27
25
|
...format,
|
|
@@ -38,6 +36,7 @@ function initSemantics(semantics = {}) {
|
|
|
38
36
|
trailingComma: true,
|
|
39
37
|
encodeSingleQuote: true,
|
|
40
38
|
encodeDoubleQuote: false,
|
|
39
|
+
roundBraces: true,
|
|
41
40
|
...semantics,
|
|
42
41
|
};
|
|
43
42
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
module.exports.maybeSpaceAfterKeyword = (path, {print}) => {
|
|
3
|
+
module.exports.maybeSpaceAfterKeyword = (path, {print}, semantics) => {
|
|
4
4
|
const {argument} = path.node;
|
|
5
5
|
|
|
6
6
|
if (!argument)
|
|
@@ -17,7 +17,7 @@ module.exports.maybeSpaceAfterKeyword = (path, {print}) => {
|
|
|
17
17
|
if (type === 'UnaryExpression' && argument.operator === '!')
|
|
18
18
|
return print.space();
|
|
19
19
|
|
|
20
|
-
if (type === 'ArrowFunctionExpression')
|
|
20
|
+
if (type === 'ArrowFunctionExpression' && semantics.roundBraces)
|
|
21
21
|
return print.space();
|
|
22
22
|
|
|
23
23
|
print(' ');
|
|
@@ -20,12 +20,12 @@ module.exports.ReturnStatement = {
|
|
|
20
20
|
before(path, {print}) {
|
|
21
21
|
print.linebreak();
|
|
22
22
|
},
|
|
23
|
-
print(path,
|
|
23
|
+
print(path, printer, semantics) {
|
|
24
|
+
const {indent, print} = printer;
|
|
25
|
+
|
|
24
26
|
indent();
|
|
25
27
|
print('return');
|
|
26
|
-
maybeSpaceAfterKeyword(path,
|
|
27
|
-
print,
|
|
28
|
-
});
|
|
28
|
+
maybeSpaceAfterKeyword(path, printer, semantics);
|
|
29
29
|
|
|
30
30
|
if (isJSXWithComment(path)) {
|
|
31
31
|
print('(');
|
package/lib/tokenize/tokenize.js
CHANGED
|
@@ -25,7 +25,6 @@ const {parseOverrides} = require('./overrides');
|
|
|
25
25
|
|
|
26
26
|
const isString = (a) => typeof a === 'string';
|
|
27
27
|
const {assign, freeze} = Object;
|
|
28
|
-
const callWith = (fn, a) => () => fn(a);
|
|
29
28
|
|
|
30
29
|
const GET = '__';
|
|
31
30
|
const get = (path, command) => path.get(command.replace(GET, ''));
|
|
@@ -88,16 +87,6 @@ module.exports.tokenize = (ast, overrides) => {
|
|
|
88
87
|
});
|
|
89
88
|
};
|
|
90
89
|
|
|
91
|
-
const roundBraceOpen = callWith(addToken, {
|
|
92
|
-
type: TYPES.ROUND_BRACE_OPEN,
|
|
93
|
-
value: format.roundBraceOpen,
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
const roundBraceClose = callWith(addToken, {
|
|
97
|
-
type: TYPES.ROUND_BRACE_Close,
|
|
98
|
-
value: format.roundBraceClose,
|
|
99
|
-
});
|
|
100
|
-
|
|
101
90
|
const linebreak = () => {
|
|
102
91
|
indent();
|
|
103
92
|
newline();
|
|
@@ -207,8 +196,6 @@ module.exports.tokenize = (ast, overrides) => {
|
|
|
207
196
|
assign(print, write, {
|
|
208
197
|
space,
|
|
209
198
|
round,
|
|
210
|
-
roundBraceOpen,
|
|
211
|
-
roundBraceClose,
|
|
212
199
|
});
|
|
213
200
|
|
|
214
201
|
const printer = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"@putout/babel": "^2.0.0",
|
|
30
30
|
"@putout/compare": "^14.0.0",
|
|
31
31
|
"@putout/operate": "^12.0.0",
|
|
32
|
-
"@putout/operator-json": "^
|
|
32
|
+
"@putout/operator-json": "^2.0.0",
|
|
33
33
|
"fullstore": "^3.0.0",
|
|
34
34
|
"just-snake-case": "^3.2.0",
|
|
35
35
|
"parse-import-specifiers": "^1.0.1",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
],
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@babel/plugin-codemod-object-assign-to-object-spread": "^7.10.4",
|
|
49
|
-
"@putout/plugin-minify": "^
|
|
49
|
+
"@putout/plugin-minify": "^7.1.1",
|
|
50
50
|
"@putout/plugin-printer": "^3.0.0",
|
|
51
51
|
"@putout/plugin-promises": "^14.0.0",
|
|
52
52
|
"@putout/plugin-react-hook-form": "^4.0.0",
|
|
53
|
-
"@putout/plugin-react-hooks": "^
|
|
53
|
+
"@putout/plugin-react-hooks": "^6.0.0",
|
|
54
54
|
"acorn": "^8.8.2",
|
|
55
|
-
"c8": "^
|
|
55
|
+
"c8": "^9.1.0",
|
|
56
56
|
"check-dts": "^0.7.2",
|
|
57
57
|
"escover": "^4.0.1",
|
|
58
58
|
"eslint": "^8.0.1",
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"mock-require": "^3.0.3",
|
|
65
65
|
"montag": "^1.0.0",
|
|
66
66
|
"nodemon": "^3.0.1",
|
|
67
|
-
"putout": "^
|
|
67
|
+
"putout": "^35.0.0",
|
|
68
68
|
"supertape": "^9.0.0",
|
|
69
69
|
"try-catch": "^3.0.0",
|
|
70
70
|
"typescript": "^5.3.3"
|