@putout/printer 1.54.2 → 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 +5 -0
- package/lib/tokenize/expressions/array-expression.js +15 -0
- package/lib/tokenize/expressions/functions/function-declaration.js +36 -0
- package/lib/tokenize/expressions/functions/functions.js +2 -27
- package/lib/tokenize/is.js +1 -4
- package/lib/tokenize/statements/export-default-declaration.js +11 -4
- package/lib/tokenize/typescript/ts-type-alias-declaration.js +2 -0
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -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,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,10 +1,10 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {hasPrevNewline} = require('../../mark');
|
|
4
|
-
const isFirst = (path) => !path.getPrevSibling().node;
|
|
5
3
|
const {ArrowFunctionExpression} = require('./arrow-function-expression');
|
|
4
|
+
const {FunctionDeclaration} = require('./function-declaration');
|
|
6
5
|
|
|
7
6
|
module.exports.ArrowFunctionExpression = ArrowFunctionExpression;
|
|
7
|
+
module.exports.FunctionDeclaration = FunctionDeclaration;
|
|
8
8
|
|
|
9
9
|
module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
|
|
10
10
|
const {node} = path;
|
|
@@ -64,31 +64,6 @@ module.exports.ObjectMethod = (path, {print}) => {
|
|
|
64
64
|
print('__body');
|
|
65
65
|
};
|
|
66
66
|
|
|
67
|
-
module.exports.FunctionDeclaration = (path, {print, maybe}) => {
|
|
68
|
-
const {async} = path.node;
|
|
69
|
-
|
|
70
|
-
if (!isFirst(path) && !hasPrevNewline(path) && !path.parentPath.isExportDeclaration())
|
|
71
|
-
print('\n');
|
|
72
|
-
|
|
73
|
-
maybe.print(async, 'async ');
|
|
74
|
-
print('function ');
|
|
75
|
-
print('__id');
|
|
76
|
-
print('(');
|
|
77
|
-
|
|
78
|
-
const params = path.get('params');
|
|
79
|
-
const n = params.length - 1;
|
|
80
|
-
|
|
81
|
-
for (let i = 0; i <= n; i++) {
|
|
82
|
-
print(params[i]);
|
|
83
|
-
|
|
84
|
-
if (i < n)
|
|
85
|
-
print(', ');
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
print(') ');
|
|
89
|
-
print('__body');
|
|
90
|
-
};
|
|
91
|
-
|
|
92
67
|
module.exports.ClassMethod = (path, {print, maybe}) => {
|
|
93
68
|
const {kind} = path.node;
|
|
94
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);
|
|
@@ -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",
|