@putout/printer 1.54.1 → 1.54.3
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 +10 -0
- package/lib/tokenize/expressions/array-expression.js +15 -0
- package/lib/tokenize/expressions/functions/arrow-function-expression.js +46 -0
- package/lib/tokenize/expressions/functions/function-declaration.js +36 -0
- package/lib/tokenize/expressions/{functions.js → functions/functions.js} +5 -60
- package/lib/tokenize/expressions/index.js +1 -1
- package/lib/tokenize/expressions/member-expressions.js +0 -1
- package/lib/tokenize/is.js +1 -4
- package/lib/tokenize/statements/export-default-declaration.js +11 -4
- package/lib/tokenize/statements/variable-declaration.js +2 -1
- package/lib/tokenize/typescript/ts-type-alias-declaration.js +2 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2023.04.18, v1.54.3
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- b5acf3e @putout/printer: improve support of newlines between elements of ArrayExpression
|
|
5
|
+
|
|
6
|
+
2023.04.18, v1.54.2
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- a9c17af @putout/printer: improve support of ArrowFunctionExpression used inside LogicalExpression
|
|
10
|
+
|
|
1
11
|
2023.04.18, v1.54.1
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -174,7 +174,22 @@ function tooLong(path) {
|
|
|
174
174
|
return false;
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
+
function isCallInsideArrow(path) {
|
|
178
|
+
const {parentPath} = path;
|
|
179
|
+
|
|
180
|
+
if (!parentPath.isCallExpression())
|
|
181
|
+
return false;
|
|
182
|
+
|
|
183
|
+
if (!parentPath.parentPath.isFunction())
|
|
184
|
+
return false;
|
|
185
|
+
|
|
186
|
+
return path.node.elements.length < 4;
|
|
187
|
+
}
|
|
188
|
+
|
|
177
189
|
function isNewlineBetweenElements(path, {elements}) {
|
|
190
|
+
if (isCallInsideArrow(path))
|
|
191
|
+
return false;
|
|
192
|
+
|
|
178
193
|
if (isTwoElementReturn(path, {elements}))
|
|
179
194
|
return false;
|
|
180
195
|
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {exists} = require('../../is');
|
|
4
|
+
|
|
5
|
+
module.exports.ArrowFunctionExpression = {
|
|
6
|
+
condition({parentPath}) {
|
|
7
|
+
return parentPath.isLogicalExpression();
|
|
8
|
+
},
|
|
9
|
+
before(path, {write}) {
|
|
10
|
+
write('(');
|
|
11
|
+
},
|
|
12
|
+
print(path, {print, maybe, write, traverse}) {
|
|
13
|
+
const {async} = path.node;
|
|
14
|
+
|
|
15
|
+
maybe.print(async, 'async ');
|
|
16
|
+
print('(');
|
|
17
|
+
|
|
18
|
+
const params = path.get('params');
|
|
19
|
+
const n = params.length;
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < n; i++) {
|
|
22
|
+
print(params[i]);
|
|
23
|
+
|
|
24
|
+
if (i < n - 1)
|
|
25
|
+
print(', ');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
print(')');
|
|
29
|
+
|
|
30
|
+
const returnType = path.get('returnType');
|
|
31
|
+
|
|
32
|
+
if (exists(returnType)) {
|
|
33
|
+
write(':');
|
|
34
|
+
write.space();
|
|
35
|
+
traverse(returnType);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
print.space();
|
|
39
|
+
print('=>');
|
|
40
|
+
print.space();
|
|
41
|
+
print('__body');
|
|
42
|
+
},
|
|
43
|
+
after(path, {write}) {
|
|
44
|
+
write(')');
|
|
45
|
+
},
|
|
46
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const {hasPrevNewline} = require('../../mark');
|
|
4
|
+
const isFirst = (path) => !path.getPrevSibling().node;
|
|
5
|
+
|
|
6
|
+
module.exports.FunctionDeclaration = {
|
|
7
|
+
beforeIf(path) {
|
|
8
|
+
return !isFirst(path) && !hasPrevNewline(path) && !path.parentPath.isExportDeclaration();
|
|
9
|
+
},
|
|
10
|
+
before(path, {write}) {
|
|
11
|
+
write('\n');
|
|
12
|
+
},
|
|
13
|
+
print(path, {print, maybe}) {
|
|
14
|
+
const {async} = path.node;
|
|
15
|
+
|
|
16
|
+
maybe.print(async, 'async ');
|
|
17
|
+
|
|
18
|
+
print('function ');
|
|
19
|
+
print('__id');
|
|
20
|
+
print('(');
|
|
21
|
+
|
|
22
|
+
const params = path.get('params');
|
|
23
|
+
const n = params.length - 1;
|
|
24
|
+
|
|
25
|
+
for (let i = 0; i <= n; i++) {
|
|
26
|
+
print(params[i]);
|
|
27
|
+
|
|
28
|
+
if (i < n)
|
|
29
|
+
print(', ');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
print(') ');
|
|
33
|
+
print('__body');
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {
|
|
4
|
-
const {
|
|
5
|
-
|
|
3
|
+
const {ArrowFunctionExpression} = require('./arrow-function-expression');
|
|
4
|
+
const {FunctionDeclaration} = require('./function-declaration');
|
|
5
|
+
|
|
6
|
+
module.exports.ArrowFunctionExpression = ArrowFunctionExpression;
|
|
7
|
+
module.exports.FunctionDeclaration = FunctionDeclaration;
|
|
6
8
|
|
|
7
9
|
module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
|
|
8
10
|
const {node} = path;
|
|
@@ -39,38 +41,6 @@ module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
|
|
|
39
41
|
print('__body');
|
|
40
42
|
};
|
|
41
43
|
|
|
42
|
-
module.exports.ArrowFunctionExpression = ArrowFunctionExpression;
|
|
43
|
-
|
|
44
|
-
function ArrowFunctionExpression(path, {print, maybe, write, traverse}) {
|
|
45
|
-
const {async} = path.node;
|
|
46
|
-
maybe.print(async, 'async ');
|
|
47
|
-
print('(');
|
|
48
|
-
|
|
49
|
-
const params = path.get('params');
|
|
50
|
-
const n = params.length;
|
|
51
|
-
|
|
52
|
-
for (let i = 0; i < n; i++) {
|
|
53
|
-
print(params[i]);
|
|
54
|
-
|
|
55
|
-
if (i < n - 1)
|
|
56
|
-
print(', ');
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
print(')');
|
|
60
|
-
|
|
61
|
-
const returnType = path.get('returnType');
|
|
62
|
-
|
|
63
|
-
if (exists(returnType)) {
|
|
64
|
-
write(':');
|
|
65
|
-
write.space();
|
|
66
|
-
traverse(returnType);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
print.space();
|
|
70
|
-
print('=>');
|
|
71
|
-
print.space();
|
|
72
|
-
print('__body');
|
|
73
|
-
}
|
|
74
44
|
module.exports.ObjectMethod = (path, {print}) => {
|
|
75
45
|
const {kind} = path.node;
|
|
76
46
|
|
|
@@ -94,31 +64,6 @@ module.exports.ObjectMethod = (path, {print}) => {
|
|
|
94
64
|
print('__body');
|
|
95
65
|
};
|
|
96
66
|
|
|
97
|
-
module.exports.FunctionDeclaration = (path, {print, maybe}) => {
|
|
98
|
-
const {async} = path.node;
|
|
99
|
-
|
|
100
|
-
if (!isFirst(path) && !hasPrevNewline(path) && !path.parentPath.isExportDeclaration())
|
|
101
|
-
print('\n');
|
|
102
|
-
|
|
103
|
-
maybe.print(async, 'async ');
|
|
104
|
-
print('function ');
|
|
105
|
-
print('__id');
|
|
106
|
-
print('(');
|
|
107
|
-
|
|
108
|
-
const params = path.get('params');
|
|
109
|
-
const n = params.length - 1;
|
|
110
|
-
|
|
111
|
-
for (let i = 0; i <= n; i++) {
|
|
112
|
-
print(params[i]);
|
|
113
|
-
|
|
114
|
-
if (i < n)
|
|
115
|
-
print(', ');
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
print(') ');
|
|
119
|
-
print('__body');
|
|
120
|
-
};
|
|
121
|
-
|
|
122
67
|
module.exports.ClassMethod = (path, {print, maybe}) => {
|
|
123
68
|
const {kind} = path.node;
|
|
124
69
|
const notMethod = kind !== 'method';
|
package/lib/tokenize/is.js
CHANGED
|
@@ -1,14 +1,21 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
const {isNewlineBetweenStatements} = require('../is');
|
|
4
|
+
const {isMarkedAfter} = require('../mark');
|
|
5
|
+
|
|
3
6
|
module.exports.ExportDefaultDeclaration = {
|
|
4
|
-
/*
|
|
5
7
|
beforeIf(path) {
|
|
6
|
-
|
|
8
|
+
const prev = path.getPrevSibling();
|
|
9
|
+
|
|
10
|
+
if (isMarkedAfter(prev))
|
|
11
|
+
return false;
|
|
12
|
+
|
|
13
|
+
return isNewlineBetweenStatements(prev);
|
|
7
14
|
},
|
|
8
15
|
before(path, {print}) {
|
|
9
|
-
print.
|
|
16
|
+
print.newline();
|
|
10
17
|
},
|
|
11
|
-
|
|
18
|
+
print(path, {print, traverse, maybe}) {
|
|
12
19
|
const declaration = path.get('declaration');
|
|
13
20
|
print('export default ');
|
|
14
21
|
traverse(declaration);
|
|
@@ -126,5 +126,6 @@ const isNextAssign = (path) => {
|
|
|
126
126
|
if (parentPath.isBlockStatement() && parentPath.node.body.length < 3)
|
|
127
127
|
return false;
|
|
128
128
|
|
|
129
|
-
return nextPath
|
|
129
|
+
return nextPath
|
|
130
|
+
.get('expression').isAssignmentExpression();
|
|
130
131
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {isLast} = require('../is');
|
|
4
|
+
const {markAfter} = require('../mark');
|
|
4
5
|
const isNextType = (a) => a.getNextSibling().isTSTypeAliasDeclaration();
|
|
5
6
|
|
|
6
7
|
module.exports.TSTypeAliasDeclaration = {
|
|
@@ -31,5 +32,6 @@ module.exports.TSTypeAliasDeclaration = {
|
|
|
31
32
|
},
|
|
32
33
|
after(path, {print}) {
|
|
33
34
|
print.newline();
|
|
35
|
+
markAfter(path);
|
|
34
36
|
},
|
|
35
37
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.54.
|
|
3
|
+
"version": "1.54.3",
|
|
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",
|