@putout/printer 5.2.0 → 5.4.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 +11 -0
- package/lib/tokenize/expressions/array-pattern.js +3 -2
- package/lib/tokenize/expressions/object-expression/object-expression.js +5 -14
- package/lib/tokenize/expressions/object-expression/record-expression.js +1 -5
- package/lib/tokenize/expressions/object-pattern/object-pattern.js +3 -9
- package/lib/tokenize/expressions/rest-element.js +3 -11
- package/lib/tokenize/literals/identifier.js +3 -5
- package/lib/tokenize/literals/maybe-type-annotation.js +14 -0
- package/lib/tokenize/typescript/index.js +0 -5
- package/lib/tokenize/typescript/ts-property-signature.js +3 -10
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.09.20, v5.4.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 896b185 @putout/printer: maybeTypeAnnotation
|
|
5
|
+
- 74f9303 @putout/printer: ObjectExpression: maybeParens
|
|
6
|
+
|
|
7
|
+
2023.09.19, v5.3.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- c0b651a @putout/printer: ArrayPattern: typeAnnotation
|
|
11
|
+
|
|
1
12
|
2023.09.19, v5.2.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {maybeTypeAnnotation} = require('../literals/maybe-type-annotation');
|
|
3
4
|
const isForOf = ({parentPath}) => parentPath.parentPath.parentPath?.isForOfStatement();
|
|
4
5
|
|
|
5
|
-
module.exports.ArrayPattern = (path, {indent, maybe, print}, options) => {
|
|
6
|
+
module.exports.ArrayPattern = maybeTypeAnnotation((path, {indent, maybe, print}, options) => {
|
|
6
7
|
const {maxElementsInOneLine} = options;
|
|
7
8
|
|
|
8
9
|
print('[');
|
|
@@ -30,4 +31,4 @@ module.exports.ArrayPattern = (path, {indent, maybe, print}, options) => {
|
|
|
30
31
|
indent.dec();
|
|
31
32
|
maybe.indent(elements.length && isNewLine);
|
|
32
33
|
print(']');
|
|
33
|
-
};
|
|
34
|
+
});
|
|
@@ -13,11 +13,10 @@ const {
|
|
|
13
13
|
|
|
14
14
|
const {parseComments} = require('../../comment/comment');
|
|
15
15
|
const {likeChain} = require('../member-expression/member-expressions');
|
|
16
|
+
const {maybeParens} = require('../function/parens');
|
|
16
17
|
|
|
17
|
-
const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
|
|
18
18
|
const isLogical = (path) => path.get('argument').isLogicalExpression();
|
|
19
19
|
const isValue = (path) => path.get('properties.0.value').node;
|
|
20
|
-
const isParentExpression = (path) => path.parentPath.isExpressionStatement();
|
|
21
20
|
|
|
22
21
|
const isMemberExpressionCallee = ({parentPath}) => {
|
|
23
22
|
if (!parentPath.isCallExpression())
|
|
@@ -31,16 +30,16 @@ const isMemberExpressionCallee = ({parentPath}) => {
|
|
|
31
30
|
return likeChain(callee);
|
|
32
31
|
};
|
|
33
32
|
|
|
34
|
-
module.exports.ObjectExpression = (path, {print, maybe, indent, write}, semantics) => {
|
|
33
|
+
module.exports.ObjectExpression = maybeParens((path, {print, maybe, indent, write}, semantics) => {
|
|
35
34
|
const {trailingComma} = semantics;
|
|
36
35
|
indent.inc();
|
|
37
36
|
|
|
38
37
|
const properties = path.get('properties');
|
|
39
38
|
const {length} = properties;
|
|
40
|
-
const parens = isParens(path);
|
|
41
39
|
const manyLines = !isOneLine(path);
|
|
42
40
|
|
|
43
|
-
maybe.print(
|
|
41
|
+
maybe.print(path.isRecordExpression(), '#');
|
|
42
|
+
|
|
44
43
|
print('{');
|
|
45
44
|
parseComments(path, {write}, semantics);
|
|
46
45
|
maybe.print.newline(manyLines);
|
|
@@ -82,10 +81,9 @@ module.exports.ObjectExpression = (path, {print, maybe, indent, write}, semantic
|
|
|
82
81
|
indent.dec();
|
|
83
82
|
maybe.indent(manyLines);
|
|
84
83
|
print('}');
|
|
85
|
-
maybe.print(parens, ')');
|
|
86
84
|
|
|
87
85
|
maybe.indent.dec(isMemberExpressionCallee(path));
|
|
88
|
-
};
|
|
86
|
+
});
|
|
89
87
|
|
|
90
88
|
const hasNextLeadingComment = (path) => {
|
|
91
89
|
const next = path.getNextSibling();
|
|
@@ -134,10 +132,3 @@ function isOneLine(path) {
|
|
|
134
132
|
|
|
135
133
|
return !isValue(path);
|
|
136
134
|
}
|
|
137
|
-
|
|
138
|
-
function isParens(path) {
|
|
139
|
-
if (isBodyOfArrow(path))
|
|
140
|
-
return true;
|
|
141
|
-
|
|
142
|
-
return isParentExpression(path);
|
|
143
|
-
}
|
|
@@ -2,8 +2,4 @@
|
|
|
2
2
|
|
|
3
3
|
const {ObjectExpression} = require('./object-expression');
|
|
4
4
|
|
|
5
|
-
module.exports.RecordExpression =
|
|
6
|
-
const {write} = operations;
|
|
7
|
-
write('#');
|
|
8
|
-
ObjectExpression(path, operations, semantics);
|
|
9
|
-
};
|
|
5
|
+
module.exports.RecordExpression = ObjectExpression;
|
|
@@ -15,13 +15,14 @@ const {
|
|
|
15
15
|
} = require('../../is');
|
|
16
16
|
|
|
17
17
|
const {checkMaxPropertiesInOneLine} = require('./max-properties-in-one-line');
|
|
18
|
+
const {maybeTypeAnnotation} = require('../../literals/maybe-type-annotation');
|
|
18
19
|
|
|
19
20
|
const isTwoLevelsDeep = ({parentPath}) => parentPath.parentPath.parentPath.isObjectProperty();
|
|
20
21
|
|
|
21
22
|
const isOneParentProperty = ({parentPath}) => parentPath.parentPath.node.properties?.length === 1;
|
|
22
23
|
|
|
23
24
|
module.exports.ObjectPattern = {
|
|
24
|
-
print(path, {indent, print, maybe}, semantics) {
|
|
25
|
+
print: maybeTypeAnnotation((path, {indent, print, maybe}, semantics) => {
|
|
25
26
|
const {maxPropertiesInOneLine} = semantics;
|
|
26
27
|
|
|
27
28
|
indent.inc();
|
|
@@ -89,14 +90,7 @@ module.exports.ObjectPattern = {
|
|
|
89
90
|
indent.dec();
|
|
90
91
|
maybe.indent(is);
|
|
91
92
|
print('}');
|
|
92
|
-
|
|
93
|
-
const {typeAnnotation} = path.node;
|
|
94
|
-
|
|
95
|
-
if (typeAnnotation) {
|
|
96
|
-
print(': ');
|
|
97
|
-
print('__typeAnnotation');
|
|
98
|
-
}
|
|
99
|
-
},
|
|
93
|
+
}),
|
|
100
94
|
afterIf(path) {
|
|
101
95
|
if (!path.parentPath.isObjectProperty())
|
|
102
96
|
return false;
|
|
@@ -1,16 +1,8 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {maybeTypeAnnotation} = require('../literals/maybe-type-annotation');
|
|
4
4
|
|
|
5
|
-
module.exports.RestElement = (path, {print
|
|
6
|
-
const typeAnnotation = path.get('typeAnnotation');
|
|
7
|
-
|
|
5
|
+
module.exports.RestElement = maybeTypeAnnotation((path, {print}) => {
|
|
8
6
|
print('...');
|
|
9
7
|
print('__argument');
|
|
10
|
-
|
|
11
|
-
if (exists(typeAnnotation)) {
|
|
12
|
-
print(':');
|
|
13
|
-
print.space();
|
|
14
|
-
traverse(typeAnnotation);
|
|
15
|
-
}
|
|
16
|
-
};
|
|
8
|
+
});
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
const {maybeDecorators} = require('../maybe-get');
|
|
4
4
|
const {maybeParens} = require('../expressions/function/parens');
|
|
5
|
+
const {maybeTypeAnnotation} = require('./maybe-type-annotation');
|
|
5
6
|
|
|
6
|
-
module.exports.Identifier = maybeParens((path, printer) => {
|
|
7
|
+
module.exports.Identifier = maybeParens(maybeTypeAnnotation((path, printer) => {
|
|
7
8
|
const {
|
|
8
9
|
write,
|
|
9
10
|
maybe,
|
|
@@ -14,8 +15,6 @@ module.exports.Identifier = maybeParens((path, printer) => {
|
|
|
14
15
|
const {node} = path;
|
|
15
16
|
const {name, optional} = node;
|
|
16
17
|
|
|
17
|
-
const typeAnnotation = path.get('typeAnnotation');
|
|
18
|
-
|
|
19
18
|
for (const decorator of maybeDecorators(path)) {
|
|
20
19
|
traverse(decorator);
|
|
21
20
|
print(' ');
|
|
@@ -23,5 +22,4 @@ module.exports.Identifier = maybeParens((path, printer) => {
|
|
|
23
22
|
|
|
24
23
|
write(name);
|
|
25
24
|
maybe.write(optional, '?');
|
|
26
|
-
|
|
27
|
-
});
|
|
25
|
+
}));
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.maybeTypeAnnotation = (visit) => (path, printer, semantics) => {
|
|
4
|
+
const {typeAnnotation} = path.node;
|
|
5
|
+
const {print} = printer;
|
|
6
|
+
|
|
7
|
+
visit(path, printer, semantics);
|
|
8
|
+
|
|
9
|
+
if (typeAnnotation) {
|
|
10
|
+
print(':');
|
|
11
|
+
print.space();
|
|
12
|
+
print('__typeAnnotation');
|
|
13
|
+
}
|
|
14
|
+
};
|
|
@@ -177,11 +177,6 @@ module.exports = {
|
|
|
177
177
|
print('__parameter');
|
|
178
178
|
},
|
|
179
179
|
TSTypeAnnotation(path, {print}) {
|
|
180
|
-
if (path.parentPath.isIdentifier()) {
|
|
181
|
-
print(':');
|
|
182
|
-
print.space();
|
|
183
|
-
}
|
|
184
|
-
|
|
185
180
|
print('__typeAnnotation');
|
|
186
181
|
},
|
|
187
182
|
TSConstructSignatureDeclaration,
|
|
@@ -1,17 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {maybeTypeAnnotation} = require('../literals/maybe-type-annotation');
|
|
4
4
|
|
|
5
|
-
module.exports.TSPropertySignature = (path, {print, maybe
|
|
5
|
+
module.exports.TSPropertySignature = maybeTypeAnnotation((path, {print, maybe}) => {
|
|
6
6
|
const {optional} = path.node;
|
|
7
|
-
const typeAnnotation = path.get('typeAnnotation');
|
|
8
7
|
|
|
9
8
|
print('__key');
|
|
10
9
|
maybe.print(optional, '?');
|
|
11
|
-
|
|
12
|
-
if (exists(typeAnnotation)) {
|
|
13
|
-
print(':');
|
|
14
|
-
print.space();
|
|
15
|
-
traverse(typeAnnotation);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
10
|
+
});
|
package/package.json
CHANGED