@putout/printer 5.37.0 → 5.39.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 +11 -0
- package/lib/tokenize/comment/parse-leading-comments.js +0 -1
- package/lib/tokenize/comment/parse-trailing-comments.js +6 -2
- package/lib/tokenize/expressions/function/arrow-function-expression.js +1 -2
- package/lib/tokenize/jsx/jsx-element.js +31 -15
- package/lib/tokenize/jsx/jsx-opening-element.js +11 -0
- package/lib/tokenize/typescript/index.js +1 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.10.25, v5.39.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- e02cb0e JSXExpression: improve support
|
|
5
|
+
- 1dc666f @putout/printer: ArrowFunctionExpression: space
|
|
6
|
+
|
|
7
|
+
2023.10.25, v5.38.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- 983412b comments: leading: improve
|
|
11
|
+
|
|
1
12
|
2023.10.24, v5.37.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -66,7 +66,6 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
|
|
|
66
66
|
const looksLikeDirective = path.isDirective();
|
|
67
67
|
const looksLikeProp = path.isObjectProperty();
|
|
68
68
|
|
|
69
|
-
// || path.isTSPropertySignature();
|
|
70
69
|
if (looksLikeProp)
|
|
71
70
|
print.breakline();
|
|
72
71
|
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {isDecorator} = require('@putout/babel').types;
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
isLast,
|
|
6
|
+
isCoupleLines,
|
|
7
|
+
isNext,
|
|
8
|
+
} = require('../is');
|
|
5
9
|
|
|
6
10
|
const hasBody = (path) => path.node.body;
|
|
7
11
|
|
|
@@ -30,7 +34,7 @@ module.exports.parseTrailingComments = (path, {write, maybe}, semantics) => {
|
|
|
30
34
|
|
|
31
35
|
if (hasBody(path)) {
|
|
32
36
|
write.breakline();
|
|
33
|
-
write.breakline();
|
|
37
|
+
maybe.write.breakline(!isNext(path));
|
|
34
38
|
}
|
|
35
39
|
|
|
36
40
|
write(`//${value}`);
|
|
@@ -30,10 +30,9 @@ module.exports.ArrowFunctionExpression = maybeParens((path, printer, semantics)
|
|
|
30
30
|
|
|
31
31
|
const body = path.get('body');
|
|
32
32
|
|
|
33
|
-
const insideCall = path.parentPath.isCallExpression();
|
|
34
33
|
const isJSX = body.isJSXElement();
|
|
35
34
|
|
|
36
|
-
maybe.print.space(!insideCall && isJSX);
|
|
37
35
|
maybe.print.space(!isJSX);
|
|
36
|
+
|
|
38
37
|
print('__body');
|
|
39
38
|
});
|
|
@@ -1,21 +1,28 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {isJSXElement} = require('@putout/babel').types;
|
|
4
|
+
|
|
5
|
+
const isInsideArrow = ({parentPath}) => parentPath.isArrowFunctionExpression();
|
|
6
|
+
|
|
3
7
|
module.exports.JSXElement = {
|
|
4
8
|
condition,
|
|
5
|
-
before(path, {write, indent}) {
|
|
6
|
-
|
|
9
|
+
before(path, {write, indent, maybe}) {
|
|
10
|
+
const {leadingComments} = path.node;
|
|
11
|
+
|
|
12
|
+
maybe.write.space(!leadingComments && isInsideArrow(path));
|
|
7
13
|
indent.inc();
|
|
8
|
-
|
|
14
|
+
|
|
15
|
+
if (!leadingComments) {
|
|
16
|
+
write('(');
|
|
17
|
+
write.newline();
|
|
18
|
+
}
|
|
9
19
|
},
|
|
10
|
-
print(path, {print, traverse, indent
|
|
20
|
+
print(path, {print, traverse, indent}) {
|
|
11
21
|
const insideFn = path.parentPath.isArrowFunctionExpression();
|
|
12
22
|
const insideCall = path.parentPath.parentPath.isCallExpression();
|
|
13
23
|
|
|
14
|
-
if (insideFn && insideCall)
|
|
15
|
-
indent.inc();
|
|
24
|
+
if (insideFn && insideCall)
|
|
16
25
|
indent.inc();
|
|
17
|
-
indent();
|
|
18
|
-
}
|
|
19
26
|
|
|
20
27
|
print('__openingElement');
|
|
21
28
|
path
|
|
@@ -24,16 +31,22 @@ module.exports.JSXElement = {
|
|
|
24
31
|
|
|
25
32
|
print('__closingElement');
|
|
26
33
|
|
|
27
|
-
if (insideFn && insideCall)
|
|
34
|
+
if (insideFn && insideCall)
|
|
28
35
|
indent.dec();
|
|
29
|
-
|
|
36
|
+
},
|
|
37
|
+
after(path, {write, indent, maybe}) {
|
|
38
|
+
const {leadingComments} = path.node;
|
|
39
|
+
const isJSX = isJSXElement(path.parentPath.parentPath?.parentPath?.parentPath);
|
|
40
|
+
|
|
41
|
+
if (isJSX) {
|
|
42
|
+
write.breakline();
|
|
30
43
|
indent.dec();
|
|
44
|
+
} else {
|
|
45
|
+
indent.dec();
|
|
46
|
+
write.breakline();
|
|
31
47
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
indent.dec();
|
|
35
|
-
write.breakline();
|
|
36
|
-
write(')');
|
|
48
|
+
|
|
49
|
+
maybe.write(!leadingComments, ')');
|
|
37
50
|
},
|
|
38
51
|
};
|
|
39
52
|
|
|
@@ -44,5 +57,8 @@ function condition(path) {
|
|
|
44
57
|
if (path.node.extra?.parenthesized)
|
|
45
58
|
return true;
|
|
46
59
|
|
|
60
|
+
if (path.parentPath.isArrowFunctionExpression())
|
|
61
|
+
return true;
|
|
62
|
+
|
|
47
63
|
return path.parentPath.isVariableDeclarator();
|
|
48
64
|
}
|
|
@@ -2,8 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
const {isCoupleLines} = require('../is');
|
|
4
4
|
|
|
5
|
+
const isNotJSX = ({parentPath}) => {
|
|
6
|
+
if (parentPath.parentPath.isJSXElement())
|
|
7
|
+
return false;
|
|
8
|
+
|
|
9
|
+
if (parentPath.parentPath.isJSXExpressionContainer())
|
|
10
|
+
return false;
|
|
11
|
+
|
|
12
|
+
return !parentPath.parentPath.isJSXFragment();
|
|
13
|
+
};
|
|
14
|
+
|
|
5
15
|
module.exports.JSXOpeningElement = {
|
|
6
16
|
print(path, {print, maybe}) {
|
|
17
|
+
maybe.indent(isNotJSX(path));
|
|
7
18
|
print('<');
|
|
8
19
|
print('__name');
|
|
9
20
|
|
package/package.json
CHANGED