@putout/printer 1.72.7 → 1.73.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,13 @@
1
+ 2023.04.26, v1.73.1
2
+
3
+ feature:
4
+ - 5b48ac8 @putout/printer: improve support of ArrayExpression
5
+
6
+ 2023.04.26, v1.73.0
7
+
8
+ feature:
9
+ - 73af03b @putout/printer: add support of TSDeclareFunction
10
+
1
11
  2023.04.26, v1.72.7
2
12
 
3
13
  feature:
@@ -194,7 +194,13 @@ function isOneSimple(path) {
194
194
 
195
195
  const [first] = elements;
196
196
 
197
- return first.isIdentifier() && first.node.name.length < 5;
197
+ if (first.isIdentifier() && first.node.name.length < 5)
198
+ return true;
199
+
200
+ if (first.isCallExpression())
201
+ return false;
202
+
203
+ return first.isMemberExpression();
198
204
  }
199
205
 
200
206
  function isNewlineBetweenElements(path, {elements}) {
@@ -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}) {
@@ -5,8 +5,11 @@ const {isLast} = require('../is');
5
5
 
6
6
  module.exports.ImportDeclaration = {
7
7
  print(path, {print, maybe}) {
8
+ const isType = path.node.importKind === 'type';
8
9
  const specifiers = path.get('specifiers');
10
+
9
11
  print('import ');
12
+ maybe.print(isType, 'type ');
10
13
 
11
14
  let wasSpecifier = false;
12
15
  const n = specifiers.length - 1;
@@ -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.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 fro 🐊Putout",