@putout/printer 1.54.1 → 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 +5 -0
- 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 +0 -1
- package/lib/tokenize/statements/variable-declaration.js +2 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -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
|
|
|
@@ -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
|
};
|
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",
|