@putout/printer 1.68.0 → 1.69.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 +10 -0
- package/lib/tokenize/expressions/functions/function-expression.js +36 -0
- package/lib/tokenize/expressions/functions/functions.js +5 -59
- package/lib/tokenize/expressions/functions/object-method.js +24 -0
- package/lib/tokenize/expressions/object-expression.js +0 -1
- package/lib/tokenize/is.js +1 -1
- package/lib/tokenize/statements/block-statement.js +5 -0
- package/lib/tokenize/statements/if-statement.js +3 -3
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2023.04.24, v1.69.1
|
|
2
|
+
|
|
3
|
+
fix:
|
|
4
|
+
- be3dc7d @putout/printer: newline after ObjectProperty
|
|
5
|
+
|
|
6
|
+
2023.04.23, v1.69.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- fb7202b @putout/printer: improve support of newline after IfStatement inside of ObjectMethod
|
|
10
|
+
|
|
1
11
|
2023.04.23, v1.68.0
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
|
|
4
|
+
const {node} = path;
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
generator,
|
|
8
|
+
async,
|
|
9
|
+
} = node;
|
|
10
|
+
|
|
11
|
+
maybe.write(async, 'async ');
|
|
12
|
+
write('function');
|
|
13
|
+
maybe.write(generator, '*');
|
|
14
|
+
|
|
15
|
+
const id = path.get('id');
|
|
16
|
+
|
|
17
|
+
if (id.node) {
|
|
18
|
+
write.space();
|
|
19
|
+
traverse(id);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
print('(');
|
|
23
|
+
|
|
24
|
+
const params = path.get('params');
|
|
25
|
+
const n = params.length;
|
|
26
|
+
|
|
27
|
+
for (let i = 0; i < n; i++) {
|
|
28
|
+
print(params[i]);
|
|
29
|
+
|
|
30
|
+
if (i < n - 1)
|
|
31
|
+
print(', ');
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
print(') ');
|
|
35
|
+
print('__body');
|
|
36
|
+
};
|
|
@@ -3,65 +3,11 @@
|
|
|
3
3
|
const {ArrowFunctionExpression} = require('./arrow-function-expression');
|
|
4
4
|
const {FunctionDeclaration} = require('./function-declaration');
|
|
5
5
|
const {ClassMethod} = require('./class-method');
|
|
6
|
+
const {ObjectMethod} = require('./object-method');
|
|
7
|
+
const {FunctionExpression} = require('./function-expression');
|
|
6
8
|
|
|
7
|
-
module.exports.ArrowFunctionExpression = ArrowFunctionExpression;
|
|
8
9
|
module.exports.FunctionDeclaration = FunctionDeclaration;
|
|
10
|
+
module.exports.FunctionExpression = FunctionExpression;
|
|
11
|
+
module.exports.ArrowFunctionExpression = ArrowFunctionExpression;
|
|
9
12
|
module.exports.ClassMethod = ClassMethod;
|
|
10
|
-
|
|
11
|
-
module.exports.FunctionExpression = (path, {print, maybe, write, traverse}) => {
|
|
12
|
-
const {node} = path;
|
|
13
|
-
|
|
14
|
-
const {
|
|
15
|
-
generator,
|
|
16
|
-
async,
|
|
17
|
-
} = node;
|
|
18
|
-
|
|
19
|
-
maybe.write(async, 'async ');
|
|
20
|
-
write('function');
|
|
21
|
-
maybe.write(generator, '*');
|
|
22
|
-
|
|
23
|
-
const id = path.get('id');
|
|
24
|
-
|
|
25
|
-
if (id.node) {
|
|
26
|
-
write.space();
|
|
27
|
-
traverse(id);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
print('(');
|
|
31
|
-
|
|
32
|
-
const params = path.get('params');
|
|
33
|
-
const n = params.length;
|
|
34
|
-
|
|
35
|
-
for (let i = 0; i < n; i++) {
|
|
36
|
-
print(params[i]);
|
|
37
|
-
|
|
38
|
-
if (i < n - 1)
|
|
39
|
-
print(', ');
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
print(') ');
|
|
43
|
-
print('__body');
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
module.exports.ObjectMethod = (path, {print}) => {
|
|
47
|
-
const {kind} = path.node;
|
|
48
|
-
|
|
49
|
-
if (kind !== 'method')
|
|
50
|
-
print(`${kind} `);
|
|
51
|
-
|
|
52
|
-
print('__key');
|
|
53
|
-
print('(');
|
|
54
|
-
|
|
55
|
-
const params = path.get('params');
|
|
56
|
-
const n = params.length - 1;
|
|
57
|
-
|
|
58
|
-
for (let i = 0; i <= n; i++) {
|
|
59
|
-
print(params[i]);
|
|
60
|
-
|
|
61
|
-
if (i < n)
|
|
62
|
-
print(', ');
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
print(') ');
|
|
66
|
-
print('__body');
|
|
67
|
-
};
|
|
13
|
+
module.exports.ObjectMethod = ObjectMethod;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
module.exports.ObjectMethod = (path, {print}) => {
|
|
4
|
+
const {kind} = path.node;
|
|
5
|
+
|
|
6
|
+
if (kind !== 'method')
|
|
7
|
+
print(`${kind} `);
|
|
8
|
+
|
|
9
|
+
print('__key');
|
|
10
|
+
print('(');
|
|
11
|
+
|
|
12
|
+
const params = path.get('params');
|
|
13
|
+
const n = params.length - 1;
|
|
14
|
+
|
|
15
|
+
for (let i = 0; i <= n; i++) {
|
|
16
|
+
print(params[i]);
|
|
17
|
+
|
|
18
|
+
if (i < n)
|
|
19
|
+
print(', ');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
print(') ');
|
|
23
|
+
print('__body');
|
|
24
|
+
};
|
package/lib/tokenize/is.js
CHANGED
|
@@ -7,6 +7,8 @@ const {
|
|
|
7
7
|
exists,
|
|
8
8
|
} = require('../is');
|
|
9
9
|
|
|
10
|
+
const {isArrowFunctionExpression} = require('@babel/types');
|
|
11
|
+
|
|
10
12
|
const isFirstStatement = (path) => path.get('body.0')?.isStatement();
|
|
11
13
|
|
|
12
14
|
module.exports.BlockStatement = {
|
|
@@ -48,6 +50,9 @@ function shouldAddNewlineAfter(path) {
|
|
|
48
50
|
if (!isNext(path) && !isNext(path.parentPath) && isParentProgram(path.parentPath))
|
|
49
51
|
return false;
|
|
50
52
|
|
|
53
|
+
if (path.parentPath.isIfStatement() && path.find(isArrowFunctionExpression))
|
|
54
|
+
return true;
|
|
55
|
+
|
|
51
56
|
if (parentPath.isStatement() && !path.node.body.length && !isNext(parentPath))
|
|
52
57
|
return false;
|
|
53
58
|
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
const {markAfter} = require('../mark');
|
|
4
|
+
const {exists} = require('../is');
|
|
4
5
|
|
|
5
6
|
const isEmptyConsequent = (path) => path.get('consequent').isEmptyStatement();
|
|
6
7
|
|
|
@@ -33,7 +34,7 @@ module.exports.IfStatement = {
|
|
|
33
34
|
write('else');
|
|
34
35
|
write.space();
|
|
35
36
|
traverse(alternate);
|
|
36
|
-
} else if (alternate
|
|
37
|
+
} else if (exists(alternate)) {
|
|
37
38
|
write('else');
|
|
38
39
|
print.newline();
|
|
39
40
|
indent.inc();
|
|
@@ -53,8 +54,7 @@ module.exports.IfStatement = {
|
|
|
53
54
|
return true;
|
|
54
55
|
},
|
|
55
56
|
after: (path, {print}) => {
|
|
56
|
-
print.
|
|
57
|
-
print.newline();
|
|
57
|
+
print.linebreak();
|
|
58
58
|
markAfter(path);
|
|
59
59
|
},
|
|
60
60
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@putout/printer",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.69.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",
|