@putout/printer 7.3.0 → 8.0.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 +3 -5
- package/lib/json.js +1 -0
- package/lib/printer.d.ts +1 -2
- package/lib/tokenize/expressions/function/params.js +8 -8
- package/lib/tokenize/literals/index.js +4 -1
- package/lib/tokenize/overrides.js +2 -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 +2 -2
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2024.01.09, v8.0.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 7bfc136 @putout/printer: format.roundBraceOpen/roundBraceClose -> semantics.roundBraces (#4)
|
|
5
|
+
- d235aee @putout/printer: @putout/plugin-react-hooks v6.0.0
|
|
6
|
+
|
|
7
|
+
2023.12.18, v7.4.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- 48b8257 @putout/printer: encodeDoubleQuote: add
|
|
11
|
+
|
|
1
12
|
2023.12.18, v7.3.0
|
|
2
13
|
|
|
3
14
|
fix:
|
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
|
},
|
|
@@ -102,6 +100,8 @@ print(ast, {
|
|
|
102
100
|
maxPropertiesInOneLine: 2,
|
|
103
101
|
trailingComma: true,
|
|
104
102
|
encodeSingleQuote: true,
|
|
103
|
+
encodeDoubleQuote: false,
|
|
104
|
+
roundBraces: true,
|
|
105
105
|
},
|
|
106
106
|
visitors: {
|
|
107
107
|
AssignmentPattern(path, {print}) {
|
|
@@ -127,8 +127,6 @@ const overrides = {
|
|
|
127
127
|
newline: '\n',
|
|
128
128
|
space: ' ',
|
|
129
129
|
splitter: '\n',
|
|
130
|
-
roundBraceOpen: '(',
|
|
131
|
-
roundBraceClose: ')',
|
|
132
130
|
endOfFile: '\n',
|
|
133
131
|
},
|
|
134
132
|
};
|
|
@@ -138,7 +136,6 @@ const overrides = {
|
|
|
138
136
|
- `newline` - symbol used for line separation;
|
|
139
137
|
- `space` - default symbol used for space character;
|
|
140
138
|
- `splitter` - mandatory symbol that used inside of statements like this:
|
|
141
|
-
- `roundBraceOpen` and `roundBraceClose` symbols to output braces in a single argument arrow function expressions: `(a) => {}`.
|
|
142
139
|
|
|
143
140
|
Default options produce:
|
|
144
141
|
|
|
@@ -175,6 +172,7 @@ Options used to configure logic of output, similar to ESLint rules:
|
|
|
175
172
|
- ✅ `maxElementsInOneLine` - count of `ArrayExpression` and `ArrayPattern` elements placed in one line.
|
|
176
173
|
- ✅ `maxVariablesInOneLine` - count of `VariableDeclarators` in one line.
|
|
177
174
|
- ✅ `maxPropertiesInOneLine` - count of `ObjectProperties` in one line.
|
|
175
|
+
- ✅ `roundBraces` - to output braces in a single argument arrow function expressions: `(a) => {}` or not `a => {}`.
|
|
178
176
|
|
|
179
177
|
## Visitors API
|
|
180
178
|
|
package/lib/json.js
CHANGED
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
|
}
|
|
@@ -3,10 +3,13 @@
|
|
|
3
3
|
const {TemplateLiteral} = require('./template-literal');
|
|
4
4
|
const {Identifier} = require('./identifier');
|
|
5
5
|
|
|
6
|
-
const maybeEncode = (value, {encodeSingleQuote}) => {
|
|
6
|
+
const maybeEncode = (value, {encodeDoubleQuote, encodeSingleQuote}) => {
|
|
7
7
|
if (encodeSingleQuote && !value.includes('\\'))
|
|
8
8
|
return value.replaceAll(`'`, `\\'`);
|
|
9
9
|
|
|
10
|
+
if (encodeDoubleQuote && !value.includes('\\"'))
|
|
11
|
+
return value.replaceAll(`"`, '\\"');
|
|
12
|
+
|
|
10
13
|
return value;
|
|
11
14
|
};
|
|
12
15
|
|
|
@@ -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,
|
|
@@ -37,6 +35,8 @@ function initSemantics(semantics = {}) {
|
|
|
37
35
|
maxVariablesInOneLine: 4,
|
|
38
36
|
trailingComma: true,
|
|
39
37
|
encodeSingleQuote: true,
|
|
38
|
+
encodeDoubleQuote: false,
|
|
39
|
+
roundBraces: true,
|
|
40
40
|
...semantics,
|
|
41
41
|
};
|
|
42
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.0",
|
|
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",
|
|
@@ -50,7 +50,7 @@
|
|
|
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
55
|
"c8": "^8.0.0",
|
|
56
56
|
"check-dts": "^0.7.2",
|