@putout/printer 2.73.1 → 2.74.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.07.15, v2.74.0
2
+
3
+ feature:
4
+ - e6b07a5 @putout/printer: TSTypePredicate: add
5
+
1
6
  2023.07.14, v2.73.1
2
7
 
3
8
  feature:
@@ -1,16 +1,17 @@
1
1
  'use strict';
2
2
 
3
3
  const {markAfter} = require('../../mark');
4
-
5
4
  const {isNext, isNextParent} = require('../../is');
6
-
7
5
  const {printParams} = require('./params');
8
6
 
9
7
  module.exports.FunctionDeclaration = {
10
8
  print(path, printer, semantics) {
11
9
  const {print, maybe} = printer;
12
-
13
- const {async, generator} = path.node;
10
+ const {
11
+ async,
12
+ generator,
13
+ returnType,
14
+ } = path.node;
14
15
 
15
16
  maybe.print(async, 'async ');
16
17
 
@@ -22,8 +23,12 @@ module.exports.FunctionDeclaration = {
22
23
 
23
24
  printParams(path, printer, semantics);
24
25
 
25
- print.space();
26
+ if (returnType) {
27
+ print(': ');
28
+ print('__returnType');
29
+ }
26
30
 
31
+ print.space();
27
32
  print('__body');
28
33
  },
29
34
  afterSatisfy: () => [isNext, isNextParent],
@@ -176,20 +176,14 @@ module.exports = {
176
176
 
177
177
  print('__typeAnnotation');
178
178
  },
179
- TSConstructSignatureDeclaration(path, {write, traverse, maybe}) {
180
- write('new');
181
- write('(');
182
-
183
- const params = path.get('parameters');
184
- const n = params.length - 1;
179
+ TSConstructSignatureDeclaration(path, printer, semantics) {
180
+ const {write, traverse} = printer;
185
181
 
186
- for (const [index, param] of params.entries()) {
187
- traverse(param);
188
- maybe.write(index < n, ',');
189
- maybe.write.space(index < n);
190
- }
182
+ write('new');
183
+ printParams(path, printer, semantics, {
184
+ params: path.get('parameters'),
185
+ });
191
186
 
192
- write(')');
193
187
  const typeAnnotation = path.get('typeAnnotation');
194
188
 
195
189
  if (exists(typeAnnotation)) {
@@ -214,20 +208,13 @@ module.exports = {
214
208
  print.space();
215
209
  print('__typeAnnotation');
216
210
  },
217
- TSMethodSignature(path, {traverse, write, maybe}) {
218
- traverse(path.get('key'));
219
- write('(');
220
-
221
- const params = path.get('parameters');
222
- const n = params.length - 1;
211
+ TSMethodSignature(path, printer, semantics) {
212
+ const {traverse, write} = printer;
223
213
 
224
- for (const [index, param] of params.entries()) {
225
- traverse(param);
226
- maybe.write(index < n, ',');
227
- maybe.write.space(index < n);
228
- }
229
-
230
- write(')');
214
+ traverse(path.get('key'));
215
+ printParams(path, printer, semantics, {
216
+ params: path.get('parameters'),
217
+ });
231
218
 
232
219
  const typeAnnotation = path.get('typeAnnotation');
233
220
 
@@ -243,4 +230,9 @@ module.exports = {
243
230
  },
244
231
  TSPropertySignature,
245
232
  TSFunctionType,
233
+ TSTypePredicate(path, {print}) {
234
+ print('__parameterName');
235
+ print(' is ');
236
+ print('__typeAnnotation');
237
+ },
246
238
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.73.1",
3
+ "version": "2.74.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 for 🐊Putout",