@putout/printer 1.70.3 → 1.71.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/comments.js +21 -8
- package/lib/tokenize/expressions/object-expression.js +4 -3
- package/lib/tokenize/is.js +2 -0
- package/lib/tokenize/statements/export-declarations.js +1 -0
- package/lib/tokenize/statements/import-declaration.js +7 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2023.04.25, v1.71.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- b56cdb1 @putout/printer: ImportDeclaration: improve support of ImportSpecifier
|
|
5
|
+
|
|
6
|
+
2023.04.25, v1.70.4
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- b59320e @putout/printer: improve printing of comments after ObjectProperty
|
|
10
|
+
|
|
1
11
|
2023.04.25, v1.70.3
|
|
2
12
|
|
|
3
13
|
feature:
|
package/lib/tokenize/comments.js
CHANGED
|
@@ -4,28 +4,30 @@ const {isNext} = require('./is');
|
|
|
4
4
|
|
|
5
5
|
const {markBefore} = require('./mark');
|
|
6
6
|
|
|
7
|
-
module.exports.parseLeadingComments = (path, {print, maybe}) => {
|
|
7
|
+
module.exports.parseLeadingComments = (path, {print, maybe, indent}) => {
|
|
8
8
|
const {leadingComments} = path.node;
|
|
9
9
|
|
|
10
10
|
if (!leadingComments || !leadingComments.length)
|
|
11
11
|
return;
|
|
12
12
|
|
|
13
13
|
const insideFn = path.parentPath.isFunction();
|
|
14
|
-
const
|
|
14
|
+
const isProperty = path.isObjectProperty();
|
|
15
|
+
const isIndent = !path.isClassMethod() && !insideFn && !isProperty;
|
|
15
16
|
|
|
16
17
|
for (const {type, value} of leadingComments) {
|
|
17
18
|
maybe.indent(isIndent);
|
|
18
19
|
|
|
19
20
|
if (type === 'CommentLine') {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
maybe.indent.dec(insideFn);
|
|
21
|
+
maybeInsideFn(insideFn, {
|
|
22
|
+
print,
|
|
23
|
+
indent,
|
|
24
|
+
});
|
|
25
25
|
|
|
26
|
+
maybe.print.space(isProperty);
|
|
26
27
|
print(`//${value}`);
|
|
27
|
-
print.newline();
|
|
28
28
|
|
|
29
|
+
maybe.print.breakline(isProperty);
|
|
30
|
+
maybe.print.newline(!isProperty);
|
|
29
31
|
continue;
|
|
30
32
|
}
|
|
31
33
|
|
|
@@ -67,3 +69,14 @@ module.exports.parseTrailingComments = (path, {write, maybe}) => {
|
|
|
67
69
|
function isSameLine(path, loc) {
|
|
68
70
|
return path.node.loc.start.line === loc.start.line;
|
|
69
71
|
}
|
|
72
|
+
|
|
73
|
+
function maybeInsideFn(insideFn, {print, indent}) {
|
|
74
|
+
if (!insideFn)
|
|
75
|
+
return;
|
|
76
|
+
|
|
77
|
+
indent.inc();
|
|
78
|
+
indent.inc();
|
|
79
|
+
print.breakline();
|
|
80
|
+
indent.dec();
|
|
81
|
+
indent.dec();
|
|
82
|
+
}
|
|
@@ -6,7 +6,8 @@ const {
|
|
|
6
6
|
isIf,
|
|
7
7
|
noTrailingComment,
|
|
8
8
|
isNewlineBetweenSiblings,
|
|
9
|
-
|
|
9
|
+
noLeadingComment,
|
|
10
|
+
noComment,
|
|
10
11
|
} = require('../is');
|
|
11
12
|
|
|
12
13
|
const {isFunction} = require('@babel/types');
|
|
@@ -43,7 +44,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
|
|
|
43
44
|
continue;
|
|
44
45
|
}
|
|
45
46
|
|
|
46
|
-
maybe.indent(manyLines);
|
|
47
|
+
maybe.indent(manyLines && noLeadingComment(property));
|
|
47
48
|
|
|
48
49
|
if (property.isObjectMethod()) {
|
|
49
50
|
print(property);
|
|
@@ -51,7 +52,7 @@ module.exports.ObjectExpression = (path, {print, maybe, indent}) => {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
print(property);
|
|
54
|
-
maybe.print.newline(manyLines && noTrailingComment(property));
|
|
55
|
+
maybe.print.newline(manyLines && noTrailingComment(property) && noComment(property));
|
|
55
56
|
maybe.print.linebreak(isNewlineBetweenSiblings(property));
|
|
56
57
|
}
|
|
57
58
|
|
package/lib/tokenize/is.js
CHANGED
|
@@ -87,3 +87,5 @@ module.exports.satisfy = (conditions) => (path) => {
|
|
|
87
87
|
};
|
|
88
88
|
|
|
89
89
|
module.exports.noTrailingComment = (path) => !path.node.trailingComments?.length;
|
|
90
|
+
module.exports.noComment = (path) => !path.node.comments?.length;
|
|
91
|
+
module.exports.noLeadingComment = (path) => !path.node.leadingComments?.length;
|
|
@@ -23,12 +23,18 @@ module.exports.ImportDeclaration = {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
if (spec.isImportSpecifier()) {
|
|
26
|
+
const {imported, local} = spec.node;
|
|
26
27
|
maybe.print(index, ', ');
|
|
27
28
|
maybe.print(!wasSpecifier, '{');
|
|
28
29
|
|
|
29
30
|
wasSpecifier = true;
|
|
31
|
+
print(imported.name);
|
|
32
|
+
|
|
33
|
+
if (imported.name !== local.name) {
|
|
34
|
+
print(' as ');
|
|
35
|
+
print(spec.node.local.name);
|
|
36
|
+
}
|
|
30
37
|
|
|
31
|
-
print(spec.get('imported'));
|
|
32
38
|
maybe.print(index === n, '}');
|
|
33
39
|
|
|
34
40
|
continue;
|
package/package.json
CHANGED