@putout/printer 5.12.0 → 5.14.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/class/class.js +3 -2
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +3 -6
- package/lib/tokenize/typescript/function/ts-declare-function.js +7 -1
- package/lib/tokenize/typescript/function/ts-declare-method.js +12 -4
- package/lib/tokenize/typescript/index.js +1 -1
- package/lib/tokenize/typescript/interface/ts-interface-declaration.js +5 -3
- package/lib/tokenize/typescript/namespace/maybeDeclare.js +9 -0
- package/lib/tokenize/typescript/{ts-module-declaration.js → namespace/ts-module-declaration.js} +4 -6
- package/lib/tokenize/typescript/type/ts-type-alias-declaration.js +3 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.10.02, v5.14.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 0157a3c @putout/printer: ClassDeclaration: declare
|
|
5
|
+
- 09310b8 @putout/printer: typescript: maybeDeclare
|
|
6
|
+
|
|
7
|
+
2023.10.02, v5.13.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- e8d8b04 @putout/printer: typescript: type, interface: add support of declare
|
|
11
|
+
|
|
1
12
|
2023.09.26, v5.12.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -3,13 +3,14 @@
|
|
|
3
3
|
const {isNext} = require('../../is');
|
|
4
4
|
const {markAfter} = require('../../mark');
|
|
5
5
|
const {maybeDecorators} = require('../../maybe-get');
|
|
6
|
+
const {maybeDeclare} = require('../../typescript/namespace/maybeDeclare');
|
|
6
7
|
|
|
7
8
|
const isInsideExport = ({parentPath}) => parentPath.isExportDeclaration();
|
|
8
9
|
|
|
9
10
|
module.exports.ClassExpression = classVisitor;
|
|
10
11
|
|
|
11
12
|
module.exports.ClassDeclaration = {
|
|
12
|
-
print(path, {print, indent, maybe, traverse}) {
|
|
13
|
+
print: maybeDeclare((path, {print, indent, maybe, traverse}) => {
|
|
13
14
|
indent();
|
|
14
15
|
|
|
15
16
|
classVisitor(path, {
|
|
@@ -18,7 +19,7 @@ module.exports.ClassDeclaration = {
|
|
|
18
19
|
maybe,
|
|
19
20
|
traverse,
|
|
20
21
|
});
|
|
21
|
-
},
|
|
22
|
+
}),
|
|
22
23
|
afterIf(path) {
|
|
23
24
|
if (!isNext(path))
|
|
24
25
|
return false;
|
|
@@ -14,6 +14,7 @@ const {maybeSpaceAfterKeyword} = require('./maybe-space-after-keyword');
|
|
|
14
14
|
|
|
15
15
|
const {isConcatenation} = require('../../expressions/binary-expression/concatanate');
|
|
16
16
|
const {parseLeadingComments} = require('../../comment/comment');
|
|
17
|
+
const {maybeDeclare} = require('../../typescript/namespace/maybeDeclare');
|
|
17
18
|
|
|
18
19
|
const isParentTSModuleBlock = (path) => path.parentPath.isTSModuleBlock();
|
|
19
20
|
const isParentBlock = (path) => /Program|BlockStatement|Export/.test(path.parentPath.type);
|
|
@@ -26,15 +27,11 @@ module.exports.VariableDeclaration = {
|
|
|
26
27
|
before(path, {print}) {
|
|
27
28
|
print.breakline();
|
|
28
29
|
},
|
|
29
|
-
print(path, {maybe, store, write, traverse, print, indent}, semantics) {
|
|
30
|
-
const {declare} = path.node;
|
|
30
|
+
print: maybeDeclare((path, {maybe, store, write, traverse, print, indent}, semantics) => {
|
|
31
31
|
const {maxVariablesInOneLine} = semantics;
|
|
32
32
|
|
|
33
33
|
maybe.indent(isInsideBlock(path));
|
|
34
34
|
|
|
35
|
-
if (declare)
|
|
36
|
-
write('declare ');
|
|
37
|
-
|
|
38
35
|
write(path.node.kind);
|
|
39
36
|
maybeSpaceAfterKeyword(path, {
|
|
40
37
|
write,
|
|
@@ -94,7 +91,7 @@ module.exports.VariableDeclaration = {
|
|
|
94
91
|
}
|
|
95
92
|
|
|
96
93
|
store(wasNewline);
|
|
97
|
-
},
|
|
94
|
+
}),
|
|
98
95
|
afterSatisfy: () => [
|
|
99
96
|
noNextParentBlock,
|
|
100
97
|
notLastCoupleLines,
|
|
@@ -8,9 +8,14 @@ const isInsideExport = (path) => {
|
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
module.exports.TSDeclareFunction = (path, printer, semantics) => {
|
|
11
|
-
const {
|
|
11
|
+
const {
|
|
12
|
+
print,
|
|
13
|
+
maybe,
|
|
14
|
+
indent,
|
|
15
|
+
} = printer;
|
|
12
16
|
const {declare} = path.node;
|
|
13
17
|
|
|
18
|
+
indent();
|
|
14
19
|
maybe.print(declare, 'declare ');
|
|
15
20
|
print('function ');
|
|
16
21
|
print('__id');
|
|
@@ -26,3 +31,4 @@ module.exports.TSDeclareFunction = (path, printer, semantics) => {
|
|
|
26
31
|
maybe.print.newline(isNext(path) || isNext(path.parentPath));
|
|
27
32
|
}
|
|
28
33
|
};
|
|
34
|
+
|
|
@@ -4,7 +4,11 @@ const {printParams} = require('../../expressions/function/params');
|
|
|
4
4
|
|
|
5
5
|
module.exports.TSDeclareMethod = (path, printer, semantics) => {
|
|
6
6
|
const {print} = printer;
|
|
7
|
-
const {
|
|
7
|
+
const {
|
|
8
|
+
accessibility,
|
|
9
|
+
abstract,
|
|
10
|
+
returnType,
|
|
11
|
+
} = path.node;
|
|
8
12
|
|
|
9
13
|
if (accessibility) {
|
|
10
14
|
print(accessibility);
|
|
@@ -20,9 +24,13 @@ module.exports.TSDeclareMethod = (path, printer, semantics) => {
|
|
|
20
24
|
|
|
21
25
|
printParams(path, printer, semantics);
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
if (returnType) {
|
|
28
|
+
print(':');
|
|
29
|
+
print.space();
|
|
30
|
+
print('__returnType');
|
|
31
|
+
}
|
|
32
|
+
|
|
26
33
|
print(';');
|
|
27
34
|
print.newline();
|
|
28
35
|
};
|
|
36
|
+
|
|
@@ -12,7 +12,7 @@ const {TSDeclareMethod} = require('./function/ts-declare-method');
|
|
|
12
12
|
const {
|
|
13
13
|
TSModuleDeclaration,
|
|
14
14
|
TSModuleBlock,
|
|
15
|
-
} = require('./ts-module-declaration');
|
|
15
|
+
} = require('./namespace/ts-module-declaration');
|
|
16
16
|
|
|
17
17
|
const {TSInterfaceDeclaration} = require('./interface/ts-interface-declaration');
|
|
18
18
|
const {TSAsExpression} = require('./ts-as-expression');
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {isNext, isNextParent} = require('../../is');
|
|
4
3
|
const {
|
|
5
4
|
isTSTypeAliasDeclaration,
|
|
6
5
|
isExportDeclaration,
|
|
7
6
|
} = require('@putout/babel').types;
|
|
8
7
|
|
|
8
|
+
const {isNext, isNextParent} = require('../../is');
|
|
9
|
+
const {maybeDeclare} = require('../namespace/maybeDeclare');
|
|
10
|
+
|
|
9
11
|
module.exports.TSInterfaceDeclaration = {
|
|
10
|
-
print(path, {print}) {
|
|
12
|
+
print: maybeDeclare((path, {print}) => {
|
|
11
13
|
print('interface ');
|
|
12
14
|
print('__id');
|
|
13
15
|
print('__body');
|
|
14
|
-
},
|
|
16
|
+
}),
|
|
15
17
|
afterSatisfy: () => [isNext, isNextParent],
|
|
16
18
|
after(path, {print}) {
|
|
17
19
|
const next = path.parentPath.getNextSibling();
|
package/lib/tokenize/typescript/{ts-module-declaration.js → namespace/ts-module-declaration.js}
RENAMED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {isNext} = require('
|
|
3
|
+
const {isNext} = require('../../is');
|
|
4
|
+
const {maybeDeclare} = require('./maybeDeclare');
|
|
4
5
|
|
|
5
6
|
module.exports.TSModuleDeclaration = {
|
|
6
|
-
print(path, {print
|
|
7
|
-
const {declare} = path.node;
|
|
8
|
-
maybe.print(declare, 'declare ');
|
|
9
|
-
|
|
7
|
+
print: maybeDeclare((path, {print}) => {
|
|
10
8
|
print('namespace ');
|
|
11
9
|
print('__id');
|
|
12
10
|
print.space();
|
|
13
11
|
print('__body');
|
|
14
|
-
},
|
|
12
|
+
}),
|
|
15
13
|
afterSatisfy: () => [isNext],
|
|
16
14
|
after(path, {print}) {
|
|
17
15
|
print.newline();
|
|
@@ -2,10 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
const {isLast} = require('../../is');
|
|
4
4
|
const {markAfter} = require('../../mark');
|
|
5
|
+
const {maybeDeclare} = require('../namespace/maybeDeclare');
|
|
5
6
|
const isNextType = (a) => a.getNextSibling().isTSTypeAliasDeclaration();
|
|
6
7
|
|
|
7
8
|
module.exports.TSTypeAliasDeclaration = {
|
|
8
|
-
print(path, {print, maybe, store}) {
|
|
9
|
+
print: maybeDeclare((path, {print, maybe, store}) => {
|
|
9
10
|
const typeAnnotation = path.get('typeAnnotation');
|
|
10
11
|
const isConditional = typeAnnotation.isTSConditionalType();
|
|
11
12
|
|
|
@@ -22,7 +23,7 @@ module.exports.TSTypeAliasDeclaration = {
|
|
|
22
23
|
|
|
23
24
|
const is = store(isLast(path) || isLast(path.parentPath));
|
|
24
25
|
maybe.print.newline(!is);
|
|
25
|
-
},
|
|
26
|
+
}),
|
|
26
27
|
afterIf(path, {store}) {
|
|
27
28
|
const last = store();
|
|
28
29
|
|
package/package.json
CHANGED