@putout/printer 1.67.0 → 1.68.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.04.23, v1.68.0
2
+
3
+ feature:
4
+ - 4975e30 @putout/printer: comment in ReturnStatement
5
+
1
6
  2023.04.21, v1.67.0
2
7
 
3
8
  feature:
@@ -55,10 +55,11 @@ module.exports.parseTrailingComments = (path, {write, maybe}) => {
55
55
  for (const {type, value, loc} of trailingComments) {
56
56
  if (type === 'CommentLine') {
57
57
  const sameLine = isSameLine(path, loc);
58
+
58
59
  maybe.write.space(sameLine);
59
60
  maybe.indent(!sameLine);
60
61
  write(`//${value}`);
61
- maybe.write.newline(!sameLine);
62
+ write.newline();
62
63
  }
63
64
  }
64
65
  };
@@ -4,6 +4,8 @@ const {
4
4
  isCoupleLines,
5
5
  isForOf,
6
6
  isIf,
7
+ noTrailingComment,
8
+
7
9
  } = require('../is');
8
10
 
9
11
  const {isFunction} = require('@babel/types');
@@ -46,7 +48,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
46
48
  }
47
49
 
48
50
  print(property);
49
- maybe.print.newline(manyLines);
51
+ maybe.print.newline(manyLines && noTrailingComment(property));
50
52
  }
51
53
 
52
54
  indent.dec();
@@ -85,3 +85,5 @@ module.exports.satisfy = (conditions) => (path) => {
85
85
 
86
86
  return false;
87
87
  };
88
+
89
+ module.exports.noTrailingComment = (path) => !path.node.trailingComments;
@@ -23,7 +23,9 @@ module.exports.maybeThrow = (a, path, b) => {
23
23
  }));
24
24
  };
25
25
 
26
- const maybeProgram = (ast) => isProgram(ast) ? ast : Program([ExpressionStatement(ast)]);
26
+ const maybeProgram = (ast) => isProgram(ast) ? ast : Program([
27
+ ExpressionStatement(ast),
28
+ ]);
27
29
 
28
30
  module.exports.maybeFile = (ast) => isFile(ast) ? ast : File(maybeProgram(ast));
29
31
 
@@ -1,25 +1,38 @@
1
1
  'use strict';
2
2
 
3
- const {isPrevBody} = require('../is');
3
+ const {
4
+ isPrevBody,
5
+ noTrailingComment,
6
+ } = require('../is');
7
+
4
8
  const {hasPrevNewline} = require('../mark');
5
9
  const isBodyLength = ({parentPath}) => parentPath.node?.body?.length > 2;
6
10
 
7
- module.exports.ReturnStatement = (path, {indent, traverse, print}) => {
8
- if (!hasPrevNewline(path) && isBodyLength(path) || isPrevBody(path)) {
11
+ module.exports.ReturnStatement = {
12
+ beforeIf(path) {
13
+ return !hasPrevNewline(path) && isBodyLength(path) || isPrevBody(path);
14
+ },
15
+ before(path, {print}) {
9
16
  print.indent();
10
17
  print.newline();
11
- }
12
-
13
- indent();
14
- print('return');
15
-
16
- const argPath = path.get('argument');
17
-
18
- if (argPath.node) {
19
- print(' ');
20
- traverse(argPath);
21
- }
22
-
23
- print(';');
24
- print.newline();
18
+ },
19
+ print(path, {indent, traverse, print}) {
20
+ indent();
21
+ print('return');
22
+
23
+ const argPath = path.get('argument');
24
+
25
+ if (argPath.node) {
26
+ print(' ');
27
+ traverse(argPath);
28
+ }
29
+
30
+ print(';');
31
+ },
32
+ afterSatisfy: () => [
33
+ noTrailingComment,
34
+ ],
35
+ after(path, {print}) {
36
+ print.newline();
37
+ },
25
38
  };
@@ -25,4 +25,3 @@ module.exports.TSTypeParameter = (path, {write, traverse}) => {
25
25
 
26
26
  traverse(constraint);
27
27
  };
28
-
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "1.67.0",
3
+ "version": "1.68.0",
4
4
  "type": "commonjs",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",