@putout/printer 5.42.0 → 5.44.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,13 @@
1
+ 2023.10.26, v5.44.0
2
+
3
+ feature:
4
+ - b9e05b0 @putout/printer: JSX: improve handling return with comment
5
+
6
+ 2023.10.25, v5.43.0
7
+
8
+ feature:
9
+ - 743122f JSX: newlines
10
+
1
11
  2023.10.25, v5.42.0
2
12
 
3
13
  feature:
@@ -9,7 +9,10 @@ const isNotJSX = ({parentPath}) => {
9
9
  if (parentPath.parentPath.isJSXExpressionContainer())
10
10
  return false;
11
11
 
12
- return !parentPath.parentPath.isJSXFragment();
12
+ if (parentPath.parentPath.isJSXFragment())
13
+ return false;
14
+
15
+ return !parentPath.parentPath.isLogicalExpression();
13
16
  };
14
17
 
15
18
  module.exports.JSXOpeningElement = {
@@ -10,6 +10,8 @@ const {
10
10
  const {
11
11
  isArrowFunctionExpression,
12
12
  isObjectMethod,
13
+ isFunctionDeclaration,
14
+ isExportDeclaration,
13
15
  } = require('@putout/babel').types;
14
16
 
15
17
  const {markAfter} = require('../../mark');
@@ -103,9 +105,23 @@ function shouldAddNewlineAfter(path) {
103
105
  if (isLast(path))
104
106
  return false;
105
107
 
108
+ if (isExportFunction(path))
109
+ return false;
110
+
106
111
  return !isNextIfAlternate(path);
107
112
  }
108
113
 
114
+ // export function a() {}
115
+ function isExportFunction(path) {
116
+ if (!isFunctionDeclaration(path.parentPath))
117
+ return false;
118
+
119
+ if (!isExportDeclaration(path.parentPath?.parentPath))
120
+ return false;
121
+
122
+ return !isNext(path.parentPath?.parentPath);
123
+ }
124
+
109
125
  function isNextIfAlternate(path) {
110
126
  const {parentPath} = path;
111
127
 
@@ -86,7 +86,6 @@ module.exports.ExportNamedDeclaration = {
86
86
  indent.dec();
87
87
  indent();
88
88
  write('}');
89
-
90
89
  const source = path.get('source');
91
90
 
92
91
  if (exists(source)) {
@@ -1,5 +1,7 @@
1
1
  'use strict';
2
2
 
3
+ const {isJSXElement} = require('@putout/babel').types;
4
+
3
5
  const {
4
6
  isPrevBody,
5
7
  noTrailingComment,
@@ -24,6 +26,16 @@ module.exports.ReturnStatement = {
24
26
  maybeSpaceAfterKeyword(path, {
25
27
  print,
26
28
  });
29
+
30
+ if (isJSXWithComment(path)) {
31
+ print('(');
32
+ print.breakline();
33
+ print('__argument');
34
+ print(');');
35
+
36
+ return;
37
+ }
38
+
27
39
  print('__argument');
28
40
  print(';');
29
41
  },
@@ -37,3 +49,13 @@ module.exports.ReturnStatement = {
37
49
  print.newline();
38
50
  },
39
51
  };
52
+ function isJSXWithComment(path) {
53
+ const arg = path.node.argument;
54
+
55
+ if (!arg)
56
+ return;
57
+
58
+ const {leadingComments} = arg;
59
+
60
+ return isJSXElement(arg) && leadingComments?.length;
61
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/printer",
3
- "version": "5.42.0",
3
+ "version": "5.44.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",