@putout/printer 15.21.0 → 15.22.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/jsx/jsx-element.js +7 -4
- package/lib/tokenize/literals/template-literal.js +5 -17
- package/lib/tokenize/literals/write-template-literal.js +20 -0
- package/lib/tokenize/typescript/index.js +2 -0
- package/lib/tokenize/typescript/ts-template-literal-type/ts-template-literal-type.js +10 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -5,6 +5,7 @@ const {
|
|
|
5
5
|
isJSXElement,
|
|
6
6
|
isJSXExpressionContainer,
|
|
7
7
|
isFunction,
|
|
8
|
+
isJSXSpreadAttribute,
|
|
8
9
|
} = types;
|
|
9
10
|
|
|
10
11
|
const isInsideArrow = ({parentPath}) => parentPath.isArrowFunctionExpression();
|
|
@@ -69,10 +70,12 @@ function condition(path) {
|
|
|
69
70
|
function hasComplexAttribute(path) {
|
|
70
71
|
const {attributes} = path.node.openingElement;
|
|
71
72
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
for (const attribute of attributes) {
|
|
74
|
+
const {value} = attribute;
|
|
75
|
+
|
|
76
|
+
if (isJSXSpreadAttribute(attribute))
|
|
77
|
+
return true;
|
|
78
|
+
|
|
76
79
|
if (!isJSXExpressionContainer(value))
|
|
77
80
|
continue;
|
|
78
81
|
|
|
@@ -1,22 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
let i = 0;
|
|
3
|
+
const {writeTemplateLiteral} = require('./write-template-literal');
|
|
4
|
+
|
|
5
|
+
module.exports.TemplateLiteral = (path, printer) => {
|
|
7
6
|
const expressions = path.get('expressions');
|
|
7
|
+
const quasis = path.get('quasis');
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
write(element.value.raw);
|
|
11
|
-
|
|
12
|
-
const exp = expressions[i++];
|
|
13
|
-
|
|
14
|
-
if (exp) {
|
|
15
|
-
write('${');
|
|
16
|
-
traverse(exp);
|
|
17
|
-
write('}');
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
write('`');
|
|
9
|
+
writeTemplateLiteral(quasis, expressions, printer);
|
|
22
10
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.writeTemplateLiteral = (quasis, expressions, {write, traverse}) => {
|
|
4
|
+
write('`');
|
|
5
|
+
let i = 0;
|
|
6
|
+
|
|
7
|
+
for (const element of quasis) {
|
|
8
|
+
write(element.node.value.raw);
|
|
9
|
+
|
|
10
|
+
const exp = expressions[i++];
|
|
11
|
+
|
|
12
|
+
if (exp) {
|
|
13
|
+
write('${');
|
|
14
|
+
traverse(exp);
|
|
15
|
+
write('}');
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
write('`');
|
|
20
|
+
};
|
|
@@ -39,6 +39,7 @@ const {TSInferType} = require('./ts-infer-type/ts-infer-type');
|
|
|
39
39
|
const {TSParameterProperty} = require('./ts-parameter-property/ts-parameter-property');
|
|
40
40
|
const {TSTypeQuery} = require('./ts-type-query/ts-type-query');
|
|
41
41
|
const {TSParenthesizedType} = require('./ts-parenthesized-type/ts-parenthesized-type');
|
|
42
|
+
const {TSTemplateLiteralType} = require('./ts-template-literal-type/ts-template-literal-type');
|
|
42
43
|
|
|
43
44
|
module.exports = {
|
|
44
45
|
TSAsExpression,
|
|
@@ -55,6 +56,7 @@ module.exports = {
|
|
|
55
56
|
TSImportType,
|
|
56
57
|
TSUnionType,
|
|
57
58
|
TSTypeQuery,
|
|
59
|
+
TSTemplateLiteralType,
|
|
58
60
|
TSBigIntKeyword(path, {write}) {
|
|
59
61
|
write('bigint');
|
|
60
62
|
},
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {writeTemplateLiteral} = require('../../literals/write-template-literal');
|
|
4
|
+
|
|
5
|
+
module.exports.TSTemplateLiteralType = (path, printer) => {
|
|
6
|
+
const quasis = path.get('quasis');
|
|
7
|
+
const types = path.get('types');
|
|
8
|
+
|
|
9
|
+
writeTemplateLiteral(quasis, types, printer);
|
|
10
|
+
};
|
package/package.json
CHANGED