@putout/printer 11.3.0 → 11.5.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/logical-expression/logical-expression.js +4 -10
- package/lib/tokenize/maybe/maybe-parens.js +14 -1
- package/lib/tokenize/statements/export-declaration/export-declaration.js +2 -2
- package/lib/tokenize/typescript/enum/ts-enum-declaration.js +15 -2
- package/lib/tokenize/typescript/interface/ts-interface-declaration.js +14 -8
- package/package.json +2 -2
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2024.12.15, v11.5.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 2224570 @putout/printer: improve support of TSInterfaceDeclaration
|
|
5
|
+
- d15b999 @putout/printer: putout v37.0.1
|
|
6
|
+
|
|
7
|
+
2024.12.13, v11.4.0
|
|
8
|
+
|
|
9
|
+
feature:
|
|
10
|
+
- 332efd1 @putout/printer: LogicalExpression inside UnaryExpression: parens
|
|
11
|
+
|
|
1
12
|
2024.12.12, v11.3.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {maybeParens} = require('../../maybe/maybe-parens');
|
|
4
4
|
const {chain, isRootOk} = require('./chain');
|
|
5
5
|
|
|
6
|
-
module.exports.LogicalExpression = {
|
|
6
|
+
module.exports.LogicalExpression = maybeParens({
|
|
7
7
|
condition(path) {
|
|
8
|
-
if (
|
|
8
|
+
if (path.parentPath.isUnaryExpression())
|
|
9
9
|
return true;
|
|
10
10
|
|
|
11
11
|
return path.parentPath.isAwaitExpression();
|
|
12
12
|
},
|
|
13
|
-
before(path, {print}) {
|
|
14
|
-
print('(');
|
|
15
|
-
},
|
|
16
13
|
print(path, {print, maybe}, semantics) {
|
|
17
14
|
print('__left');
|
|
18
15
|
|
|
@@ -26,10 +23,7 @@ module.exports.LogicalExpression = {
|
|
|
26
23
|
print.space();
|
|
27
24
|
print('__right');
|
|
28
25
|
},
|
|
29
|
-
|
|
30
|
-
print(')');
|
|
31
|
-
},
|
|
32
|
-
};
|
|
26
|
+
});
|
|
33
27
|
|
|
34
28
|
function isNewLine(path, semantics) {
|
|
35
29
|
const [root, count] = chain(path);
|
|
@@ -1,9 +1,17 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const isFn = (a) => typeof a === 'function';
|
|
3
4
|
const isParens = (path) => path.node.extra?.parenthesized;
|
|
4
5
|
|
|
5
6
|
module.exports.isParens = isParens;
|
|
6
|
-
module.exports.maybeParens = (print) =>
|
|
7
|
+
module.exports.maybeParens = (print) => {
|
|
8
|
+
if (isFn(print))
|
|
9
|
+
return maybeParensPrint(print);
|
|
10
|
+
|
|
11
|
+
return maybeParensCondition(print);
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const maybeParensPrint = (print) => ({
|
|
7
15
|
condition: isParens,
|
|
8
16
|
before(path, {write}) {
|
|
9
17
|
write('(');
|
|
@@ -13,3 +21,8 @@ module.exports.maybeParens = (print) => ({
|
|
|
13
21
|
write(')');
|
|
14
22
|
},
|
|
15
23
|
});
|
|
24
|
+
|
|
25
|
+
const maybeParensCondition = ({print, condition}) => ({
|
|
26
|
+
...maybeParensPrint(print),
|
|
27
|
+
condition: (path) => condition(path) || isParens(path),
|
|
28
|
+
});
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {isExportNamespaceSpecifier} = require('@putout/babel').types;
|
|
4
|
+
const {markAfter, isMarkedAfter} = require('../../mark');
|
|
3
5
|
const {
|
|
4
6
|
isNewlineBetweenSiblings,
|
|
5
7
|
exists,
|
|
@@ -7,8 +9,6 @@ const {
|
|
|
7
9
|
isLast,
|
|
8
10
|
} = require('../../is');
|
|
9
11
|
|
|
10
|
-
const {markAfter, isMarkedAfter} = require('../../mark');
|
|
11
|
-
const {isExportNamespaceSpecifier} = require('@putout/babel').types;
|
|
12
12
|
const isDeclarationNewline = (path) => isMarkedAfter(path.get('declaration'));
|
|
13
13
|
const isInsideNamespace = (path) => path.parentPath.isTSModuleBlock();
|
|
14
14
|
|
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
3
|
+
const {
|
|
4
|
+
isNext,
|
|
5
|
+
isNextParent,
|
|
6
|
+
isLast,
|
|
7
|
+
} = require('../../is');
|
|
8
|
+
|
|
9
|
+
const {markAfter} = require('../../mark');
|
|
4
10
|
|
|
5
11
|
module.exports.TSEnumDeclaration = {
|
|
6
12
|
beforeIf(path) {
|
|
@@ -25,10 +31,17 @@ module.exports.TSEnumDeclaration = {
|
|
|
25
31
|
}
|
|
26
32
|
|
|
27
33
|
indent.dec();
|
|
34
|
+
indent();
|
|
28
35
|
print('}');
|
|
36
|
+
|
|
37
|
+
if (isLast(path))
|
|
38
|
+
return;
|
|
39
|
+
|
|
40
|
+
print.newline();
|
|
41
|
+
markAfter(path);
|
|
29
42
|
},
|
|
30
43
|
afterSatisfy: () => [isNext, isNextParent],
|
|
31
44
|
after(path, {print}) {
|
|
32
|
-
print.
|
|
45
|
+
print.linebreak();
|
|
33
46
|
},
|
|
34
47
|
};
|
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {types} = require('@putout/babel');
|
|
3
4
|
const {
|
|
4
5
|
isTSTypeAliasDeclaration,
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
isExportNamedDeclaration,
|
|
7
|
+
isTSModuleBlock,
|
|
8
|
+
} = types;
|
|
7
9
|
|
|
8
10
|
const {isNext, isNextParent} = require('../../is');
|
|
9
11
|
const {maybeDeclare} = require('../../maybe/maybe-declare');
|
|
12
|
+
const {markAfter} = require('../../mark');
|
|
13
|
+
const isInsideNamespace = (path) => isTSModuleBlock(path.parentPath.parentPath);
|
|
10
14
|
|
|
11
15
|
module.exports.TSInterfaceDeclaration = {
|
|
12
16
|
print: maybeDeclare((path, {print, maybe}) => {
|
|
13
|
-
const {node
|
|
17
|
+
const {node} = path;
|
|
14
18
|
|
|
15
|
-
maybe.indent(!
|
|
19
|
+
maybe.indent(!isExportNamedDeclaration(path.parentPath));
|
|
16
20
|
print('interface ');
|
|
17
21
|
print('__id');
|
|
18
22
|
|
|
@@ -28,11 +32,13 @@ module.exports.TSInterfaceDeclaration = {
|
|
|
28
32
|
}),
|
|
29
33
|
afterSatisfy: () => [isNext, isNextParent],
|
|
30
34
|
after(path, {print}) {
|
|
31
|
-
print.
|
|
35
|
+
print.linebreak();
|
|
36
|
+
const exportNamed = isExportNamedDeclaration(path.parentPath);
|
|
32
37
|
|
|
33
|
-
|
|
38
|
+
if (exportNamed && isInsideNamespace(path))
|
|
39
|
+
markAfter(path);
|
|
34
40
|
|
|
35
|
-
if (!
|
|
36
|
-
print.
|
|
41
|
+
if (!exportNamed && !isTSTypeAliasDeclaration(path))
|
|
42
|
+
print.newline();
|
|
37
43
|
},
|
|
38
44
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.5.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",
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
"mock-require": "^3.0.3",
|
|
71
71
|
"montag": "^1.0.0",
|
|
72
72
|
"nodemon": "^3.0.1",
|
|
73
|
-
"putout": "^
|
|
73
|
+
"putout": "^37.0.1",
|
|
74
74
|
"redlint": "^3.16.0",
|
|
75
75
|
"samadhi": "^2.8.0",
|
|
76
76
|
"supertape": "^10.0.0",
|