@putout/printer 1.63.1 → 1.65.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 CHANGED
@@ -1,3 +1,13 @@
1
+ 2023.04.21, v1.65.0
2
+
3
+ feature:
4
+ - a67785f @putout/printer: add support of TSConditionalType
5
+
6
+ 2023.04.21, v1.64.0
7
+
8
+ feature:
9
+ - 3ffb203 @putout/printer: add support of optional variance annotation
10
+
1
11
  2023.04.21, v1.63.1
2
12
 
3
13
  feature:
@@ -4,11 +4,40 @@ const {exists} = require('../is');
4
4
  const {TSTypeLiteral} = require('./ts-type-literal');
5
5
  const {TSTypeAliasDeclaration} = require('./ts-type-alias-declaration');
6
6
  const {TSMappedType} = require('./ts-mapped-type');
7
+ const {TSConditionalType} = require('./ts-conditional-type');
7
8
 
8
9
  module.exports = {
9
10
  TSTypeLiteral,
10
11
  TSTypeAliasDeclaration,
11
12
  TSMappedType,
13
+ TSConditionalType,
14
+ TSNeverKeyword(path, {write}) {
15
+ write('never');
16
+ },
17
+ TSUnknownKeyword(path, {write}) {
18
+ write('unknown');
19
+ },
20
+ TSTupleType(path, {write, traverse, maybe}) {
21
+ const elementTypes = path.get('elementTypes');
22
+ const n = elementTypes.length - 1;
23
+
24
+ write('[');
25
+
26
+ for (const [i, elementType] of elementTypes.entries()) {
27
+ traverse(elementType);
28
+ maybe.write(i < n, ', ');
29
+ }
30
+
31
+ write(']');
32
+ },
33
+ TSInferType(path, {print}) {
34
+ print('infer ');
35
+ print('__typeParameter');
36
+ },
37
+ TSRestType(path, {print}) {
38
+ print('...');
39
+ print('__typeAnnotation');
40
+ },
12
41
  TSTypeParameterDeclaration(path, {print}) {
13
42
  print('<');
14
43
 
@@ -37,12 +66,24 @@ module.exports = {
37
66
  },
38
67
  TSTypeParameter(path, {write, traverse}) {
39
68
  const constraint = path.get('constraint');
69
+
70
+ if (path.node.in)
71
+ write('in ');
72
+ else if (path.node.out)
73
+ write('out ');
74
+
40
75
  write(path.node.name);
41
76
 
42
- if (exists(constraint)) {
77
+ if (!exists(constraint))
78
+ return;
79
+
80
+ if (constraint.isTSTypeOperator()) {
43
81
  write(' in ');
44
- traverse(constraint);
82
+ } else {
83
+ write(' extends ');
45
84
  }
85
+
86
+ traverse(constraint);
46
87
  },
47
88
  TSTypeOperator(path, {write, print}) {
48
89
  const {operator} = path.node;
@@ -0,0 +1,23 @@
1
+ 'use strict';
2
+
3
+ module.exports.TSConditionalType = (path, {print, indent}) => {
4
+ indent.inc();
5
+ print.breakline();
6
+ print('__checkType');
7
+ print(' extends ');
8
+ print('__extendsType');
9
+
10
+ indent.inc();
11
+ print.breakline();
12
+
13
+ print('? ');
14
+ print('__trueType');
15
+
16
+ print.breakline();
17
+
18
+ print(': ');
19
+ print('__falseType');
20
+
21
+ indent.dec();
22
+ indent.dec();
23
+ };
@@ -6,12 +6,16 @@ const isNextType = (a) => a.getNextSibling().isTSTypeAliasDeclaration();
6
6
 
7
7
  module.exports.TSTypeAliasDeclaration = {
8
8
  print(path, {print, maybe, store}) {
9
+ const typeAnnotation = path.get('typeAnnotation');
10
+ const isConditional = typeAnnotation.isTSConditionalType();
11
+
9
12
  print('type ');
10
13
  print('__id');
14
+ print('__typeParameters');
11
15
 
12
16
  print.space();
13
17
  print('=');
14
- print.space();
18
+ maybe.print.space(!isConditional);
15
19
 
16
20
  print('__typeAnnotation');
17
21
  print(';');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.63.1",
3
+ "version": "1.65.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",