@putout/printer 1.13.1 → 1.14.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 +13 -0
- package/README.md +0 -4
- package/lib/tokenize/comments.js +12 -3
- package/lib/tokenize/expressions/array-pattern.js +1 -2
- package/lib/tokenize/expressions/call-expression.js +1 -3
- package/lib/tokenize/expressions/class-declaration.js +1 -3
- package/lib/tokenize/expressions/functions.js +5 -0
- package/lib/tokenize/expressions/object-expression.js +0 -2
- package/lib/tokenize/expressions/sequence-expression.js +1 -3
- package/lib/tokenize/expressions/unary-expressions.js +1 -0
- package/lib/tokenize/literals/index.js +2 -1
- package/lib/tokenize/statements/switch-statement.js +1 -3
- package/lib/tokenize/typescript/index.js +10 -2
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
2023.03.30, v1.14.1
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- 1a117af @putout/printer: duplicate comment
|
|
5
|
+
|
|
6
|
+
feature:
|
|
7
|
+
- 260d680 @putout/printer: add support of getters
|
|
8
|
+
|
|
9
|
+
2023.03.30, v1.14.0
|
|
10
|
+
|
|
11
|
+
feature:
|
|
12
|
+
- 90687b1 @putout/printer: add support of TSTypeAnnotation
|
|
13
|
+
|
|
1
14
|
2023.03.29, v1.13.1
|
|
2
15
|
|
|
3
16
|
feature:
|
package/README.md
CHANGED
|
@@ -24,7 +24,6 @@ const ast = parse('const a = (b, c) => {const d = 5; return a;}');
|
|
|
24
24
|
|
|
25
25
|
print(ast);
|
|
26
26
|
|
|
27
|
-
// returns
|
|
28
27
|
// returns
|
|
29
28
|
`
|
|
30
29
|
const a = (b, c) => {
|
|
@@ -32,7 +31,6 @@ const a = (b, c) => {
|
|
|
32
31
|
return a;
|
|
33
32
|
};
|
|
34
33
|
`;
|
|
35
|
-
|
|
36
34
|
```
|
|
37
35
|
|
|
38
36
|
## Overrides
|
|
@@ -62,10 +60,8 @@ print(ast, {
|
|
|
62
60
|
},
|
|
63
61
|
});
|
|
64
62
|
|
|
65
|
-
// returns
|
|
66
63
|
// returns
|
|
67
64
|
'const {a /* [hello world] */= 5} = b;\n';
|
|
68
|
-
|
|
69
65
|
```
|
|
70
66
|
|
|
71
67
|
## License
|
package/lib/tokenize/comments.js
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
|
|
3
|
+
const {
|
|
4
|
+
isFirst,
|
|
5
|
+
isNext,
|
|
6
|
+
} = require('./is');
|
|
7
|
+
const {
|
|
8
|
+
markBefore,
|
|
9
|
+
hasPrevNewline,
|
|
10
|
+
} = require('./mark');
|
|
5
11
|
|
|
6
12
|
module.exports.parseLeadingComments = (path, {print, indent}) => {
|
|
7
13
|
const {leadingComments} = path.node;
|
|
@@ -41,6 +47,9 @@ module.exports.parseTrailingComments = (path, {print}) => {
|
|
|
41
47
|
if (!trailingComments || !trailingComments.length)
|
|
42
48
|
return;
|
|
43
49
|
|
|
50
|
+
if (isNext(path))
|
|
51
|
+
return;
|
|
52
|
+
|
|
44
53
|
for (const {type, value} of trailingComments) {
|
|
45
54
|
if (type === 'CommentLine') {
|
|
46
55
|
print.space();
|
|
@@ -52,5 +61,5 @@ module.exports.parseTrailingComments = (path, {print}) => {
|
|
|
52
61
|
};
|
|
53
62
|
|
|
54
63
|
function shouldAddNewlineBefore(path) {
|
|
55
|
-
return path.isStatement() && !isFirst(path);
|
|
64
|
+
return path.isStatement() && !isFirst(path) && !hasPrevNewline(path);
|
|
56
65
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {entries} = Object;
|
|
4
3
|
const isForOf = ({parentPath}) => parentPath.parentPath.parentPath.isForOfStatement();
|
|
5
4
|
|
|
6
5
|
module.exports.ArrayPattern = (path, {indent, maybe, print}) => {
|
|
@@ -15,7 +14,7 @@ module.exports.ArrayPattern = (path, {indent, maybe, print}) => {
|
|
|
15
14
|
|
|
16
15
|
maybe.print(isNewLine && elements.length, '\n');
|
|
17
16
|
|
|
18
|
-
for (const [index, element] of entries(
|
|
17
|
+
for (const [index, element] of elements.entries()) {
|
|
19
18
|
maybe.indent(isNewLine);
|
|
20
19
|
print(element);
|
|
21
20
|
maybe.print(isNewLine, ',\n');
|
|
@@ -5,8 +5,6 @@ const {
|
|
|
5
5
|
hasPrevNewline,
|
|
6
6
|
} = require('../mark');
|
|
7
7
|
|
|
8
|
-
const {entries} = Object;
|
|
9
|
-
|
|
10
8
|
const CallExpression = {
|
|
11
9
|
beforeIf(path) {
|
|
12
10
|
return isNewLineBefore(path) && !isMarkedParentBefore(path) && !hasPrevNewline(path.parentPath);
|
|
@@ -28,7 +26,7 @@ const CallExpression = {
|
|
|
28
26
|
|
|
29
27
|
maybe.indent.inc(isParentCall);
|
|
30
28
|
|
|
31
|
-
for (const [i, arg] of entries(
|
|
29
|
+
for (const [i, arg] of args.entries()) {
|
|
32
30
|
if (isParentCall) {
|
|
33
31
|
print.newline();
|
|
34
32
|
indent();
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {entries} = Object;
|
|
4
|
-
|
|
5
3
|
module.exports.ClassDeclaration = (path, {maybe, print, indent}) => {
|
|
6
4
|
indent();
|
|
7
5
|
print('class ');
|
|
@@ -21,7 +19,7 @@ module.exports.ClassDeclaration = (path, {maybe, print, indent}) => {
|
|
|
21
19
|
const body = path.get('body.body');
|
|
22
20
|
const n = body.length - 1;
|
|
23
21
|
|
|
24
|
-
for (const [i, item] of entries(
|
|
22
|
+
for (const [i, item] of body.entries()) {
|
|
25
23
|
indent();
|
|
26
24
|
print(item);
|
|
27
25
|
maybe.print(i < n, '\n');
|
|
@@ -51,6 +51,11 @@ function ArrowFunctionExpression(path, {print, maybe}) {
|
|
|
51
51
|
print('__body');
|
|
52
52
|
}
|
|
53
53
|
module.exports.ObjectMethod = (path, {print}) => {
|
|
54
|
+
const {kind} = path.node;
|
|
55
|
+
|
|
56
|
+
if (kind !== 'method')
|
|
57
|
+
print(`${kind} `);
|
|
58
|
+
|
|
54
59
|
print('__key');
|
|
55
60
|
print('(');
|
|
56
61
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {isCoupleLines} = require('../is');
|
|
4
|
-
|
|
5
4
|
const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
|
|
6
5
|
const isLogical = (path) => path.get('argument').isLogicalExpression();
|
|
7
6
|
|
|
@@ -90,4 +89,3 @@ function isOneLine(path) {
|
|
|
90
89
|
|
|
91
90
|
return isForOf(path);
|
|
92
91
|
}
|
|
93
|
-
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {entries} = Object;
|
|
4
|
-
|
|
5
3
|
module.exports.SequenceExpression = (path, {maybe, print}) => {
|
|
6
4
|
const expressions = path.get('expressions');
|
|
7
5
|
const n = expressions.length - 1;
|
|
8
6
|
|
|
9
|
-
for (const [index, expression] of entries(
|
|
7
|
+
for (const [index, expression] of expressions.entries()) {
|
|
10
8
|
print(expression);
|
|
11
9
|
maybe.print(index < n, ',');
|
|
12
10
|
maybe.print(index < n, ' ');
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {entries} = Object;
|
|
4
|
-
|
|
5
3
|
module.exports.SwitchStatement = (path, {print, maybe}) => {
|
|
6
4
|
print('switch');
|
|
7
5
|
print.space();
|
|
@@ -13,7 +11,7 @@ module.exports.SwitchStatement = (path, {print, maybe}) => {
|
|
|
13
11
|
const cases = path.get('cases');
|
|
14
12
|
const n = cases.length - 1;
|
|
15
13
|
|
|
16
|
-
for (const [index, switchCase] of entries(
|
|
14
|
+
for (const [index, switchCase] of cases.entries()) {
|
|
17
15
|
print('case');
|
|
18
16
|
print.space();
|
|
19
17
|
print(switchCase.get('test'));
|
|
@@ -14,8 +14,16 @@ module.exports = {
|
|
|
14
14
|
TSTypeReference(path, {print}) {
|
|
15
15
|
print('__typeName');
|
|
16
16
|
},
|
|
17
|
-
TSTypeParameter(path, {
|
|
18
|
-
|
|
17
|
+
TSTypeParameter(path, {write}) {
|
|
18
|
+
write(path.node.name);
|
|
19
|
+
},
|
|
20
|
+
TSNumberKeyword(path, {write}) {
|
|
21
|
+
write('number');
|
|
22
|
+
},
|
|
23
|
+
TSTypeAnnotation(path, {print}) {
|
|
24
|
+
print(':');
|
|
25
|
+
print.space();
|
|
26
|
+
print('__typeAnnotation');
|
|
19
27
|
},
|
|
20
28
|
TSExpressionWithTypeArguments(path, {print}) {
|
|
21
29
|
print('__expression');
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.14.1",
|
|
4
4
|
"type": "commonjs",
|
|
5
5
|
"author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
|
|
6
6
|
"description": "Easiest possible opinionated Babel AST printer made with ❤️ to use in 🐊Putout",
|