@putout/printer 1.34.0 → 1.36.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
CHANGED
|
@@ -9,7 +9,7 @@ module.exports.ObjectPattern = (path, {indent, print, maybe}) => {
|
|
|
9
9
|
|
|
10
10
|
const properties = path.get('properties');
|
|
11
11
|
const n = properties.length - 1;
|
|
12
|
-
const is =
|
|
12
|
+
const is = shouldAddNewline(path);
|
|
13
13
|
|
|
14
14
|
maybe.print(is, '\n');
|
|
15
15
|
|
|
@@ -63,3 +63,16 @@ function checkLength(properties) {
|
|
|
63
63
|
|
|
64
64
|
return false;
|
|
65
65
|
}
|
|
66
|
+
|
|
67
|
+
function shouldAddNewline(path) {
|
|
68
|
+
const properties = path.get('properties');
|
|
69
|
+
const n = properties.length - 1;
|
|
70
|
+
|
|
71
|
+
if (!isForOf(path) && !path.parentPath.isFunction() && n && checkLength(properties))
|
|
72
|
+
return true;
|
|
73
|
+
|
|
74
|
+
if (path.parentPath.isObjectProperty())
|
|
75
|
+
return true;
|
|
76
|
+
|
|
77
|
+
return false;
|
|
78
|
+
}
|
package/lib/tokenize/is.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {exists} = require('../is');
|
|
4
|
+
const {TSTypeLiteral} = require('./ts-type-literal');
|
|
5
|
+
|
|
3
6
|
module.exports = {
|
|
7
|
+
TSTypeLiteral,
|
|
4
8
|
TSTypeParameterDeclaration(path, {print}) {
|
|
5
9
|
print('<');
|
|
6
10
|
|
|
@@ -28,6 +32,10 @@ module.exports = {
|
|
|
28
32
|
TSNumberKeyword(path, {write}) {
|
|
29
33
|
write('number');
|
|
30
34
|
},
|
|
35
|
+
TSInstantiationExpression(path, {print}) {
|
|
36
|
+
print('__expression');
|
|
37
|
+
print('__typeParameters');
|
|
38
|
+
},
|
|
31
39
|
TSAnyKeyword(path, {write}) {
|
|
32
40
|
write('any');
|
|
33
41
|
},
|
|
@@ -63,27 +71,17 @@ module.exports = {
|
|
|
63
71
|
print('__typeAnnotation');
|
|
64
72
|
print(';');
|
|
65
73
|
},
|
|
66
|
-
|
|
67
|
-
write('{');
|
|
68
|
-
write.newline();
|
|
69
|
-
indent.inc();
|
|
70
|
-
|
|
71
|
-
for (const member of path.get('members')) {
|
|
72
|
-
indent();
|
|
73
|
-
traverse(member);
|
|
74
|
-
write(';');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
write.newline();
|
|
78
|
-
indent.dec();
|
|
79
|
-
write('}');
|
|
80
|
-
},
|
|
81
|
-
TSPropertySignature(path, {print, maybe}) {
|
|
74
|
+
TSPropertySignature(path, {print, maybe, traverse}) {
|
|
82
75
|
const {optional} = path.node;
|
|
76
|
+
const typeAnnotation = path.get('typeAnnotation');
|
|
77
|
+
|
|
83
78
|
print('__key');
|
|
84
79
|
maybe.print(optional, '?');
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
80
|
+
|
|
81
|
+
if (exists(typeAnnotation)) {
|
|
82
|
+
print(':');
|
|
83
|
+
print.space();
|
|
84
|
+
traverse(typeAnnotation);
|
|
85
|
+
}
|
|
88
86
|
},
|
|
89
87
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.TSTypeLiteral = (path, {indent, traverse, write, maybe}) => {
|
|
4
|
+
const members = path.get('members');
|
|
5
|
+
write('{');
|
|
6
|
+
|
|
7
|
+
const is = isNewline(path);
|
|
8
|
+
|
|
9
|
+
if (is) {
|
|
10
|
+
write.newline();
|
|
11
|
+
indent.inc();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
for (const member of members) {
|
|
15
|
+
indent();
|
|
16
|
+
traverse(member);
|
|
17
|
+
maybe.write(is, ';');
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (is) {
|
|
21
|
+
write.newline();
|
|
22
|
+
indent.inc();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
write('}');
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
function isNewline(path) {
|
|
29
|
+
const members = path.get('members');
|
|
30
|
+
|
|
31
|
+
if (members.length && members[0].node.typeAnnotation)
|
|
32
|
+
return true;
|
|
33
|
+
|
|
34
|
+
return false;
|
|
35
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.36.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",
|