@putout/printer 10.11.0 → 11.1.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 +13 -0
- package/README.md +3 -0
- package/lib/tokenize/expressions/binary-expression/binary-expression.js +3 -3
- package/lib/tokenize/expressions/binary-expression/{concatanate.js → concatenate.js} +1 -1
- package/lib/tokenize/expressions/class/class.js +1 -1
- package/lib/tokenize/expressions/index.js +1 -1
- package/lib/tokenize/expressions/{new-expression.js → new-expression/new-expression.js} +24 -5
- package/lib/tokenize/overrides/overrides.js +1 -0
- package/lib/tokenize/overrides/parse-round-braces.js +3 -0
- package/lib/tokenize/typescript/index.js +2 -25
- package/lib/tokenize/typescript/ts-type-reference/ts-type-reference.js +1 -1
- package/lib/tokenize/typescript/ts-union-type/ts-union-type.js +46 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
2024.12.11, v11.1.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 43d733c @putout/printer: maxTypesInOneLine: add
|
|
5
|
+
- 85c6d1b @putout/printer: TSUnionType: more
|
|
6
|
+
- d3ee397 @putout/printer: ts-union-type: move out
|
|
7
|
+
|
|
8
|
+
2024.12.10, v11.0.0
|
|
9
|
+
|
|
10
|
+
feature:
|
|
11
|
+
- b2a249c @putout/printer: overrides: roundBraces: new
|
|
12
|
+
- 179df4d @putout/printer: align to babel v8 (https://github.com/babel/babel/blob/main/.github/CHANGELOG-v8.md#v800-alpha14-2024-12-06)
|
|
13
|
+
|
|
1
14
|
2024.12.04, v10.11.0
|
|
2
15
|
|
|
3
16
|
feature:
|
package/README.md
CHANGED
|
@@ -97,6 +97,7 @@ print(ast, {
|
|
|
97
97
|
maxSpecifiersInOneLine: 2,
|
|
98
98
|
maxElementsInOneLine: 3,
|
|
99
99
|
maxVariablesInOneLine: 4,
|
|
100
|
+
maxTypesInOneLine: 3,
|
|
100
101
|
maxPropertiesInOneLine: 2,
|
|
101
102
|
maxPropertiesLengthInOneLine: 15,
|
|
102
103
|
trailingComma: true,
|
|
@@ -106,6 +107,7 @@ print(ast, {
|
|
|
106
107
|
arrow: true,
|
|
107
108
|
sequence: true,
|
|
108
109
|
assign: false,
|
|
110
|
+
new: true,
|
|
109
111
|
},
|
|
110
112
|
},
|
|
111
113
|
visitors: {
|
|
@@ -182,6 +184,7 @@ Options used to configure logic of output, similar to ESLint rules:
|
|
|
182
184
|
- `arrow`: In a single argument arrow function expressions enabled: `(a) => {}`, disabled: `a => {}`;
|
|
183
185
|
- `sequence`: In sequence expressions: enabled: `for(let e of l) (a(), b())`, disabled: `for(let e of l) a(), b()`;
|
|
184
186
|
- `assign`: In assignment expressions: enabled: `(e.o=w(e.o)`, disabled: `e.o=w(e.o)`;
|
|
187
|
+
- `new`: In new expressions: enabled: `new Date()`, disabled: `new Date`;
|
|
185
188
|
|
|
186
189
|
## Visitors API
|
|
187
190
|
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {
|
|
4
|
-
|
|
4
|
+
concatenate,
|
|
5
5
|
isConcatenation,
|
|
6
|
-
} = require('./
|
|
6
|
+
} = require('./concatenate');
|
|
7
7
|
|
|
8
8
|
const {maybeSpace} = require('./maybe-space');
|
|
9
9
|
const {isParens} = require('../unary-expression/parens');
|
|
@@ -38,7 +38,7 @@ const BinaryExpression = {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
if (isConcatenation(path))
|
|
41
|
-
return
|
|
41
|
+
return concatenate(path, {
|
|
42
42
|
print,
|
|
43
43
|
indent,
|
|
44
44
|
maybe,
|
|
@@ -35,7 +35,7 @@ module.exports.isConcatenation = (path) => {
|
|
|
35
35
|
return isBinaryExpression(left) && isStringLike(right);
|
|
36
36
|
};
|
|
37
37
|
|
|
38
|
-
module.exports.
|
|
38
|
+
module.exports.concatenate = (path, {print, indent}) => {
|
|
39
39
|
if (!path.parentPath.isBinaryExpression()) {
|
|
40
40
|
indent.inc();
|
|
41
41
|
print.breakline();
|
|
@@ -14,7 +14,7 @@ const {
|
|
|
14
14
|
OptionalCallExpression,
|
|
15
15
|
} = require('./call-expression/call-expression');
|
|
16
16
|
|
|
17
|
-
const {NewExpression} = require('./new-expression');
|
|
17
|
+
const {NewExpression} = require('./new-expression/new-expression');
|
|
18
18
|
|
|
19
19
|
const {ObjectExpression} = require('./object-expression/object-expression');
|
|
20
20
|
const {ObjectProperty} = require('./object-expression/object-property');
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {exists} = require('
|
|
4
|
-
const {isMarkedAfter} = require('
|
|
3
|
+
const {exists} = require('../../is');
|
|
4
|
+
const {isMarkedAfter} = require('../../mark');
|
|
5
5
|
const isInsideExpressionStatement = ({parentPath}) => parentPath.isExpressionStatement();
|
|
6
6
|
const notFirst = ({parentPath}) => exists(parentPath.getPrevSibling());
|
|
7
7
|
|
|
@@ -35,13 +35,14 @@ module.exports.NewExpression = {
|
|
|
35
35
|
before(path, {print}) {
|
|
36
36
|
print.breakline();
|
|
37
37
|
},
|
|
38
|
-
print(path,
|
|
38
|
+
print(path, printer, semantics) {
|
|
39
|
+
const {print, maybe} = printer;
|
|
39
40
|
print('new ');
|
|
40
41
|
print('__callee');
|
|
41
42
|
print('__typeParameters');
|
|
42
43
|
|
|
43
44
|
const args = path.get('arguments');
|
|
44
|
-
|
|
45
|
+
maybePrintOpenBrace(path, printer, semantics);
|
|
45
46
|
|
|
46
47
|
const n = args.length - 1;
|
|
47
48
|
|
|
@@ -50,6 +51,24 @@ module.exports.NewExpression = {
|
|
|
50
51
|
maybe.print(i < n, ', ');
|
|
51
52
|
}
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
maybePrintCloseBrace(path, printer, semantics);
|
|
54
55
|
},
|
|
55
56
|
};
|
|
57
|
+
|
|
58
|
+
function maybePrintOpenBrace(path, printer, semantics) {
|
|
59
|
+
maybePrintBrace('(', path, printer, semantics);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function maybePrintCloseBrace(path, printer, semantics) {
|
|
63
|
+
maybePrintBrace(')', path, printer, semantics);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function maybePrintBrace(brace, path, printer, semantics) {
|
|
67
|
+
const {maybe, print} = printer;
|
|
68
|
+
const {roundBraces} = semantics;
|
|
69
|
+
|
|
70
|
+
if (path.node.arguments.length)
|
|
71
|
+
return print(brace);
|
|
72
|
+
|
|
73
|
+
maybe.print(roundBraces.new, brace);
|
|
74
|
+
}
|
|
@@ -7,18 +7,21 @@ const ROUND_BRACES_DEFAULTS = {
|
|
|
7
7
|
arrow: true,
|
|
8
8
|
sequence: true,
|
|
9
9
|
assign: false,
|
|
10
|
+
new: true,
|
|
10
11
|
};
|
|
11
12
|
|
|
12
13
|
const ROUND_BRACES_ENABLED = {
|
|
13
14
|
arrow: true,
|
|
14
15
|
sequence: true,
|
|
15
16
|
assign: true,
|
|
17
|
+
new: true,
|
|
16
18
|
};
|
|
17
19
|
|
|
18
20
|
const ROUND_BRACES_DISABLED = {
|
|
19
21
|
arrow: false,
|
|
20
22
|
sequence: false,
|
|
21
23
|
assign: false,
|
|
24
|
+
new: false,
|
|
22
25
|
};
|
|
23
26
|
|
|
24
27
|
module.exports.parseRoundBraces = ({roundBraces}) => {
|
|
@@ -29,11 +29,7 @@ const {TSConstructorType} = require('./function/ts-constructor-type');
|
|
|
29
29
|
const {TSCallSignatureDeclaration} = require('./function/ts-call-signature-declaration');
|
|
30
30
|
const {TSConstructSignatureDeclaration} = require('./function/ts-construct-signature-declaration');
|
|
31
31
|
const {TSMethodSignature} = require('./function/ts-method-signature');
|
|
32
|
-
|
|
33
|
-
const {
|
|
34
|
-
maybeParenOpen,
|
|
35
|
-
maybeParenClose,
|
|
36
|
-
} = require('../expressions/unary-expression/parens');
|
|
32
|
+
const {TSUnionType} = require('./ts-union-type/ts-union-type');
|
|
37
33
|
|
|
38
34
|
const {maybePrintTypeAnnotation} = require('../maybe/maybe-type-annotation');
|
|
39
35
|
const {TSImportType} = require('./ts-import-type');
|
|
@@ -55,6 +51,7 @@ module.exports = {
|
|
|
55
51
|
TSModuleBlock,
|
|
56
52
|
TSIntersectionType,
|
|
57
53
|
TSImportType,
|
|
54
|
+
TSUnionType,
|
|
58
55
|
TSBigIntKeyword(path, {write}) {
|
|
59
56
|
write('bigint');
|
|
60
57
|
},
|
|
@@ -127,26 +124,6 @@ module.exports = {
|
|
|
127
124
|
print(' satisfies ');
|
|
128
125
|
print('__typeAnnotation');
|
|
129
126
|
},
|
|
130
|
-
TSUnionType(path, printer) {
|
|
131
|
-
const {traverse, write} = printer;
|
|
132
|
-
|
|
133
|
-
const types = path.get('types');
|
|
134
|
-
const n = types.length - 1;
|
|
135
|
-
|
|
136
|
-
maybeParenOpen(path, printer);
|
|
137
|
-
|
|
138
|
-
for (const [i, type] of types.entries()) {
|
|
139
|
-
traverse(type);
|
|
140
|
-
|
|
141
|
-
if (i < n) {
|
|
142
|
-
write.space();
|
|
143
|
-
write('|');
|
|
144
|
-
write.space();
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
maybeParenClose(path, printer);
|
|
149
|
-
},
|
|
150
127
|
TSNumberKeyword(path, {write}) {
|
|
151
128
|
write('number');
|
|
152
129
|
},
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {
|
|
4
|
+
maybeParenOpen,
|
|
5
|
+
maybeParenClose,
|
|
6
|
+
} = require('../../expressions/unary-expression/parens');
|
|
7
|
+
|
|
8
|
+
module.exports.TSUnionType = (path, printer, semantics) => {
|
|
9
|
+
const types = path.get('types');
|
|
10
|
+
|
|
11
|
+
maybeParenOpen(path, printer);
|
|
12
|
+
|
|
13
|
+
if (types.length <= semantics.maxTypesInOneLine)
|
|
14
|
+
printInOneLine(types, printer);
|
|
15
|
+
else
|
|
16
|
+
printInCoupleLines(types, printer);
|
|
17
|
+
|
|
18
|
+
maybeParenClose(path, printer);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
function printInOneLine(types, {traverse, write}) {
|
|
22
|
+
const n = types.length - 1;
|
|
23
|
+
|
|
24
|
+
for (const [i, type] of types.entries()) {
|
|
25
|
+
traverse(type);
|
|
26
|
+
|
|
27
|
+
if (i < n) {
|
|
28
|
+
write.space();
|
|
29
|
+
write('|');
|
|
30
|
+
write.space();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function printInCoupleLines(types, {traverse, write, indent}) {
|
|
36
|
+
indent.inc();
|
|
37
|
+
|
|
38
|
+
for (const type of types) {
|
|
39
|
+
write.breakline();
|
|
40
|
+
write('|');
|
|
41
|
+
write.space();
|
|
42
|
+
traverse(type);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
indent.dec();
|
|
46
|
+
}
|
package/package.json
CHANGED