@putout/printer 11.0.0 → 11.1.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 +12 -0
- package/README.md +1 -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/object-expression/object-property.js +1 -1
- package/lib/tokenize/overrides/overrides.js +1 -0
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +1 -1
- package/lib/tokenize/typescript/index.js +2 -25
- package/lib/tokenize/typescript/ts-union-type/ts-union-type.js +46 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
2024.12.11, v11.1.1
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- d7b4d97 @putout/printer: typos
|
|
5
|
+
|
|
6
|
+
2024.12.11, v11.1.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 43d733c @putout/printer: maxTypesInOneLine: add
|
|
10
|
+
- 85c6d1b @putout/printer: TSUnionType: more
|
|
11
|
+
- d3ee397 @putout/printer: ts-union-type: move out
|
|
12
|
+
|
|
1
13
|
2024.12.10, v11.0.0
|
|
2
14
|
|
|
3
15
|
feature:
|
package/README.md
CHANGED
|
@@ -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();
|
|
@@ -12,7 +12,7 @@ const {hasPrevNewline} = require('../../mark');
|
|
|
12
12
|
const {isExportDeclaration} = require('@putout/babel').types;
|
|
13
13
|
const {maybeSpaceAfterKeyword} = require('./maybe-space-after-keyword');
|
|
14
14
|
|
|
15
|
-
const {isConcatenation} = require('../../expressions/binary-expression/
|
|
15
|
+
const {isConcatenation} = require('../../expressions/binary-expression/concatenate');
|
|
16
16
|
const {parseLeadingComments} = require('../../comment/comment');
|
|
17
17
|
const {maybeDeclare} = require('../../maybe/maybe-declare');
|
|
18
18
|
|
|
@@ -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