@putout/printer 15.28.0 → 16.1.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 +18 -0
- package/lib/tokenize/expressions/class/class.js +14 -2
- package/lib/tokenize/expressions/function/params.js +2 -0
- package/lib/tokenize/expressions/function/print-function-params.js +2 -0
- package/lib/tokenize/expressions/import-expression.js +2 -2
- package/lib/tokenize/statements/import-declaration/import-attribute.js +2 -11
- package/lib/tokenize/statements/import-declaration/import-declaration.js +3 -2
- package/lib/tokenize/typescript/index.js +2 -6
- package/lib/tokenize/typescript/interface/ts-interface-declaration.js +7 -2
- package/lib/tokenize/typescript/ts-import-type.js +2 -4
- package/lib/tokenize/typescript/ts-type-parameter-declaration/ts-type-parameter-declaration.js +50 -0
- package/package.json +7 -8
package/ChangeLog
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
2025.12.08, v16.1.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 1974703 @putout/printer: ClassDeclaration: implements: improve support
|
|
5
|
+
- f8a62fa @putout/printer: TSInterfaceDeclaration: improve support of extends
|
|
6
|
+
- 0a62781 @putout/printer: escover v5.0.0
|
|
7
|
+
- ca1d748 @putout/printer: putout v41.0.0
|
|
8
|
+
|
|
9
|
+
2025.11.28, v16.0.0
|
|
10
|
+
|
|
11
|
+
feature:
|
|
12
|
+
- 8464bc8 @putout/printer: TSImportType: argument -> source
|
|
13
|
+
- 79e538a @putout/printer: ImportDeclaration: drop support of assertions
|
|
14
|
+
- 4a62b80 @putout/printer: @putout/operate v15.0.0
|
|
15
|
+
- 1876784 @putout/printer: @putout/compare v19.0.1
|
|
16
|
+
- 0a777ac @putout/printer: eslint-plugin-putout v29.0.0
|
|
17
|
+
- b0874ca @putout/printer: @putout/babel v5.0.0
|
|
18
|
+
|
|
1
19
|
2025.11.27, v15.28.0
|
|
2
20
|
|
|
3
21
|
feature:
|
|
@@ -52,8 +52,20 @@ const classVisitor = maybeDecorators((path, printer, semantics) => {
|
|
|
52
52
|
}
|
|
53
53
|
|
|
54
54
|
if (node.implements) {
|
|
55
|
-
|
|
56
|
-
|
|
55
|
+
const {typeParameters} = node;
|
|
56
|
+
|
|
57
|
+
if (!typeParameters || typeParameters.params.length < 2)
|
|
58
|
+
print(' ');
|
|
59
|
+
|
|
60
|
+
print('implements ');
|
|
61
|
+
|
|
62
|
+
const implementsPaths = path.get('implements');
|
|
63
|
+
const n = implementsPaths.length - 1;
|
|
64
|
+
|
|
65
|
+
for (const [i, implement] of implementsPaths.entries()) {
|
|
66
|
+
print(implement);
|
|
67
|
+
maybe.print(i < n, ', ');
|
|
68
|
+
}
|
|
57
69
|
}
|
|
58
70
|
|
|
59
71
|
print.space();
|
|
@@ -20,6 +20,7 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
|
|
|
20
20
|
printSpace = print.space,
|
|
21
21
|
printAfterOpen = noop,
|
|
22
22
|
printBeforeClose = noop,
|
|
23
|
+
printAfterClose = noop,
|
|
23
24
|
} = customization;
|
|
24
25
|
|
|
25
26
|
if (typeParameters)
|
|
@@ -54,6 +55,7 @@ module.exports.printParams = (path, printer, semantics, customization = {}) => {
|
|
|
54
55
|
print,
|
|
55
56
|
braceClose,
|
|
56
57
|
}, semantics);
|
|
58
|
+
printAfterClose();
|
|
57
59
|
};
|
|
58
60
|
|
|
59
61
|
function printBraceOpen(path, {print, braceOpen}, semantics) {
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
module.exports.ImportExpression = createImportExpression;
|
|
4
4
|
module.exports.createImportExpression = createImportExpression;
|
|
5
5
|
|
|
6
|
-
function createImportExpression(path, printer
|
|
6
|
+
function createImportExpression(path, printer) {
|
|
7
7
|
const {print, maybe} = printer;
|
|
8
8
|
const {options} = path.node;
|
|
9
9
|
|
|
10
10
|
print('import(');
|
|
11
|
-
print(
|
|
11
|
+
print('__source');
|
|
12
12
|
|
|
13
13
|
maybe.print(options, ',');
|
|
14
14
|
maybe.print.space(options);
|
|
@@ -8,16 +8,7 @@ module.exports.ImportAttribute = (path, {print}) => {
|
|
|
8
8
|
print(',');
|
|
9
9
|
};
|
|
10
10
|
|
|
11
|
-
module.exports.
|
|
12
|
-
if (isAssertions(path))
|
|
13
|
-
return printAttributes(path, 'assert', printer);
|
|
14
|
-
|
|
15
|
-
printAttributes(path, 'with', printer);
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
const isAssertions = (path) => path.node.extra?.deprecatedAssertSyntax;
|
|
19
|
-
|
|
20
|
-
function printAttributes(path, keyword, {write, traverse, indent}) {
|
|
11
|
+
module.exports.printAttributes = (path, keyword, {write, traverse, indent}) => {
|
|
21
12
|
const attributes = path.get('attributes');
|
|
22
13
|
|
|
23
14
|
if (!attributes.length)
|
|
@@ -38,4 +29,4 @@ function printAttributes(path, keyword, {write, traverse, indent}) {
|
|
|
38
29
|
|
|
39
30
|
indent.dec();
|
|
40
31
|
write('}');
|
|
41
|
-
}
|
|
32
|
+
};
|
|
@@ -6,8 +6,8 @@ const {markAfter} = require('../../mark');
|
|
|
6
6
|
const {isLast, isNext} = require('../../is');
|
|
7
7
|
|
|
8
8
|
const {
|
|
9
|
-
maybePrintAttributes,
|
|
10
9
|
ImportAttribute,
|
|
10
|
+
printAttributes,
|
|
11
11
|
} = require('./import-attribute');
|
|
12
12
|
|
|
13
13
|
const {
|
|
@@ -102,7 +102,8 @@ module.exports.ImportDeclaration = {
|
|
|
102
102
|
print.space();
|
|
103
103
|
|
|
104
104
|
print('__source');
|
|
105
|
-
|
|
105
|
+
printAttributes(path, 'with', printer);
|
|
106
|
+
|
|
106
107
|
print(';');
|
|
107
108
|
|
|
108
109
|
if (isNext(path))
|
|
@@ -37,6 +37,7 @@ const {TSExportAssignment} = require('./ts-export-assignment/ts-export-assignmen
|
|
|
37
37
|
const {TSTypeReference} = require('./ts-type-reference/ts-type-reference');
|
|
38
38
|
const {TSInferType} = require('./ts-infer-type/ts-infer-type');
|
|
39
39
|
const {TSParameterProperty} = require('./ts-parameter-property/ts-parameter-property');
|
|
40
|
+
const {TSTypeParameterDeclaration} = require('./ts-type-parameter-declaration/ts-type-parameter-declaration');
|
|
40
41
|
const {TSTypeQuery} = require('./ts-type-query/ts-type-query');
|
|
41
42
|
const {TSParenthesizedType} = require('./ts-parenthesized-type/ts-parenthesized-type');
|
|
42
43
|
const {TSTemplateLiteralType} = require('./ts-template-literal-type/ts-template-literal-type');
|
|
@@ -59,6 +60,7 @@ module.exports = {
|
|
|
59
60
|
TSTypeQuery,
|
|
60
61
|
TSTemplateLiteralType,
|
|
61
62
|
TSOptionalType,
|
|
63
|
+
TSTypeParameterDeclaration,
|
|
62
64
|
TSBigIntKeyword(path, {write}) {
|
|
63
65
|
write('bigint');
|
|
64
66
|
},
|
|
@@ -86,12 +88,6 @@ module.exports = {
|
|
|
86
88
|
print('...');
|
|
87
89
|
print('__typeAnnotation');
|
|
88
90
|
},
|
|
89
|
-
TSTypeParameterDeclaration(path, printer, semantics) {
|
|
90
|
-
printParams(path, printer, semantics, {
|
|
91
|
-
braceOpen: '<',
|
|
92
|
-
braceClose: '>',
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
91
|
TSTypeParameterInstantiation(path, printer, semantics) {
|
|
96
92
|
printParams(path, printer, semantics, {
|
|
97
93
|
braceOpen: '<',
|
|
@@ -17,13 +17,19 @@ const isInsideNamespace = (path) => isTSModuleBlock(path.parentPath.parentPath);
|
|
|
17
17
|
module.exports.TSInterfaceDeclaration = {
|
|
18
18
|
print: maybeDeclare((path, {print, maybe}) => {
|
|
19
19
|
const {node} = path;
|
|
20
|
+
const {typeParameters} = node;
|
|
20
21
|
|
|
21
22
|
maybe.indent(!isExportNamedDeclaration(path.parentPath));
|
|
22
23
|
print('interface ');
|
|
23
24
|
print('__id');
|
|
24
25
|
|
|
26
|
+
print('__typeParameters');
|
|
27
|
+
|
|
25
28
|
if (node.extends) {
|
|
26
|
-
|
|
29
|
+
if (!typeParameters || typeParameters.length < 2)
|
|
30
|
+
print(' ');
|
|
31
|
+
|
|
32
|
+
print('extends ');
|
|
27
33
|
|
|
28
34
|
const extendsPaths = path.get('extends');
|
|
29
35
|
const n = extendsPaths.length - 1;
|
|
@@ -34,7 +40,6 @@ module.exports.TSInterfaceDeclaration = {
|
|
|
34
40
|
}
|
|
35
41
|
}
|
|
36
42
|
|
|
37
|
-
print('__typeParameters');
|
|
38
43
|
print('__body');
|
|
39
44
|
}),
|
|
40
45
|
afterSatisfy: () => [isNext, isNextParent],
|
|
@@ -2,8 +2,6 @@
|
|
|
2
2
|
|
|
3
3
|
const {createImportExpression} = require('../expressions/import-expression');
|
|
4
4
|
|
|
5
|
-
module.exports.TSImportType = (path, printer
|
|
6
|
-
createImportExpression(path, printer
|
|
7
|
-
source: 'argument',
|
|
8
|
-
});
|
|
5
|
+
module.exports.TSImportType = (path, printer) => {
|
|
6
|
+
createImportExpression(path, printer);
|
|
9
7
|
};
|
package/lib/tokenize/typescript/ts-type-parameter-declaration/ts-type-parameter-declaration.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {types} = require('@putout/babel');
|
|
4
|
+
const {createPrintSpace} = require('../../expressions/function/print-function-params');
|
|
5
|
+
const {printParams} = require('../../expressions/function/params');
|
|
6
|
+
const {isTSUnionType} = types;
|
|
7
|
+
const noop = () => {};
|
|
8
|
+
|
|
9
|
+
module.exports.TSTypeParameterDeclaration = (path, printer, semantics) => {
|
|
10
|
+
const {print, indent} = printer;
|
|
11
|
+
const isNewline = hasComplexParameters(path);
|
|
12
|
+
const printSpace = createPrintSpace({
|
|
13
|
+
isNewline,
|
|
14
|
+
printer,
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const printAfterOpen = !isNewline ? noop : () => {
|
|
18
|
+
indent.inc();
|
|
19
|
+
print.breakline();
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const printAfterClose = !isNewline ? noop : () => {
|
|
23
|
+
print.breakline();
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const printBeforeClose = !isNewline ? noop : () => {
|
|
27
|
+
indent.dec();
|
|
28
|
+
print.breakline();
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
printParams(path, printer, semantics, {
|
|
32
|
+
printSpace,
|
|
33
|
+
braceOpen: '<',
|
|
34
|
+
braceClose: '>',
|
|
35
|
+
printAfterOpen,
|
|
36
|
+
printBeforeClose,
|
|
37
|
+
printAfterClose,
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
function hasComplexParameters({node}) {
|
|
42
|
+
const {params} = node;
|
|
43
|
+
|
|
44
|
+
for (const {constraint} of params) {
|
|
45
|
+
if (isTSUnionType(constraint))
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return false;
|
|
50
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.1.0",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Simplest possible opinionated Babel AST printer for 🐊Putout",
|
|
@@ -33,9 +33,9 @@
|
|
|
33
33
|
"report": "madrun report"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@putout/babel": "^
|
|
37
|
-
"@putout/compare": "^
|
|
38
|
-
"@putout/operate": "^
|
|
36
|
+
"@putout/babel": "^5.0.0",
|
|
37
|
+
"@putout/compare": "^19.0.1",
|
|
38
|
+
"@putout/operate": "^15.0.0",
|
|
39
39
|
"@putout/operator-json": "^2.0.0",
|
|
40
40
|
"fullstore": "^3.0.0",
|
|
41
41
|
"just-snake-case": "^3.2.0",
|
|
@@ -79,17 +79,16 @@
|
|
|
79
79
|
"acorn": "^8.8.2",
|
|
80
80
|
"c8": "^10.1.2",
|
|
81
81
|
"check-dts": "^0.9.0",
|
|
82
|
-
"escover": "^
|
|
82
|
+
"escover": "^5.0.0",
|
|
83
83
|
"eslint": "^9.0.0",
|
|
84
|
-
"eslint-plugin-putout": "^
|
|
84
|
+
"eslint-plugin-putout": "^29.0.0",
|
|
85
85
|
"estree-to-babel": "^11.0.2",
|
|
86
86
|
"goldstein": "^6.0.1",
|
|
87
87
|
"just-kebab-case": "^4.2.0",
|
|
88
88
|
"madrun": "^11.0.0",
|
|
89
|
-
"mock-require": "^3.0.3",
|
|
90
89
|
"montag": "^1.0.0",
|
|
91
90
|
"nodemon": "^3.0.1",
|
|
92
|
-
"putout": "^
|
|
91
|
+
"putout": "^41.0.0",
|
|
93
92
|
"redlint": "^4.0.0",
|
|
94
93
|
"samadhi": "^3.0.3",
|
|
95
94
|
"supertape": "^11.1.0",
|