@putout/printer 16.0.0 → 16.2.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,16 @@
1
+ 2025.12.09, v16.2.0
2
+
3
+ feature:
4
+ - e0a7a89 @putout/printer: TSPropertySignature: comments: improve support
5
+
6
+ 2025.12.08, v16.1.0
7
+
8
+ feature:
9
+ - 1974703 @putout/printer: ClassDeclaration: implements: improve support
10
+ - f8a62fa @putout/printer: TSInterfaceDeclaration: improve support of extends
11
+ - 0a62781 @putout/printer: escover v5.0.0
12
+ - ca1d748 @putout/printer: putout v41.0.0
13
+
1
14
  2025.11.28, v16.0.0
2
15
 
3
16
  feature:
@@ -4,7 +4,6 @@ const {types} = require('@putout/babel');
4
4
  const {
5
5
  hasTrailingComment,
6
6
  satisfy,
7
- isPrev,
8
7
  } = require('../is');
9
8
 
10
9
  const {markBefore} = require('../mark');
@@ -179,9 +178,6 @@ module.exports.parseLeadingComments = (path, printer, semantics, {currentTravers
179
178
 
180
179
  print(`/*${value}*/`);
181
180
 
182
- if (isTSPropertySignature(path) && !isPrev(path))
183
- print.breakline();
184
-
185
181
  if (path.isStatement() || path.isTSEnumMember() || looksLikeDirective || looksLikeMethod || looksLikeProp || looksLikeSwitchCase) {
186
182
  print.newline();
187
183
  markBefore(path);
@@ -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: '<',
@@ -13,22 +13,38 @@ module.exports.TSInterfaceBody = (path, printer, semantics) => {
13
13
 
14
14
  write.space();
15
15
  write('{');
16
- maybe.write.newline(body.length);
16
+
17
+ maybe.write.newline(hasNoLeadingComments(path));
17
18
  indent.inc();
18
19
 
19
20
  parseComments(path, printer, semantics);
20
21
 
21
- for (const item of body) {
22
- indent();
22
+ for (const [index, item] of body.entries()) {
23
+ if (index || !item.node.leadingComments)
24
+ indent();
25
+
23
26
  traverse(item);
24
27
  }
25
28
 
26
29
  indent.dec();
27
30
  indent();
31
+
28
32
  write('}');
29
33
  maybe.write.newline(findTSModuleBlock(path));
30
34
  };
31
35
 
36
+ function hasNoLeadingComments(path) {
37
+ const {body} = path.node;
38
+
39
+ if (!body.length)
40
+ return false;
41
+
42
+ const [first] = body;
43
+ const {leadingComments} = first;
44
+
45
+ return !leadingComments;
46
+ }
47
+
32
48
  function findTSModuleBlock(path) {
33
49
  if (path.parentPath.parentPath.isTSModuleBlock())
34
50
  return true;
@@ -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,21 @@
1
+ 'use strict';
2
+
3
+ const {isPrev} = require('#is');
4
+ const noop = () => {};
5
+
6
+ module.exports.printLeadingCommentLine = (path, printer, semantics, {printComment}) => {
7
+ const {print} = printer;
8
+ print.breakline();
9
+ printComment();
10
+ print.breakline();
11
+ };
12
+
13
+ module.exports.printLeadingCommentBlock = (path, printer, semantics, {printComment}) => {
14
+ const {print, maybe} = printer;
15
+
16
+ maybe.print.breakline(!isPrev(path));
17
+ printComment();
18
+ print.indent();
19
+ };
20
+
21
+ module.exports.printTrailingCommentBlock = noop;
@@ -9,9 +9,14 @@ const {
9
9
 
10
10
  const {printKey} = require('../../expressions/object-expression/print-key');
11
11
 
12
+ const {
13
+ printLeadingCommentLine,
14
+ printLeadingCommentBlock,
15
+ printTrailingCommentBlock,
16
+ } = require('./comments');
17
+
12
18
  module.exports.TSPropertySignature = (path, printer) => {
13
19
  const {maybe, write} = printer;
14
-
15
20
  const {optional, readonly} = path.node;
16
21
 
17
22
  maybe.print(readonly, 'readonly ');
@@ -28,6 +33,9 @@ module.exports.TSPropertySignature = (path, printer) => {
28
33
  if (isNext(path) && hasTrailingComment(path))
29
34
  write.newline();
30
35
  };
36
+ module.exports.TSPropertySignature.printLeadingCommentLine = printLeadingCommentLine;
37
+ module.exports.TSPropertySignature.printLeadingCommentBlock = printLeadingCommentBlock;
38
+ module.exports.TSPropertySignature.printTrailingCommentBlock = printTrailingCommentBlock;
31
39
 
32
40
  function isTSTypeLiteralWithOneMember({parentPath}) {
33
41
  if (!parentPath.parentPath.isTSTypeParameterInstantiation())
@@ -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.2.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",