@putout/printer 5.32.0 → 5.34.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/comment/parse-comments.js +14 -3
- package/lib/tokenize/expressions/object-expression/object-expression.js +8 -2
- package/lib/tokenize/jsx/jsx-element.js +4 -0
- package/lib/tokenize/jsx/jsx-text.js +5 -2
- package/lib/tokenize/statements/block-statement/block-statement.js +8 -2
- package/lib/tokenize/statements/program/program.js +8 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
const {isNext} = require('../is');
|
|
4
|
+
|
|
5
|
+
module.exports.parseComments = (path, {write, maybe}, semantics) => {
|
|
4
6
|
if (!semantics.comments)
|
|
5
7
|
return;
|
|
6
8
|
|
|
@@ -9,11 +11,20 @@ module.exports.parseComments = (path, {write}, semantics) => {
|
|
|
9
11
|
if (!comments)
|
|
10
12
|
return;
|
|
11
13
|
|
|
12
|
-
|
|
14
|
+
const n = comments.length - 1;
|
|
15
|
+
const program = path.isProgram();
|
|
16
|
+
|
|
17
|
+
for (const [i, {type, value}] of comments.entries()) {
|
|
13
18
|
if (type === 'CommentLine') {
|
|
14
|
-
write.breakline();
|
|
19
|
+
maybe.write.breakline(isNext(path) || !program);
|
|
15
20
|
write('//');
|
|
16
21
|
write(value);
|
|
22
|
+
|
|
23
|
+
if (program) {
|
|
24
|
+
maybe.write.newline(i < n);
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
|
|
17
28
|
write.newline();
|
|
18
29
|
continue;
|
|
19
30
|
}
|
|
@@ -31,8 +31,14 @@ const isMemberExpressionCallee = ({parentPath}) => {
|
|
|
31
31
|
return likeChain(callee);
|
|
32
32
|
};
|
|
33
33
|
|
|
34
|
-
module.exports.ObjectExpression = (path,
|
|
34
|
+
module.exports.ObjectExpression = (path, printer, semantics) => {
|
|
35
35
|
const {trailingComma} = semantics;
|
|
36
|
+
const {
|
|
37
|
+
print,
|
|
38
|
+
maybe,
|
|
39
|
+
indent,
|
|
40
|
+
} = printer;
|
|
41
|
+
|
|
36
42
|
indent.inc();
|
|
37
43
|
|
|
38
44
|
const properties = path.get('properties');
|
|
@@ -42,7 +48,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent, write}, semantic
|
|
|
42
48
|
|
|
43
49
|
maybe.print(parens, '(');
|
|
44
50
|
print('{');
|
|
45
|
-
parseComments(path,
|
|
51
|
+
parseComments(path, printer, semantics);
|
|
46
52
|
maybe.print.newline(manyLines);
|
|
47
53
|
|
|
48
54
|
const n = properties.length - 1;
|
|
@@ -21,6 +21,7 @@ module.exports.JSXElement = {
|
|
|
21
21
|
path
|
|
22
22
|
.get('children')
|
|
23
23
|
.map(traverse);
|
|
24
|
+
|
|
24
25
|
print('__closingElement');
|
|
25
26
|
|
|
26
27
|
if (insideFn && insideCall) {
|
|
@@ -40,5 +41,8 @@ function condition(path) {
|
|
|
40
41
|
if (path.parentPath.isReturnStatement())
|
|
41
42
|
return true;
|
|
42
43
|
|
|
44
|
+
if (path.node.extra?.parenthesized)
|
|
45
|
+
return true;
|
|
46
|
+
|
|
43
47
|
return path.parentPath.isVariableDeclarator();
|
|
44
48
|
}
|
|
@@ -3,10 +3,14 @@
|
|
|
3
3
|
const {isNext} = require('../is');
|
|
4
4
|
|
|
5
5
|
module.exports.JSXText = (path, {write, indent}) => {
|
|
6
|
-
const {
|
|
6
|
+
const {node} = path;
|
|
7
|
+
const {value, extra} = node;
|
|
7
8
|
const isSpacesOnly = /^\s+$/.test(value);
|
|
8
9
|
const hasNext = isNext(path);
|
|
9
10
|
|
|
11
|
+
if (extra?.raw.startsWith('&'))
|
|
12
|
+
return write(extra.raw);
|
|
13
|
+
|
|
10
14
|
if (isSpacesOnly && hasNext) {
|
|
11
15
|
indent.inc();
|
|
12
16
|
write.breakline();
|
|
@@ -17,7 +21,6 @@ module.exports.JSXText = (path, {write, indent}) => {
|
|
|
17
21
|
|
|
18
22
|
if (isSpacesOnly) {
|
|
19
23
|
write.breakline();
|
|
20
|
-
|
|
21
24
|
return;
|
|
22
25
|
}
|
|
23
26
|
|
|
@@ -29,7 +29,13 @@ const parentIfWithoutElse = ({parentPath}) => {
|
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
module.exports.BlockStatement = {
|
|
32
|
-
print(path,
|
|
32
|
+
print(path, printer, semantics) {
|
|
33
|
+
const {
|
|
34
|
+
indent,
|
|
35
|
+
maybe,
|
|
36
|
+
write,
|
|
37
|
+
traverse,
|
|
38
|
+
} = printer;
|
|
33
39
|
const body = path.get('body');
|
|
34
40
|
const directives = getDirectives(path);
|
|
35
41
|
|
|
@@ -50,7 +56,7 @@ module.exports.BlockStatement = {
|
|
|
50
56
|
traverse(element);
|
|
51
57
|
}
|
|
52
58
|
|
|
53
|
-
parseComments(path,
|
|
59
|
+
parseComments(path, printer, semantics);
|
|
54
60
|
|
|
55
61
|
indent.dec();
|
|
56
62
|
maybe.indent(body.length);
|
|
@@ -3,10 +3,16 @@
|
|
|
3
3
|
const {parseComments} = require('../../comment/comment');
|
|
4
4
|
const {getDirectives} = require('../block-statement/get-directives');
|
|
5
5
|
|
|
6
|
-
module.exports.Program = (path,
|
|
6
|
+
module.exports.Program = (path, printer, semantics) => {
|
|
7
7
|
const {body} = path.node;
|
|
8
|
+
const {
|
|
9
|
+
print,
|
|
10
|
+
traverse,
|
|
11
|
+
maybe,
|
|
12
|
+
} = printer;
|
|
13
|
+
|
|
8
14
|
print('__interpreter');
|
|
9
|
-
parseComments(path,
|
|
15
|
+
parseComments(path, printer, semantics);
|
|
10
16
|
|
|
11
17
|
const directives = getDirectives(path);
|
|
12
18
|
|
package/package.json
CHANGED