@putout/printer 1.72.7 → 1.73.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,8 @@
1
+ 2023.04.26, v1.73.0
2
+
3
+ feature:
4
+ - 73af03b @putout/printer: add support of TSDeclareFunction
5
+
1
6
  2023.04.26, v1.72.7
2
7
 
3
8
  feature:
@@ -52,7 +52,9 @@ module.exports.isStringAndIdentifier = ([a, b]) => isStringLiteral(a) && isIdent
52
52
  const isIfOrStatement = (a) => isIfStatement(a) || isStatement(a);
53
53
  const isForOfOrStatement = (a) => isForOfStatement(a) || isStatement(a);
54
54
 
55
- module.exports.isIf = (path) => isIfStatement(path.find(isIfOrStatement));
55
+ module.exports.isIf = (path) => isIfStatement(path.find(
56
+ isIfOrStatement,
57
+ ));
56
58
 
57
59
  module.exports.isForOf = (path) => {
58
60
  const current = path.find(isForOfOrStatement);
@@ -26,8 +26,14 @@ module.exports = {
26
26
 
27
27
  write(raw || `'${value}'`);
28
28
  },
29
- Identifier(path, {write, print}) {
30
- write(path.node.name);
29
+ Identifier(path, {write, print, maybe}) {
30
+ const {
31
+ name,
32
+ optional,
33
+ } = path.node;
34
+
35
+ write(name);
36
+ maybe.write(optional, '?');
31
37
  print('__typeAnnotation');
32
38
  },
33
39
  RegExpLiteral(path, {print}) {
@@ -6,6 +6,7 @@ const {TSTypeAliasDeclaration} = require('./ts-type-alias-declaration');
6
6
  const {TSMappedType} = require('./ts-mapped-type');
7
7
  const {TSConditionalType} = require('./ts-conditional-type');
8
8
  const {TSTypeParameter} = require('./ts-type-parameter');
9
+ const {TSDeclareFunction} = require('./ts-declare-function');
9
10
 
10
11
  module.exports = {
11
12
  TSTypeLiteral,
@@ -13,6 +14,7 @@ module.exports = {
13
14
  TSTypeParameter,
14
15
  TSMappedType,
15
16
  TSConditionalType,
17
+ TSDeclareFunction,
16
18
  TSNeverKeyword(path, {write}) {
17
19
  write('never');
18
20
  },
@@ -0,0 +1,21 @@
1
+ 'use strict';
2
+
3
+ module.exports.TSDeclareFunction = (path, {print, maybe}) => {
4
+ print('function ');
5
+ print('__id');
6
+ print('(');
7
+
8
+ const params = path.get('params');
9
+ const n = params.length - 1;
10
+
11
+ for (const [i, param] of params.entries()) {
12
+ print(param);
13
+ maybe.print(i < n, ', ');
14
+ }
15
+
16
+ print(')');
17
+ print(':');
18
+ print.space();
19
+
20
+ print('__returnType');
21
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.72.7",
3
+ "version": "1.73.0",
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 fro 🐊Putout",