@putout/printer 1.54.0 → 1.54.2
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/assignment-expression.js +0 -1
- package/lib/tokenize/expressions/functions/arrow-function-expression.js +46 -0
- package/lib/tokenize/expressions/{functions.js → functions/functions.js} +4 -34
- package/lib/tokenize/expressions/index.js +1 -1
- package/lib/tokenize/expressions/member-expressions.js +7 -2
- package/lib/tokenize/is.js +1 -2
- package/lib/tokenize/statements/expression-statement.js +2 -2
- package/lib/tokenize/statements/variable-declaration.js +5 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.04.18, v1.54.2
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- a9c17af @putout/printer: improve support of ArrowFunctionExpression used inside LogicalExpression
|
|
5
|
+
|
|
6
|
+
2023.04.18, v1.54.1
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 7f6d7d4 @putout/printer: add support of Import used as object of MemberExpression
|
|
10
|
+
- c2b2e4b @putout/printer: VariableDeclaration: drop useless newline
|
|
11
|
+
|
|
1
12
|
2023.04.18, v1.54.0
|
|
2
13
|
|
|
3
14
|
feature:
|
|
@@ -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
|
+
};
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {hasPrevNewline} = require('
|
|
4
|
-
const {exists} = require('../is');
|
|
3
|
+
const {hasPrevNewline} = require('../../mark');
|
|
5
4
|
const isFirst = (path) => !path.getPrevSibling().node;
|
|
5
|
+
const {ArrowFunctionExpression} = require('./arrow-function-expression');
|
|
6
|
+
|
|
7
|
+
module.exports.ArrowFunctionExpression = ArrowFunctionExpression;
|
|
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
|
|
|
@@ -12,9 +12,14 @@ const {
|
|
|
12
12
|
getTemplateValues,
|
|
13
13
|
} = require('@putout/compare');
|
|
14
14
|
|
|
15
|
-
module.exports.MemberExpression = (path, {print, indent, maybe}) => {
|
|
15
|
+
module.exports.MemberExpression = (path, {print, indent, maybe, traverse}) => {
|
|
16
16
|
const {computed} = path.node;
|
|
17
|
-
|
|
17
|
+
const object = path.get('object');
|
|
18
|
+
const isObjectAwait = object.isAwaitExpression();
|
|
19
|
+
|
|
20
|
+
maybe.print(isObjectAwait, '(');
|
|
21
|
+
traverse(object);
|
|
22
|
+
maybe.print(isObjectAwait, ')');
|
|
18
23
|
|
|
19
24
|
if (computed) {
|
|
20
25
|
print('[');
|
package/lib/tokenize/is.js
CHANGED
|
@@ -78,10 +78,9 @@ module.exports.isNewlineBetweenStatements = (path) => {
|
|
|
78
78
|
};
|
|
79
79
|
|
|
80
80
|
module.exports.satisfy = (conditions) => (path) => {
|
|
81
|
-
for (const condition of conditions)
|
|
81
|
+
for (const condition of conditions)
|
|
82
82
|
if (condition(path))
|
|
83
83
|
return true;
|
|
84
|
-
}
|
|
85
84
|
|
|
86
85
|
return false;
|
|
87
86
|
};
|
|
@@ -28,7 +28,7 @@ module.exports.ExpressionStatement = {
|
|
|
28
28
|
}
|
|
29
29
|
},
|
|
30
30
|
afterSatisfy: () => [
|
|
31
|
-
|
|
31
|
+
isParentBlockOrNotLastOrParentLast,
|
|
32
32
|
isParentBlock,
|
|
33
33
|
isNext,
|
|
34
34
|
isNextUp,
|
|
@@ -49,7 +49,7 @@ function isNotLastBody(path) {
|
|
|
49
49
|
return path.parentPath.get('body') === path;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
function
|
|
52
|
+
function isParentBlockOrNotLastOrParentLast(path) {
|
|
53
53
|
return isParentBlock(path) || !(isLast(path) || isParentLast(path));
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -121,6 +121,11 @@ const isNextAssign = (path) => {
|
|
|
121
121
|
if (!nextPath.isExpressionStatement())
|
|
122
122
|
return false;
|
|
123
123
|
|
|
124
|
+
const {parentPath} = path;
|
|
125
|
+
|
|
126
|
+
if (parentPath.isBlockStatement() && parentPath.node.body.length < 3)
|
|
127
|
+
return false;
|
|
128
|
+
|
|
124
129
|
return nextPath
|
|
125
130
|
.get('expression').isAssignmentExpression();
|
|
126
131
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.54.
|
|
3
|
+
"version": "1.54.2",
|
|
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",
|