@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 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
@@ -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,
@@ -1,9 +1,9 @@
1
1
  'use strict';
2
2
 
3
3
  const {
4
- concatanate,
4
+ concatenate,
5
5
  isConcatenation,
6
- } = require('./concatanate');
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 concatanate(path, {
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.concatanate = (path, {print, indent}) => {
38
+ module.exports.concatenate = (path, {print, indent}) => {
39
39
  if (!path.parentPath.isBinaryExpression()) {
40
40
  indent.inc();
41
41
  print.breakline();
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- const {isConcatenation} = require('../binary-expression/concatanate');
3
+ const {isConcatenation} = require('../binary-expression/concatenate');
4
4
  const {isOneLine} = require('./object-expression');
5
5
  const {printKey} = require('./print-key');
6
6
 
@@ -36,6 +36,7 @@ function initSemantics(semantics = {}) {
36
36
  maxSpecifiersInOneLine: 2,
37
37
  maxElementsInOneLine: 5,
38
38
  maxVariablesInOneLine: 4,
39
+ maxTypesInOneLine: 3,
39
40
  trailingComma: true,
40
41
  encodeSingleQuote: true,
41
42
  encodeDoubleQuote: false,
@@ -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/concatanate');
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "11.0.0",
3
+ "version": "11.1.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",