@putout/printer 1.72.6 → 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,13 @@
1
+ 2023.04.26, v1.73.0
2
+
3
+ feature:
4
+ - 73af03b @putout/printer: add support of TSDeclareFunction
5
+
6
+ 2023.04.26, v1.72.7
7
+
8
+ feature:
9
+ - 7764b71 @putout/printer: improve chaining support of MemberExpression
10
+
1
11
  2023.04.26, v1.72.6
2
12
 
3
13
  feature:
@@ -61,9 +61,6 @@ module.exports.OptionalMemberExpression = (path, {print}) => {
61
61
  function isLooksLikeChain(path) {
62
62
  const {parentPath} = path;
63
63
 
64
- if (parentPath.parentPath.isStatement() && !parentPath.parentPath.isExpressionStatement())
65
- return false;
66
-
67
64
  if (path.find(isIfStatement))
68
65
  return false;
69
66
 
@@ -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.6",
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",