@putout/printer 2.96.0 → 3.0.1
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 +17 -0
- package/README.md +1 -1
- package/lib/tokenize/expressions/function/params.js +0 -5
- package/lib/tokenize/expressions/object-expression/object-expression.js +0 -11
- package/lib/tokenize/typescript/function/print-return-type.js +1 -13
- package/lib/tokenize/typescript/function/ts-function-type.js +6 -0
- package/lib/tokenize/typescript/index.js +0 -5
- package/lib/tokenize/typescript/type/ts-type-parameter.js +1 -7
- package/package.json +8 -8
package/ChangeLog
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
2023.08.05, v3.0.1
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 3528d83 2putout/printer: TSFunctionType: parens
|
|
5
|
+
|
|
6
|
+
2023.08.05, v3.0.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 90898aa @putout/printer: drop support of Babel < 8
|
|
10
|
+
- 95e659c package: @putout/plugin-minify v2.4.0
|
|
11
|
+
- 4025615 package: @putout/operate v10.0.2
|
|
12
|
+
- df5945b package: @putout/compare v12.0.4
|
|
13
|
+
- 6092ae6 package: nodemon v3.0.1
|
|
14
|
+
- b7428a5 package: estree-to-babel v6.0.0
|
|
15
|
+
- 2a6decd package: eslint-plugin-putout v19.0.2
|
|
16
|
+
- e17d03f package: putout v31.0.3
|
|
17
|
+
|
|
1
18
|
2023.08.03, v2.96.0
|
|
2
19
|
|
|
3
20
|
feature:
|
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
[NPMIMGURL]: https://img.shields.io/npm/v/@putout/printer.svg?style=flat&longCache=true
|
|
4
4
|
[NPMURL]: https://npmjs.org/package/@putout/printer "npm"
|
|
5
5
|
|
|
6
|
-
Prints [**Babel AST**](https://github.com/coderaiser/estree-to-babel) to readable **JavaScript**.
|
|
6
|
+
Prints [**Babel AST**](https://github.com/coderaiser/estree-to-babel) to readable **JavaScript**. For Babel 7 use `@putout/printer` v2.
|
|
7
7
|
|
|
8
8
|
- ☝️ Similar to **Recast**, but [twice faster](#speed-comparison), also simpler and easier in maintenance, since it supports only **Babel**.
|
|
9
9
|
- ☝️ As opinionated as **Prettier**, but has more user-friendly output and works directly with **AST**.
|
|
@@ -12,7 +12,6 @@ const {
|
|
|
12
12
|
} = require('../../is');
|
|
13
13
|
|
|
14
14
|
const {parseComments} = require('../../comment/comment');
|
|
15
|
-
const {isSpreadElement} = require('@babel/types');
|
|
16
15
|
|
|
17
16
|
const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
|
|
18
17
|
const isLogical = (path) => path.get('argument').isLogicalExpression();
|
|
@@ -94,13 +93,6 @@ const notLastArgInsideCall = (path) => {
|
|
|
94
93
|
const ONE_LINE = true;
|
|
95
94
|
const MANY_LINES = false;
|
|
96
95
|
|
|
97
|
-
const isSpreadFirst = (path) => {
|
|
98
|
-
const {properties} = path.node;
|
|
99
|
-
const {length} = properties;
|
|
100
|
-
|
|
101
|
-
return length > 1 && isSpreadElement(properties[0]);
|
|
102
|
-
};
|
|
103
|
-
|
|
104
96
|
module.exports.isOneLine = isOneLine;
|
|
105
97
|
function isOneLine(path) {
|
|
106
98
|
const {length} = path.get('properties');
|
|
@@ -120,9 +112,6 @@ function isOneLine(path) {
|
|
|
120
112
|
if (isCoupleLines(path))
|
|
121
113
|
return MANY_LINES;
|
|
122
114
|
|
|
123
|
-
if (isSpreadFirst(path))
|
|
124
|
-
return MANY_LINES;
|
|
125
|
-
|
|
126
115
|
return !isValue(path);
|
|
127
116
|
}
|
|
128
117
|
|
|
@@ -1,19 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
module.exports.hasReturnType = (path) => {
|
|
6
|
-
if (isBabel7(path))
|
|
7
|
-
return path.node.typeAnnotation;
|
|
8
|
-
|
|
9
|
-
return path.node.returnType;
|
|
10
|
-
};
|
|
3
|
+
module.exports.hasReturnType = (path) => path.node.returnType;
|
|
11
4
|
|
|
12
5
|
module.exports.printReturnType = (path, {traverse}) => {
|
|
13
|
-
if (isBabel7(path)) {
|
|
14
|
-
traverse(path.get('typeAnnotation'));
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
6
|
traverse(path.get('returnType'));
|
|
19
7
|
};
|
|
@@ -2,13 +2,19 @@
|
|
|
2
2
|
|
|
3
3
|
const {printParams} = require('../../expressions/function/params');
|
|
4
4
|
const {printReturnType} = require('./print-return-type');
|
|
5
|
+
const {
|
|
6
|
+
maybeParenOpen,
|
|
7
|
+
maybeParenClose,
|
|
8
|
+
} = require('../../expressions/unary-expression/parens');
|
|
5
9
|
|
|
6
10
|
module.exports.TSFunctionType = (path, printer, semantics) => {
|
|
7
11
|
const {print} = printer;
|
|
8
12
|
|
|
13
|
+
maybeParenOpen(path, printer);
|
|
9
14
|
printParams(path, printer, semantics);
|
|
10
15
|
print.space();
|
|
11
16
|
print('=>');
|
|
12
17
|
print.space();
|
|
13
18
|
printReturnType(path, printer);
|
|
19
|
+
maybeParenClose(path, printer);
|
|
14
20
|
};
|
|
@@ -113,11 +113,6 @@ module.exports = {
|
|
|
113
113
|
print('>');
|
|
114
114
|
print('__expression');
|
|
115
115
|
},
|
|
116
|
-
TSParenthesizedType(path, {print}) {
|
|
117
|
-
print('(');
|
|
118
|
-
print('__typeAnnotation');
|
|
119
|
-
print(')');
|
|
120
|
-
},
|
|
121
116
|
TSUndefinedKeyword(path, {write}) {
|
|
122
117
|
write('undefined');
|
|
123
118
|
},
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const isString = (a) => typeof a === 'string';
|
|
4
3
|
const {exists} = require('../../is');
|
|
5
4
|
|
|
6
|
-
const isBabel7 = (path) => isString(path.node.name);
|
|
7
|
-
|
|
8
5
|
module.exports.TSTypeParameter = (path, {write, traverse}) => {
|
|
9
6
|
const constraint = path.get('constraint');
|
|
10
7
|
|
|
@@ -15,10 +12,7 @@ module.exports.TSTypeParameter = (path, {write, traverse}) => {
|
|
|
15
12
|
else if (path.node.const)
|
|
16
13
|
write('const ');
|
|
17
14
|
|
|
18
|
-
|
|
19
|
-
write(path.node.name);
|
|
20
|
-
else
|
|
21
|
-
write(path.node.name.name);
|
|
15
|
+
write(path.node.name.name);
|
|
22
16
|
|
|
23
17
|
if (!exists(constraint))
|
|
24
18
|
return;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.1",
|
|
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",
|
|
@@ -30,8 +30,8 @@
|
|
|
30
30
|
"@babel/parser": "^7.19.0",
|
|
31
31
|
"@babel/traverse": "^7.21.2",
|
|
32
32
|
"@babel/types": "^7.21.3",
|
|
33
|
-
"@putout/compare": "^
|
|
34
|
-
"@putout/operate": "^
|
|
33
|
+
"@putout/compare": "^12.0.4",
|
|
34
|
+
"@putout/operate": "^10.0.2",
|
|
35
35
|
"fullstore": "^3.0.0",
|
|
36
36
|
"just-snake-case": "^3.2.0",
|
|
37
37
|
"parse-import-specifiers": "^1.0.1",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
],
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"@babel/plugin-codemod-object-assign-to-object-spread": "^7.10.4",
|
|
51
|
-
"@putout/plugin-minify": "^
|
|
51
|
+
"@putout/plugin-minify": "^2.4.0",
|
|
52
52
|
"@putout/plugin-printer": "^1.0.0",
|
|
53
53
|
"@putout/plugin-promises": "^11.0.0",
|
|
54
54
|
"@putout/plugin-react-hook-form": "^3.4.1",
|
|
@@ -58,14 +58,14 @@
|
|
|
58
58
|
"escover": "^3.0.0",
|
|
59
59
|
"eslint": "^8.0.1",
|
|
60
60
|
"eslint-plugin-n": "^16.0.0",
|
|
61
|
-
"eslint-plugin-putout": "^
|
|
62
|
-
"estree-to-babel": "^
|
|
61
|
+
"eslint-plugin-putout": "^19.0.2",
|
|
62
|
+
"estree-to-babel": "^6.0.0",
|
|
63
63
|
"just-kebab-case": "^4.2.0",
|
|
64
64
|
"madrun": "^9.0.0",
|
|
65
65
|
"mock-require": "^3.0.3",
|
|
66
66
|
"montag": "^1.0.0",
|
|
67
|
-
"nodemon": "^
|
|
68
|
-
"putout": "^
|
|
67
|
+
"nodemon": "^3.0.1",
|
|
68
|
+
"putout": "^31.0.3",
|
|
69
69
|
"supertape": "^8.0.0",
|
|
70
70
|
"try-catch": "^3.0.0"
|
|
71
71
|
},
|