@putout/printer 2.61.0 → 2.63.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.07.10, v2.63.0
2
+
3
+ feature:
4
+ - d176491 @putout/printer: TSFunctionType: parameters
5
+
6
+ 2023.07.10, v2.62.0
7
+
8
+ feature:
9
+ - 3fe49ba @putout/printer: tokenize: TSIntersectionType: add
10
+
1
11
  2023.07.09, v2.61.0
2
12
 
3
13
  feature:
@@ -3,7 +3,7 @@
3
3
  const {exists} = require('../is');
4
4
 
5
5
  function CallExpression(path, {indent, print, maybe, traverse}) {
6
- const isParentCall = toLong(path) && path.parentPath.isCallExpression();
6
+ const isParentCall = tooLong(path) && path.parentPath.isCallExpression();
7
7
 
8
8
  const callee = path.get('callee');
9
9
  const typeParameters = path.get('typeParameters');
@@ -58,7 +58,7 @@ function CallExpression(path, {indent, print, maybe, traverse}) {
58
58
  module.exports.OptionalCallExpression = CallExpression;
59
59
  module.exports.CallExpression = CallExpression;
60
60
 
61
- function toLong(path) {
61
+ function tooLong(path) {
62
62
  const args = path.get('arguments');
63
63
 
64
64
  for (const arg of args) {
@@ -2,7 +2,11 @@
2
2
 
3
3
  const {parseComments} = require('../../comment/comment');
4
4
 
5
- module.exports.printParams = (path, printer, semantics) => {
5
+ module.exports.printParams = (path, printer, semantics, customization = {}) => {
6
+ const {
7
+ params = path.get('params'),
8
+ } = customization;
9
+
6
10
  const {print, traverse} = printer;
7
11
 
8
12
  printBraceOpen(path, {
@@ -11,13 +15,14 @@ module.exports.printParams = (path, printer, semantics) => {
11
15
 
12
16
  parseComments(path, printer, semantics);
13
17
 
14
- const params = path.get('params');
15
- const n = params.length;
18
+ const n = params.length - 1;
16
19
 
17
- for (let i = 0; i < n; i++) {
20
+ for (let i = 0; i <= n; i++) {
21
+ const isLast = i === n;
22
+
18
23
  traverse(params[i]);
19
24
 
20
- if (i < n - 1) {
25
+ if (!isLast) {
21
26
  print(',');
22
27
  print.space();
23
28
  }
@@ -16,6 +16,9 @@ const {
16
16
  const {TSInterfaceDeclaration} = require('./interface/ts-interface-declaration');
17
17
  const {TSAsExpression} = require('./ts-as-expression');
18
18
  const {TSInterfaceBody} = require('./interface/ts-interface-body');
19
+ const {TSIntersectionType} = require('./ts-intersection-type');
20
+ const {TSPropertySignature} = require('./ts-property-signature');
21
+ const {TSFunctionType} = require('./ts-function-type');
19
22
 
20
23
  module.exports = {
21
24
  TSAsExpression,
@@ -27,6 +30,7 @@ module.exports = {
27
30
  TSDeclareFunction,
28
31
  TSModuleDeclaration,
29
32
  TSModuleBlock,
33
+ TSIntersectionType,
30
34
  TSBigIntKeyword(path, {write}) {
31
35
  write('bigint');
32
36
  },
@@ -159,14 +163,6 @@ module.exports = {
159
163
  TSVoidKeyword(path, {write}) {
160
164
  write('void');
161
165
  },
162
- TSFunctionType(path, {print}) {
163
- print('(');
164
- print(')');
165
- print.space();
166
- print('=>');
167
- print.space();
168
- print('__typeAnnotation');
169
- },
170
166
  TSQualifiedName(path, {print}) {
171
167
  print('__left');
172
168
  print('.');
@@ -250,17 +246,6 @@ module.exports = {
250
246
  print('__expression');
251
247
  print('__typeParameters');
252
248
  },
253
- TSPropertySignature(path, {print, maybe, traverse}) {
254
- const {optional} = path.node;
255
- const typeAnnotation = path.get('typeAnnotation');
256
-
257
- print('__key');
258
- maybe.print(optional, '?');
259
-
260
- if (exists(typeAnnotation)) {
261
- print(':');
262
- print.space();
263
- traverse(typeAnnotation);
264
- }
265
- },
249
+ TSPropertySignature,
250
+ TSFunctionType,
266
251
  };
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ const {printParams} = require('../expressions/functions/params');
4
+
5
+ module.exports.TSFunctionType = (path, printer, semantics) => {
6
+ const {print} = printer;
7
+ printParams(path, printer, semantics, {
8
+ params: path.get('parameters'),
9
+ });
10
+ print.space();
11
+ print('=>');
12
+ print.space();
13
+ print('__typeAnnotation');
14
+ };
15
+
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ module.exports.TSIntersectionType = (path, {traverse, write}) => {
4
+ const types = path.get('types');
5
+ const n = types.length - 1;
6
+
7
+ for (const [i, type] of types.entries()) {
8
+ const isLast = i === n;
9
+
10
+ traverse(type);
11
+
12
+ if (!isLast) {
13
+ write.space();
14
+ write('&');
15
+ write.space();
16
+ }
17
+ }
18
+ };
@@ -0,0 +1,18 @@
1
+ 'use strict';
2
+
3
+ const {exists} = require('../is');
4
+
5
+ module.exports.TSPropertySignature = (path, {print, maybe, traverse}) => {
6
+ const {optional} = path.node;
7
+ const typeAnnotation = path.get('typeAnnotation');
8
+
9
+ print('__key');
10
+ maybe.print(optional, '?');
11
+
12
+ if (exists(typeAnnotation)) {
13
+ print(':');
14
+ print.space();
15
+ traverse(typeAnnotation);
16
+ }
17
+ };
18
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "2.61.0",
3
+ "version": "2.63.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",