@putout/printer 18.42.2 → 18.43.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.
Files changed (20) hide show
  1. package/ChangeLog +14 -1
  2. package/lib/tokenize/expressions/conditional-expression/conditional-expression-multiline.js +1 -0
  3. package/lib/tokenize/expressions/function/{arrow-function-expression.js → arrow-function-expression/arrow-function-expression.js} +4 -16
  4. package/lib/tokenize/expressions/function/{class-method.js → class-method/class-method.js} +7 -11
  5. package/lib/tokenize/expressions/function/{function-declaration.js → function-declaration/function-declaration.js} +4 -11
  6. package/lib/tokenize/expressions/function/{function-expression.js → function-expression/function-expression.js} +3 -1
  7. package/lib/tokenize/expressions/function/functions.js +5 -5
  8. package/lib/tokenize/expressions/function/{object-method.js → object-method/object-method.js} +5 -3
  9. package/lib/tokenize/expressions/function/print-function-params.js +1 -1
  10. package/lib/tokenize/expressions/function/return-type.js +10 -0
  11. package/lib/tokenize/typescript/function/ts-call-signature-declaration.js +1 -1
  12. package/lib/tokenize/typescript/function/ts-construct-signature-declaration.js +1 -1
  13. package/lib/tokenize/typescript/function/ts-constructor-type.js +1 -1
  14. package/lib/tokenize/typescript/function/ts-declare-function.js +1 -1
  15. package/lib/tokenize/typescript/function/ts-declare-method.js +1 -1
  16. package/lib/tokenize/typescript/function/ts-function-type.js +1 -1
  17. package/lib/tokenize/typescript/function/ts-method-signature.js +1 -1
  18. package/lib/tokenize/typescript/index.js +1 -1
  19. package/lib/tokenize/typescript/ts-type-parameter-declaration/ts-type-parameter-declaration.js +1 -1
  20. package/package.json +4 -2
package/ChangeLog CHANGED
@@ -1,3 +1,16 @@
1
+ 2026.09.07, v18.43.0
2
+
3
+ feature:
4
+ - 640e6e16 @putout/printer: return-type
5
+ - 356e5394 @putout/printer: return-type
6
+ - 5cadde8c @putout/printer: FunctionExpression: returnType
7
+ - 45a16f04 @putout/printer: ObjectMethod: printReturnType
8
+
9
+ 2026.09.02, v18.42.3
10
+
11
+ fix:
12
+ - 41c18081 @putout/printer: ConditionalExpression: inside CallExpression: not multiline
13
+
1
14
  2026.09.02, v18.42.2
2
15
 
3
16
  feature:
@@ -886,7 +899,7 @@ fix:
886
899
  2026.01.18, v17.0.4
887
900
 
888
901
  feature:
889
- - 06823ba @putout/printer: print-params -> #print-params
902
+ - 06823ba @putout/printer: print-params -> #params
890
903
 
891
904
  2026.01.17, v17.0.3
892
905
 
@@ -4,6 +4,7 @@ import {isCoupleLines} from '#is';
4
4
  export const isConditionalExpressionMultiline = createTypeChecker([
5
5
  ['-: node.alternate -> ObjectExpression'],
6
6
  ['-: node.consequent -> ObjectExpression'],
7
+ ['-: parentPath -> CallExpression'],
7
8
  ['+', isCoupleLines],
8
9
  ]);
9
10
 
@@ -1,27 +1,15 @@
1
- import {exists} from '#is';
2
1
  import {maybeParens} from '#maybe-parens';
3
- import {printParams} from '#print-params';
2
+ import {printParams} from '#params';
3
+ import {printReturnType} from '#return-type';
4
4
 
5
5
  export const ArrowFunctionExpression = maybeParens((path, printer, semantics) => {
6
- const {
7
- print,
8
- maybe,
9
- write,
10
- traverse,
11
- } = printer;
6
+ const {print, maybe} = printer;
12
7
 
13
8
  const {async} = path.node;
14
9
 
15
10
  maybe.print(async, 'async ');
16
11
  printParams(path, printer, semantics);
17
-
18
- const returnType = path.get('returnType');
19
-
20
- if (exists(returnType)) {
21
- write(':');
22
- write.space();
23
- traverse(returnType);
24
- }
12
+ printReturnType(path, printer);
25
13
 
26
14
  print.space();
27
15
  print('=>');
@@ -2,10 +2,11 @@ import {
2
2
  isNext,
3
3
  hasTrailingComment,
4
4
  } from '#is';
5
- import {maybeDecorators} from '../../maybe/maybe-decorators.js';
6
- import {printKey} from '../object-expression/print-key.js';
7
- import {printKind} from './kind.js';
8
- import {printFunctionParams} from './print-function-params.js';
5
+ import {printReturnType} from '#return-type';
6
+ import {maybeDecorators} from '../../../maybe/maybe-decorators.js';
7
+ import {printKey} from '../../object-expression/print-key.js';
8
+ import {printKind} from '../kind.js';
9
+ import {printFunctionParams} from '../print-function-params.js';
9
10
 
10
11
  const noTrailingCommentAndNext = (path) => {
11
12
  if (hasTrailingComment(path))
@@ -18,7 +19,7 @@ export const ClassMethod = {
18
19
  print: maybeDecorators((path, printer, semantics) => {
19
20
  const {print} = printer;
20
21
  const {node} = path;
21
- const {accessibility, returnType} = node;
22
+ const {accessibility} = node;
22
23
 
23
24
  if (accessibility) {
24
25
  print(accessibility);
@@ -43,12 +44,7 @@ export const ClassMethod = {
43
44
  printKind(path, printer);
44
45
  printKey(path, printer);
45
46
  printFunctionParams(path, printer, semantics);
46
-
47
- if (returnType) {
48
- print(':');
49
- print.space();
50
- print('__returnType');
51
- }
47
+ printReturnType(path, printer);
52
48
 
53
49
  print.space();
54
50
  print('__body');
@@ -1,5 +1,5 @@
1
1
  import {types} from '@putout/babel';
2
- import {printParams} from '#print-params';
2
+ import {printParams} from '#params';
3
3
  import {markAfter} from '#mark';
4
4
  import {
5
5
  callWithNext,
@@ -7,6 +7,7 @@ import {
7
7
  isNextParent,
8
8
  } from '#is';
9
9
  import {createTypeChecker} from '#type-checker';
10
+ import {printReturnType} from '#return-type';
10
11
 
11
12
  const {
12
13
  isExpressionStatement,
@@ -44,11 +45,7 @@ export const FunctionDeclaration = {
44
45
  print(path, printer, semantics) {
45
46
  const {print, maybe} = printer;
46
47
 
47
- const {
48
- async,
49
- generator,
50
- returnType,
51
- } = path.node;
48
+ const {async, generator} = path.node;
52
49
 
53
50
  maybe.print(async, 'async ');
54
51
 
@@ -63,11 +60,7 @@ export const FunctionDeclaration = {
63
60
 
64
61
  print('__id');
65
62
  printParams(path, printer, semantics);
66
-
67
- if (returnType) {
68
- print(': ');
69
- print('__returnType');
70
- }
63
+ printReturnType(path, printer);
71
64
 
72
65
  print.space();
73
66
  print('__body');
@@ -1,6 +1,7 @@
1
1
  import {exists} from '#is';
2
2
  import {maybeParens} from '#maybe-parens';
3
- import {printParams} from '#print-params';
3
+ import {printParams} from '#params';
4
+ import {printReturnType} from '#return-type';
4
5
 
5
6
  export const FunctionExpression = maybeParens((path, printer, semantics) => {
6
7
  const {
@@ -25,6 +26,7 @@ export const FunctionExpression = maybeParens((path, printer, semantics) => {
25
26
  }
26
27
 
27
28
  printParams(path, printer, semantics);
29
+ printReturnType(path, printer);
28
30
 
29
31
  print.space();
30
32
  print('__body');
@@ -1,5 +1,5 @@
1
- export {ArrowFunctionExpression} from './arrow-function-expression.js';
2
- export {FunctionDeclaration} from './function-declaration.js';
3
- export {ClassPrivateMethod, ClassMethod} from './class-method.js';
4
- export {ObjectMethod} from './object-method.js';
5
- export {FunctionExpression} from './function-expression.js';
1
+ export {ArrowFunctionExpression} from './arrow-function-expression/arrow-function-expression.js';
2
+ export {FunctionDeclaration} from './function-declaration/function-declaration.js';
3
+ export {ClassPrivateMethod, ClassMethod} from './class-method/class-method.js';
4
+ export {ObjectMethod} from './object-method/object-method.js';
5
+ export {FunctionExpression} from './function-expression/function-expression.js';
@@ -2,10 +2,11 @@ import {
2
2
  isNewlineBetweenSiblings,
3
3
  isNext,
4
4
  } from '#is';
5
- import {printParams} from '#print-params';
5
+ import {printParams} from '#params';
6
6
  import {markAfter} from '#mark';
7
- import {printKey} from '../object-expression/print-key.js';
8
- import {printKind} from './kind.js';
7
+ import {printReturnType} from '#return-type';
8
+ import {printKey} from '../../object-expression/print-key.js';
9
+ import {printKind} from '../kind.js';
9
10
 
10
11
  export const ObjectMethod = {
11
12
  beforeIf(path) {
@@ -21,6 +22,7 @@ export const ObjectMethod = {
21
22
  printKind(path, printer);
22
23
  printKey(path, printer);
23
24
  printParams(path, printer, semantics);
25
+ printReturnType(path, printer);
24
26
 
25
27
  print.space();
26
28
  print('__body');
@@ -2,7 +2,7 @@ import {
2
2
  hasLeadingComment,
3
3
  hasDecorators,
4
4
  } from '#is';
5
- import {printParams} from '#print-params';
5
+ import {printParams} from '#params';
6
6
 
7
7
  const isAllParamsHasLeadingComments = (path) => {
8
8
  const params = path.get('params');
@@ -0,0 +1,10 @@
1
+ export const printReturnType = (path, printer) => {
2
+ const {print} = printer;
3
+ const {returnType} = path.node;
4
+
5
+ if (returnType) {
6
+ print(':');
7
+ print.space();
8
+ print('__returnType');
9
+ }
10
+ };
@@ -1,4 +1,4 @@
1
- import {printParams} from '#print-params';
1
+ import {printParams} from '#params';
2
2
  import {printReturnType} from './print-return-type.js';
3
3
 
4
4
  export const TSCallSignatureDeclaration = (path, printer, semantics) => {
@@ -1,4 +1,4 @@
1
- import {printParams} from '#print-params';
1
+ import {printParams} from '#params';
2
2
  import {
3
3
  hasReturnType,
4
4
  printReturnType,
@@ -1,4 +1,4 @@
1
- import {printParams} from '#print-params';
1
+ import {printParams} from '#params';
2
2
  import {printReturnType} from './print-return-type.js';
3
3
 
4
4
  export const TSConstructorType = (path, printer, semantics) => {
@@ -1,5 +1,5 @@
1
1
  import {isNext} from '#is';
2
- import {printParams} from '#print-params';
2
+ import {printParams} from '#params';
3
3
  import {maybeDeclare} from '#maybe-declare';
4
4
 
5
5
  const isInsideDefaultExport = (path) => {
@@ -1,4 +1,4 @@
1
- import {printParams} from '#print-params';
1
+ import {printParams} from '#params';
2
2
 
3
3
  export const TSDeclareMethod = (path, printer, semantics) => {
4
4
  const {print} = printer;
@@ -1,5 +1,5 @@
1
1
  import {maybeParens} from '#maybe-parens';
2
- import {printParams} from '#print-params';
2
+ import {printParams} from '#params';
3
3
  import {printReturnType} from './print-return-type.js';
4
4
 
5
5
  export const TSFunctionType = maybeParens((path, printer, semantics) => {
@@ -1,4 +1,4 @@
1
- import {printParams} from '#print-params';
1
+ import {printParams} from '#params';
2
2
  import {printKind} from '../../expressions/function/kind.js';
3
3
  import {
4
4
  hasReturnType,
@@ -1,4 +1,4 @@
1
- import {printParams} from '#print-params';
1
+ import {printParams} from '#params';
2
2
  import {maybePrintTypeAnnotation} from '../maybe/maybe-type-annotation.js';
3
3
 
4
4
  export {TSNonNullExpression} from './ts-non-null-expression/ts-non-null-expression.js';
@@ -1,5 +1,5 @@
1
1
  import {types} from '@putout/babel';
2
- import {printParams} from '#print-params';
2
+ import {printParams} from '#params';
3
3
  import {createPrintSpace} from '../../expressions/function/print-function-params.js';
4
4
 
5
5
  const {isTSUnionType} = types;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "18.42.2",
3
+ "version": "18.43.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
@@ -10,6 +10,7 @@
10
10
  ".": "./lib/printer.js",
11
11
  "./is": "./lib/tokenize/is.js",
12
12
  "./params": "./lib/tokenize/expressions/function/params.js",
13
+ "./return-type": "./lib/tokenize/expressions/function/return-type.js",
13
14
  "./type-checker": "./lib/tokenize/type-checker/type-checker.js",
14
15
  "./type-checker/instrument": "./lib/tokenize/type-checker/instrument.js",
15
16
  "./type-checker/report": "./lib/tokenize/type-checker/report.js",
@@ -65,7 +66,8 @@
65
66
  "#mark": "./lib/tokenize/mark.js",
66
67
  "#maybe-parens": "./lib/tokenize/maybe/maybe-parens.js",
67
68
  "#maybe-declare": "./lib/tokenize/maybe/maybe-declare.js",
68
- "#print-params": "./lib/tokenize/expressions/function/params.js",
69
+ "#params": "./lib/tokenize/expressions/function/params.js",
70
+ "#return-type": "./lib/tokenize/expressions/function/return-type.js",
69
71
  "#import-attributes": "./lib/tokenize/statements/import-declaration/import-attribute.js",
70
72
  "#types": "./lib/types.js",
71
73
  "#type-checker": "./lib/tokenize/type-checker/type-checker.js",