@putout/printer 16.0.0 → 16.1.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,11 @@
1
+ 2025.12.08, v16.1.0
2
+
3
+ feature:
4
+ - 1974703 @putout/printer: ClassDeclaration: implements: improve support
5
+ - f8a62fa @putout/printer: TSInterfaceDeclaration: improve support of extends
6
+ - 0a62781 @putout/printer: escover v5.0.0
7
+ - ca1d748 @putout/printer: putout v41.0.0
8
+
1
9
  2025.11.28, v16.0.0
2
10
 
3
11
  feature:
@@ -52,8 +52,20 @@ const classVisitor = maybeDecorators((path, printer, semantics) => {
52
52
  }
53
53
 
54
54
  if (node.implements) {
55
- print(' implements ');
56
- path.get('implements').forEach(print);
55
+ const {typeParameters} = node;
56
+
57
+ if (!typeParameters || typeParameters.params.length < 2)
58
+ print(' ');
59
+
60
+ print('implements ');
61
+
62
+ const implementsPaths = path.get('implements');
63
+ const n = implementsPaths.length - 1;
64
+
65
+ for (const [i, implement] of implementsPaths.entries()) {
66
+ print(implement);
67
+ maybe.print(i < n, ', ');
68
+ }
57
69
  }
58
70
 
59
71
  print.space();
@@ -20,6 +20,7 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
20
20
  printSpace = print.space,
21
21
  printAfterOpen = noop,
22
22
  printBeforeClose = noop,
23
+ printAfterClose = noop,
23
24
  } = customization;
24
25
 
25
26
  if (typeParameters)
@@ -54,6 +55,7 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
54
55
  print,
55
56
  braceClose,
56
57
  }, semantics);
58
+ printAfterClose();
57
59
  };
58
60
 
59
61
  function printBraceOpen(path, {print, braceOpen}, semantics) {
@@ -89,3 +89,5 @@ const createPrintSpace = ({isNewline, printer}) => () => {
89
89
 
90
90
  print.breakline();
91
91
  };
92
+
93
+ module.exports.createPrintSpace = createPrintSpace;
@@ -37,6 +37,7 @@ const {TSExportAssignment} = require('./ts-export-assignment/ts-export-assignmen
37
37
  const {TSTypeReference} = require('./ts-type-reference/ts-type-reference');
38
38
  const {TSInferType} = require('./ts-infer-type/ts-infer-type');
39
39
  const {TSParameterProperty} = require('./ts-parameter-property/ts-parameter-property');
40
+ const {TSTypeParameterDeclaration} = require('./ts-type-parameter-declaration/ts-type-parameter-declaration');
40
41
  const {TSTypeQuery} = require('./ts-type-query/ts-type-query');
41
42
  const {TSParenthesizedType} = require('./ts-parenthesized-type/ts-parenthesized-type');
42
43
  const {TSTemplateLiteralType} = require('./ts-template-literal-type/ts-template-literal-type');
@@ -59,6 +60,7 @@ module.exports = {
59
60
  TSTypeQuery,
60
61
  TSTemplateLiteralType,
61
62
  TSOptionalType,
63
+ TSTypeParameterDeclaration,
62
64
  TSBigIntKeyword(path, {write}) {
63
65
  write('bigint');
64
66
  },
@@ -86,12 +88,6 @@ module.exports = {
86
88
  print('...');
87
89
  print('__typeAnnotation');
88
90
  },
89
- TSTypeParameterDeclaration(path, printer, semantics) {
90
- printParams(path, printer, semantics, {
91
- braceOpen: '<',
92
- braceClose: '>',
93
- });
94
- },
95
91
  TSTypeParameterInstantiation(path, printer, semantics) {
96
92
  printParams(path, printer, semantics, {
97
93
  braceOpen: '<',
@@ -17,13 +17,19 @@ const isInsideNamespace = (path) => isTSModuleBlock(path.parentPath.parentPath);
17
17
  module.exports.TSInterfaceDeclaration = {
18
18
  print: maybeDeclare((path, {print, maybe}) => {
19
19
  const {node} = path;
20
+ const {typeParameters} = node;
20
21
 
21
22
  maybe.indent(!isExportNamedDeclaration(path.parentPath));
22
23
  print('interface ');
23
24
  print('__id');
24
25
 
26
+ print('__typeParameters');
27
+
25
28
  if (node.extends) {
26
- print(' extends ');
29
+ if (!typeParameters || typeParameters.length < 2)
30
+ print(' ');
31
+
32
+ print('extends ');
27
33
 
28
34
  const extendsPaths = path.get('extends');
29
35
  const n = extendsPaths.length - 1;
@@ -34,7 +40,6 @@ module.exports.TSInterfaceDeclaration = {
34
40
  }
35
41
  }
36
42
 
37
- print('__typeParameters');
38
43
  print('__body');
39
44
  }),
40
45
  afterSatisfy: () => [isNext, isNextParent],
@@ -0,0 +1,50 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('@putout/babel');
4
+ const {createPrintSpace} = require('../../expressions/function/print-function-params');
5
+ const {printParams} = require('../../expressions/function/params');
6
+ const {isTSUnionType} = types;
7
+ const noop = () => {};
8
+
9
+ module.exports.TSTypeParameterDeclaration = (path, printer, semantics) => {
10
+ const {print, indent} = printer;
11
+ const isNewline = hasComplexParameters(path);
12
+ const printSpace = createPrintSpace({
13
+ isNewline,
14
+ printer,
15
+ });
16
+
17
+ const printAfterOpen = !isNewline ? noop : () => {
18
+ indent.inc();
19
+ print.breakline();
20
+ };
21
+
22
+ const printAfterClose = !isNewline ? noop : () => {
23
+ print.breakline();
24
+ };
25
+
26
+ const printBeforeClose = !isNewline ? noop : () => {
27
+ indent.dec();
28
+ print.breakline();
29
+ };
30
+
31
+ printParams(path, printer, semantics, {
32
+ printSpace,
33
+ braceOpen: '<',
34
+ braceClose: '>',
35
+ printAfterOpen,
36
+ printBeforeClose,
37
+ printAfterClose,
38
+ });
39
+ };
40
+
41
+ function hasComplexParameters({node}) {
42
+ const {params} = node;
43
+
44
+ for (const {constraint} of params) {
45
+ if (isTSUnionType(constraint))
46
+ return true;
47
+ }
48
+
49
+ return false;
50
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "16.0.0",
3
+ "version": "16.1.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",
@@ -79,17 +79,16 @@
79
79
  "acorn": "^8.8.2",
80
80
  "c8": "^10.1.2",
81
81
  "check-dts": "^0.9.0",
82
- "escover": "^4.0.1",
82
+ "escover": "^5.0.0",
83
83
  "eslint": "^9.0.0",
84
84
  "eslint-plugin-putout": "^29.0.0",
85
85
  "estree-to-babel": "^11.0.2",
86
86
  "goldstein": "^6.0.1",
87
87
  "just-kebab-case": "^4.2.0",
88
88
  "madrun": "^11.0.0",
89
- "mock-require": "^3.0.3",
90
89
  "montag": "^1.0.0",
91
90
  "nodemon": "^3.0.1",
92
- "putout": "^40.0.1",
91
+ "putout": "^41.0.0",
93
92
  "redlint": "^4.0.0",
94
93
  "samadhi": "^3.0.3",
95
94
  "supertape": "^11.1.0",