@putout/printer 1.71.2 → 1.72.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 +11 -0
- package/lib/tokenize/comments.js +1 -0
- package/lib/tokenize/expressions/array-pattern.js +1 -1
- package/lib/tokenize/expressions/functions/object-method.js +30 -20
- package/lib/tokenize/statements/break-statement.js +5 -0
- package/lib/tokenize/statements/for-statement.js +0 -1
- package/lib/tokenize/statements/if-statement.js +3 -1
- package/lib/tokenize/statements/switch-statement.js +43 -31
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
2023.04.26, v1.72.1
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- d3c1dbe @putout/printer: improve support of ArrayPattern
|
|
5
|
+
|
|
6
|
+
2023.04.26, v1.72.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- e1ca06a @putout/printer: improve support of SwitchCase
|
|
10
|
+
- 82b3293 @putout/printer: improve ability to determine linebreak in ObjectMethod
|
|
11
|
+
|
|
1
12
|
2023.04.25, v1.71.2
|
|
2
13
|
|
|
3
14
|
feature:
|
package/lib/tokenize/comments.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const isForOf = ({parentPath}) => parentPath.parentPath.parentPath
|
|
3
|
+
const isForOf = ({parentPath}) => parentPath.parentPath.parentPath?.isForOfStatement();
|
|
4
4
|
|
|
5
5
|
module.exports.ArrayPattern = (path, {indent, maybe, print}) => {
|
|
6
6
|
print('[');
|
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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]);
|
|
3
|
+
const {isNewlineBetweenSiblings} = require('../../is');
|
|
4
|
+
module.exports.ObjectMethod = {
|
|
5
|
+
print(path, {print}) {
|
|
6
|
+
const {kind} = path.node;
|
|
17
7
|
|
|
18
|
-
if (
|
|
19
|
-
print(
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
8
|
+
if (kind !== 'method')
|
|
9
|
+
print(`${kind} `);
|
|
10
|
+
|
|
11
|
+
print('__key');
|
|
12
|
+
print('(');
|
|
13
|
+
|
|
14
|
+
const params = path.get('params');
|
|
15
|
+
const n = params.length - 1;
|
|
16
|
+
|
|
17
|
+
for (let i = 0; i <= n; i++) {
|
|
18
|
+
print(params[i]);
|
|
19
|
+
|
|
20
|
+
if (i < n)
|
|
21
|
+
print(', ');
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
print(') ');
|
|
25
|
+
print('__body');
|
|
26
|
+
},
|
|
27
|
+
afterIf(path) {
|
|
28
|
+
return isNewlineBetweenSiblings(path);
|
|
29
|
+
},
|
|
30
|
+
after(path, {print}) {
|
|
31
|
+
print.linebreak();
|
|
32
|
+
},
|
|
24
33
|
};
|
|
34
|
+
|
|
@@ -5,6 +5,8 @@ const {
|
|
|
5
5
|
isNextParent,
|
|
6
6
|
} = require('../is');
|
|
7
7
|
|
|
8
|
+
const insideCase = (path) => path.parentPath.isSwitchCase();
|
|
9
|
+
|
|
8
10
|
module.exports.BreakStatement = {
|
|
9
11
|
split(path, {print}) {
|
|
10
12
|
print.newline();
|
|
@@ -20,6 +22,9 @@ module.exports.BreakStatement = {
|
|
|
20
22
|
if (isNextParent(path))
|
|
21
23
|
return true;
|
|
22
24
|
|
|
25
|
+
if (insideCase(path))
|
|
26
|
+
return true;
|
|
27
|
+
|
|
23
28
|
return false;
|
|
24
29
|
},
|
|
25
30
|
};
|
|
@@ -14,8 +14,9 @@ module.exports.IfStatement = {
|
|
|
14
14
|
|
|
15
15
|
const consequent = path.get('consequent');
|
|
16
16
|
const alternate = path.get('alternate');
|
|
17
|
+
const isConsequentBlock = consequent.isBlockStatement();
|
|
17
18
|
|
|
18
|
-
if (
|
|
19
|
+
if (isConsequentBlock) {
|
|
19
20
|
print(' ');
|
|
20
21
|
print(consequent);
|
|
21
22
|
} else {
|
|
@@ -35,6 +36,7 @@ module.exports.IfStatement = {
|
|
|
35
36
|
write.space();
|
|
36
37
|
traverse(alternate);
|
|
37
38
|
} else if (exists(alternate)) {
|
|
39
|
+
maybe.indent(!isConsequentBlock);
|
|
38
40
|
write('else');
|
|
39
41
|
print.newline();
|
|
40
42
|
indent.inc();
|
|
@@ -1,42 +1,54 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
print(
|
|
7
|
-
|
|
8
|
-
print(') {');
|
|
9
|
-
print.newline();
|
|
10
|
-
|
|
11
|
-
const cases = path.get('cases');
|
|
12
|
-
const n = cases.length - 1;
|
|
13
|
-
|
|
14
|
-
for (const [index, switchCase] of cases.entries()) {
|
|
15
|
-
print('case');
|
|
3
|
+
const {isNext} = require('../is');
|
|
4
|
+
|
|
5
|
+
module.exports.SwitchStatement = {
|
|
6
|
+
print(path, {print, maybe}) {
|
|
7
|
+
print('switch');
|
|
16
8
|
print.space();
|
|
17
|
-
print(
|
|
18
|
-
print('
|
|
9
|
+
print('(');
|
|
10
|
+
print('__discriminant');
|
|
11
|
+
print(') {');
|
|
12
|
+
print.newline();
|
|
19
13
|
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
maybe.print.newline(!isBlock);
|
|
14
|
+
const cases = path.get('cases');
|
|
15
|
+
const n = cases.length - 1;
|
|
23
16
|
|
|
24
|
-
for (const
|
|
25
|
-
|
|
17
|
+
for (const [index, switchCase] of cases.entries()) {
|
|
18
|
+
print('case');
|
|
19
|
+
print.space();
|
|
20
|
+
print(switchCase.get('test'));
|
|
21
|
+
print(':');
|
|
22
|
+
|
|
23
|
+
const isBlock = switchCase.get('consequent.0').isBlockStatement();
|
|
24
|
+
|
|
25
|
+
maybe.indent.inc(!isBlock);
|
|
26
|
+
maybe.print.newline(!isBlock);
|
|
27
|
+
|
|
28
|
+
for (const consequent of switchCase.get('consequent')) {
|
|
29
|
+
if (!consequent.isBlockStatement()) {
|
|
30
|
+
print(consequent);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
print.space();
|
|
26
35
|
print(consequent);
|
|
27
|
-
continue;
|
|
28
36
|
}
|
|
29
37
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
if (index < n) {
|
|
35
|
-
print.indent();
|
|
38
|
+
if (index < n) {
|
|
39
|
+
print.linebreak();
|
|
40
|
+
}
|
|
41
|
+
|
|
36
42
|
maybe.indent.dec(!isBlock);
|
|
37
|
-
print.newline();
|
|
38
43
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
44
|
+
|
|
45
|
+
print('}');
|
|
46
|
+
},
|
|
47
|
+
afterSatisfy: () => [
|
|
48
|
+
isNext,
|
|
49
|
+
],
|
|
50
|
+
after(path, {print}) {
|
|
51
|
+
print.breakline();
|
|
52
|
+
print.breakline();
|
|
53
|
+
},
|
|
42
54
|
};
|
package/package.json
CHANGED