@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 +10 -0
- package/lib/tokenize/jsx/jsx-opening-element.js +4 -1
- package/lib/tokenize/statements/block-statement/block-statement.js +16 -0
- package/lib/tokenize/statements/export-declaration/export-declaration.js +0 -1
- package/lib/tokenize/statements/return-statement/return-statement.js +22 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -9,7 +9,10 @@ const isNotJSX = ({parentPath}) => {
|
|
|
9
9
|
if (parentPath.parentPath.isJSXExpressionContainer())
|
|
10
10
|
return false;
|
|
11
11
|
|
|
12
|
-
|
|
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
|
|
|
@@ -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