@putout/printer 15.16.0 → 15.17.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
+ 2025.08.04, v15.17.0
2
+
3
+ feature:
4
+ - da01c40 @putout/printer: AssignmentExpression: inside ReturnStatement with leadingComments (coderaiser/putout#235)
5
+
1
6
  2025.08.01, v15.16.0
2
7
 
3
8
  feature:
@@ -0,0 +1,32 @@
1
+ 'use strict';
2
+
3
+ const {types} = require('@putout/babel');
4
+ const {hasLeadingComment} = require('#is');
5
+ const {isReturnStatement} = types;
6
+
7
+ module.exports.printLeadingCommentLine = ({parentPath}) => !isReturnStatement(parentPath);
8
+
9
+ module.exports.maybeInsideReturnWithCommentStart = (path, {print, indent}) => {
10
+ const {parentPath} = path;
11
+
12
+ if (isReturnStatement(parentPath) && hasLeadingComment(path)) {
13
+ indent.inc();
14
+ const {leadingComments} = path.node;
15
+
16
+ print.breakline();
17
+ for (const {value} of leadingComments) {
18
+ print(`//${value}`);
19
+ print.breakline();
20
+ }
21
+ }
22
+ };
23
+
24
+ module.exports.maybeInsideReturnWithCommentEnd = (path, {print, indent}) => {
25
+ const {parentPath} = path;
26
+
27
+ if (!isReturnStatement(parentPath) || !hasLeadingComment(path))
28
+ return;
29
+
30
+ indent.dec();
31
+ print.breakline();
32
+ };
@@ -1,11 +1,18 @@
1
1
  'use strict';
2
2
 
3
3
  const {types} = require('@putout/babel');
4
+
4
5
  const {
5
6
  maybePrintLeftBrace,
6
7
  maybePrintRightBrace,
7
8
  } = require('./maybe-write-brace');
8
9
 
10
+ const {
11
+ printLeadingCommentLine,
12
+ maybeInsideReturnWithCommentEnd,
13
+ maybeInsideReturnWithCommentStart,
14
+ } = require('./assignment-expression-comments');
15
+
9
16
  const {
10
17
  isExpressionStatement,
11
18
  isAssignmentExpression,
@@ -18,6 +25,8 @@ module.exports.AssignmentExpression = (path, printer, semantics) => {
18
25
  const {operator} = path.node;
19
26
 
20
27
  maybePrintLeftBrace(path, printer, semantics);
28
+ maybeInsideReturnWithCommentStart(path, printer);
29
+
21
30
  print('__left');
22
31
  print.space();
23
32
  print(operator);
@@ -34,9 +43,13 @@ module.exports.AssignmentExpression = (path, printer, semantics) => {
34
43
  print.breakline();
35
44
  }
36
45
 
46
+ maybeInsideReturnWithCommentEnd(path, printer);
47
+
37
48
  maybePrintRightBrace(path, printer, semantics);
38
49
  };
39
50
 
51
+ module.exports.AssignmentExpression.printLeadingCommentLine = printLeadingCommentLine;
52
+
40
53
  function isMultiline(path) {
41
54
  const {right} = path.node;
42
55
 
@@ -1,5 +1,6 @@
1
1
  'use strict';
2
2
 
3
+ const {hasLeadingComment} = require('#is');
3
4
  const {isParens} = require('../../maybe/maybe-parens');
4
5
 
5
6
  module.exports.maybePrintLeftBrace = (path, printer, semantics) => {
@@ -40,7 +41,7 @@ function maybeWriteBrace(path, printer, semantics, {brace}) {
40
41
  return;
41
42
  }
42
43
 
43
- if (!roundBraces.assign)
44
+ if (!roundBraces.assign && !hasLeadingComment(path))
44
45
  return;
45
46
 
46
47
  if (!isParens(path))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "15.16.0",
3
+ "version": "15.17.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",