@putout/printer 2.60.0 → 2.62.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 +5 -4
- package/lib/tokenize/expressions/call-expression.js +2 -2
- package/lib/tokenize/statements/switch-statement.js +1 -0
- package/lib/tokenize/typescript/index.js +2 -0
- package/lib/tokenize/typescript/ts-intersection-type.js +18 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -14,13 +14,14 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
|
|
|
14
14
|
if (!leadingComments?.length)
|
|
15
15
|
return;
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
const looksLikeSwitchCase = path.isSwitchCase();
|
|
18
|
+
|
|
19
|
+
if (!looksLikeSwitchCase && hasTrailingComment(path.getPrevSibling()))
|
|
18
20
|
return;
|
|
19
21
|
|
|
20
|
-
const looksLikeSwitchCase = path.isSwitchCase();
|
|
21
22
|
const insideFn = path.parentPath.isFunction();
|
|
22
23
|
const isProperty = path.isObjectProperty() || isVariableDeclarator(path);
|
|
23
|
-
const isIndent = looksLikeSwitchCase
|
|
24
|
+
const isIndent = !looksLikeSwitchCase && !path.isClassMethod() && !insideFn && !isProperty;
|
|
24
25
|
|
|
25
26
|
for (const {type, value} of leadingComments) {
|
|
26
27
|
maybe.indent(isIndent);
|
|
@@ -52,7 +53,7 @@ module.exports.parseLeadingComments = (path, {print, maybe, indent}, semantics)
|
|
|
52
53
|
if (path.isStatement() || looksLikeDirective || looksLikeMethod || looksLikeProp || looksLikeSwitchCase) {
|
|
53
54
|
print.newline();
|
|
54
55
|
markBefore(path);
|
|
55
|
-
maybe.indent(looksLikeMethod || looksLikeProp);
|
|
56
|
+
maybe.indent(looksLikeMethod || looksLikeProp || looksLikeSwitchCase);
|
|
56
57
|
}
|
|
57
58
|
|
|
58
59
|
continue;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
const {exists} = require('../is');
|
|
4
4
|
|
|
5
5
|
function CallExpression(path, {indent, print, maybe, traverse}) {
|
|
6
|
-
const isParentCall =
|
|
6
|
+
const isParentCall = tooLong(path) && path.parentPath.isCallExpression();
|
|
7
7
|
|
|
8
8
|
const callee = path.get('callee');
|
|
9
9
|
const typeParameters = path.get('typeParameters');
|
|
@@ -58,7 +58,7 @@ function CallExpression(path, {indent, print, maybe, traverse}) {
|
|
|
58
58
|
module.exports.OptionalCallExpression = CallExpression;
|
|
59
59
|
module.exports.CallExpression = CallExpression;
|
|
60
60
|
|
|
61
|
-
function
|
|
61
|
+
function tooLong(path) {
|
|
62
62
|
const args = path.get('arguments');
|
|
63
63
|
|
|
64
64
|
for (const arg of args) {
|
|
@@ -16,6 +16,7 @@ const {
|
|
|
16
16
|
const {TSInterfaceDeclaration} = require('./interface/ts-interface-declaration');
|
|
17
17
|
const {TSAsExpression} = require('./ts-as-expression');
|
|
18
18
|
const {TSInterfaceBody} = require('./interface/ts-interface-body');
|
|
19
|
+
const {TSIntersectionType} = require('./ts-intersection-type');
|
|
19
20
|
|
|
20
21
|
module.exports = {
|
|
21
22
|
TSAsExpression,
|
|
@@ -27,6 +28,7 @@ module.exports = {
|
|
|
27
28
|
TSDeclareFunction,
|
|
28
29
|
TSModuleDeclaration,
|
|
29
30
|
TSModuleBlock,
|
|
31
|
+
TSIntersectionType,
|
|
30
32
|
TSBigIntKeyword(path, {write}) {
|
|
31
33
|
write('bigint');
|
|
32
34
|
},
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.TSIntersectionType = (path, {traverse, write}) => {
|
|
4
|
+
const types = path.get('types');
|
|
5
|
+
const n = types.length - 1;
|
|
6
|
+
|
|
7
|
+
for (const [i, type] of types.entries()) {
|
|
8
|
+
const isLast = i === n;
|
|
9
|
+
|
|
10
|
+
traverse(type);
|
|
11
|
+
|
|
12
|
+
if (!isLast) {
|
|
13
|
+
write.space();
|
|
14
|
+
write('&');
|
|
15
|
+
write.space();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
package/package.json
CHANGED