@putout/printer 2.78.0 → 2.80.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-leading-comments.js +3 -2
- package/lib/tokenize/expressions/{class-property.js → class/class-property.js} +15 -1
- package/lib/tokenize/expressions/index.js +1 -1
- package/lib/tokenize/statements/return-statement/return-statement.js +1 -1
- package/lib/tokenize/statements/switch-statement.js +1 -1
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +10 -1
- package/lib/tokenize/typescript/enum/ts-enum-declaration.js +0 -1
- package/lib/tokenize/typescript/index.js +10 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -36,8 +36,9 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
|
|
|
36
36
|
maybe.print.space(isProperty);
|
|
37
37
|
print(`//${value}`);
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
maybe.print.
|
|
39
|
+
const isParentSwitch = path.parentPath.isSwitchCase();
|
|
40
|
+
maybe.print.breakline(isProperty || isParentSwitch);
|
|
41
|
+
maybe.print.newline(!isProperty && !isParentSwitch);
|
|
41
42
|
continue;
|
|
42
43
|
}
|
|
43
44
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {exists} = require('
|
|
3
|
+
const {exists} = require('../../is');
|
|
4
4
|
|
|
5
5
|
module.exports.ClassProperty = ClassProperty;
|
|
6
6
|
|
|
@@ -16,9 +16,23 @@ module.exports.PrivateName = (path, {print}) => {
|
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
function ClassProperty(path, {print}) {
|
|
19
|
+
const {accessibility} = path.node;
|
|
19
20
|
const value = path.get('value');
|
|
21
|
+
const typeAnnotation = path.get('typeAnnotation');
|
|
22
|
+
|
|
23
|
+
if (accessibility) {
|
|
24
|
+
print(accessibility);
|
|
25
|
+
print(' ');
|
|
26
|
+
}
|
|
27
|
+
|
|
20
28
|
print('__key');
|
|
21
29
|
|
|
30
|
+
if (exists(typeAnnotation)) {
|
|
31
|
+
print(':');
|
|
32
|
+
print.space();
|
|
33
|
+
print(typeAnnotation);
|
|
34
|
+
}
|
|
35
|
+
|
|
22
36
|
if (exists(value)) {
|
|
23
37
|
print.space();
|
|
24
38
|
print('=');
|
|
@@ -24,7 +24,7 @@ const {
|
|
|
24
24
|
ClassProperty,
|
|
25
25
|
ClassPrivateProperty,
|
|
26
26
|
PrivateName,
|
|
27
|
-
} = require('./class-property');
|
|
27
|
+
} = require('./class/class-property');
|
|
28
28
|
|
|
29
29
|
const {AssignmentExpression} = require('./assignment-expression');
|
|
30
30
|
const {ArrayExpression} = require('./array-expression/array-expression');
|
|
@@ -8,6 +8,7 @@ const {
|
|
|
8
8
|
|
|
9
9
|
const {hasPrevNewline} = require('../../mark');
|
|
10
10
|
const {maybeSpaceAfterKeyword} = require('./maybe-space-after-keyword');
|
|
11
|
+
|
|
11
12
|
const isBodyLength = ({parentPath}) => parentPath.node?.body?.length > 2;
|
|
12
13
|
|
|
13
14
|
module.exports.ReturnStatement = {
|
|
@@ -24,7 +25,6 @@ module.exports.ReturnStatement = {
|
|
|
24
25
|
print,
|
|
25
26
|
});
|
|
26
27
|
print('__argument');
|
|
27
|
-
|
|
28
28
|
print(';');
|
|
29
29
|
},
|
|
30
30
|
afterIf: (path) => {
|
|
@@ -17,6 +17,8 @@ const {parseLeadingComments} = require('../../comment/comment');
|
|
|
17
17
|
|
|
18
18
|
const isParentBlock = (path) => /Program|BlockStatement|Export/.test(path.parentPath.type);
|
|
19
19
|
const isInsideBlock = (path) => /^(Program|BlockStatement)$/.test(path.parentPath.type);
|
|
20
|
+
const isParentSwitchCase = (path) => path.parentPath.isSwitchCase();
|
|
21
|
+
const isFirstInSwitch = (path) => path.parentPath.get('consequent.0') === path;
|
|
20
22
|
|
|
21
23
|
module.exports.VariableDeclaration = {
|
|
22
24
|
beforeIf: shouldAddNewlineBefore,
|
|
@@ -72,10 +74,17 @@ module.exports.VariableDeclaration = {
|
|
|
72
74
|
}
|
|
73
75
|
|
|
74
76
|
maybe.indent.dec(n);
|
|
75
|
-
maybe.write(isParentBlock(path), ';');
|
|
77
|
+
maybe.write(isParentBlock(path) || isParentSwitchCase(path), ';');
|
|
76
78
|
|
|
77
79
|
let wasNewline = false;
|
|
78
80
|
|
|
81
|
+
if (isParentSwitchCase(path) && !isFirstInSwitch(path)) {
|
|
82
|
+
write.newline();
|
|
83
|
+
wasNewline = true;
|
|
84
|
+
} else if (isParentSwitchCase(path)) {
|
|
85
|
+
write.breakline();
|
|
86
|
+
}
|
|
87
|
+
|
|
79
88
|
if (isParentBlock(path) && isNext(path) && (noTrailingComment(path) || isNewlineBetweenSiblings(path))) {
|
|
80
89
|
write.newline();
|
|
81
90
|
wasNewline = true;
|
|
@@ -243,4 +243,14 @@ module.exports = {
|
|
|
243
243
|
},
|
|
244
244
|
TSEnumDeclaration,
|
|
245
245
|
TSEnumMember,
|
|
246
|
+
TSImportEqualsDeclaration(path, {print}) {
|
|
247
|
+
print('import ');
|
|
248
|
+
print('__id');
|
|
249
|
+
print.space();
|
|
250
|
+
print('=');
|
|
251
|
+
print.space();
|
|
252
|
+
print('__moduleReference');
|
|
253
|
+
print(';');
|
|
254
|
+
print.newline();
|
|
255
|
+
},
|
|
246
256
|
};
|
package/package.json
CHANGED