@putout/printer 1.40.2 → 1.42.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,14 @@
1
+ 2023.04.13, v1.42.0
2
+
3
+ feature:
4
+ - 39aedd9 @putout/printer: add support of TSUnionType
5
+ - 952b8b3 @putout/printer: CallExpression: add support of typeParameters
6
+
7
+ 2023.04.13, v1.41.0
8
+
9
+ feature:
10
+ - 99adbd5 @putout/printer: add support of TSArrayType
11
+
1
12
  2023.04.13, v1.40.2
2
13
 
3
14
  feature:
@@ -1,13 +1,20 @@
1
1
  'use strict';
2
2
 
3
+ const {exists} = require('../is');
4
+
3
5
  const CallExpression = {
4
6
  print(path, {indent, print, maybe, traverse}) {
5
7
  const isParentCall = toLong(path) && path.parentPath.isCallExpression();
6
8
  const callee = path.get('callee');
9
+ const typeParameters = path.get('typeParameters');
7
10
  const isFn = callee.isFunction();
8
11
 
9
12
  maybe.write(isFn, '(');
10
13
  traverse(callee);
14
+
15
+ if (exists(typeParameters))
16
+ traverse(typeParameters);
17
+
11
18
  maybe.write(isFn, ')');
12
19
 
13
20
  if (path.node.optional)
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  const {hasPrevNewline} = require('../mark');
4
+ const {exists} = require('../is');
4
5
  const isFirst = (path) => !path.getPrevSibling().node;
5
6
 
6
7
  module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
@@ -40,7 +41,7 @@ module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
40
41
 
41
42
  module.exports.ArrowFunctionExpression = ArrowFunctionExpression;
42
43
 
43
- function ArrowFunctionExpression(path, {print, maybe}) {
44
+ function ArrowFunctionExpression(path, {print, maybe, write, traverse}) {
44
45
  const {async} = path.node;
45
46
  maybe.print(async, 'async ');
46
47
  print('(');
@@ -55,7 +56,18 @@ function ArrowFunctionExpression(path, {print, maybe}) {
55
56
  print(', ');
56
57
  }
57
58
 
58
- print(') => ');
59
+ print(')');
60
+ const returnType = path.get('returnType');
61
+
62
+ if (exists(returnType)) {
63
+ write(':');
64
+ write.space();
65
+ traverse(returnType);
66
+ }
67
+
68
+ print.space();
69
+ print('=>');
70
+ print.space();
59
71
  print('__body');
60
72
  }
61
73
  module.exports.ObjectMethod = (path, {print}) => {
@@ -128,3 +140,4 @@ module.exports.ClassMethod = (path, {print, maybe}) => {
128
140
  print(') ');
129
141
  print('__body');
130
142
  };
143
+
@@ -27,10 +27,32 @@ module.exports = {
27
27
  },
28
28
  TSTypeReference(path, {print}) {
29
29
  print('__typeName');
30
+ print('__typeParameters');
31
+ },
32
+ TSArrayType(path, {print}) {
33
+ print('__elementType');
34
+ print('[]');
30
35
  },
31
36
  TSTypeParameter(path, {write}) {
32
37
  write(path.node.name);
33
38
  },
39
+ TSUndefinedKeyword(path, {write}) {
40
+ write('undefined');
41
+ },
42
+ TSUnionType(path, {traverse, write}) {
43
+ const types = path.get('types');
44
+ const n = types.length - 1;
45
+
46
+ for (const [i, type] of types.entries()) {
47
+ traverse(type);
48
+
49
+ if (i < n) {
50
+ write.space();
51
+ write('|');
52
+ write.space();
53
+ }
54
+ }
55
+ },
34
56
  TSNumberKeyword(path, {write}) {
35
57
  write('number');
36
58
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.40.2",
3
+ "version": "1.42.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",