@putout/printer 8.46.0 → 8.48.0
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/array-expression/array-expression.js +12 -2
- package/lib/tokenize/expressions/array-expression/newline.js +2 -2
- package/lib/tokenize/is.js +1 -1
- package/lib/tokenize/statements/return-statement/maybe-space-after-keyword.js +3 -0
- package/lib/tokenize/statements/try-statement/try-statements.js +16 -8
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
2024.06.07, v8.48.0
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- 715d6f3 @putout/printer: TryStatement: add support of format: space (#15)
|
|
5
|
+
|
|
6
|
+
2024.06.06, v8.47.0
|
|
7
|
+
|
|
8
|
+
feature:
|
|
9
|
+
- 53c7909 @putout/printer: ArrayExpression: comma (coderaiser/putout#206)
|
|
10
|
+
|
|
1
11
|
2024.06.06, v8.46.0
|
|
2
12
|
|
|
3
13
|
feature:
|
|
@@ -6,7 +6,7 @@ const {
|
|
|
6
6
|
isStringAndIdentifier,
|
|
7
7
|
isIdentifierAndIdentifier,
|
|
8
8
|
isStringAndArray,
|
|
9
|
-
|
|
9
|
+
isSimpleAndNotEmptyObject,
|
|
10
10
|
isNextObject,
|
|
11
11
|
} = require('../../is');
|
|
12
12
|
|
|
@@ -29,6 +29,7 @@ const {
|
|
|
29
29
|
isSpreadElement,
|
|
30
30
|
isStringLiteral,
|
|
31
31
|
isIdentifier,
|
|
32
|
+
isFunction,
|
|
32
33
|
} = types;
|
|
33
34
|
|
|
34
35
|
const isNextString = (path) => isStringLiteral(path.getNextSibling());
|
|
@@ -44,6 +45,15 @@ const isSpreadBeforeObject = (a) => {
|
|
|
44
45
|
if (!prev.isSpreadElement())
|
|
45
46
|
return false;
|
|
46
47
|
|
|
48
|
+
const argCall = prev.get('argument');
|
|
49
|
+
|
|
50
|
+
if (argCall.isCallExpression()) {
|
|
51
|
+
const [first] = argCall.get('arguments');
|
|
52
|
+
|
|
53
|
+
if (isFunction(first))
|
|
54
|
+
return false;
|
|
55
|
+
}
|
|
56
|
+
|
|
47
57
|
if (prev.getPrevSibling().isObjectExpression())
|
|
48
58
|
return false;
|
|
49
59
|
|
|
@@ -158,7 +168,7 @@ module.exports.ArrayExpression = {
|
|
|
158
168
|
maybe.indent(elements.length && isNewLine);
|
|
159
169
|
}
|
|
160
170
|
|
|
161
|
-
if (
|
|
171
|
+
if (isSimpleAndNotEmptyObject(elements) && !isSpreadElement(elements.at(-1))) {
|
|
162
172
|
print(',');
|
|
163
173
|
print.breakline();
|
|
164
174
|
}
|
|
@@ -21,7 +21,7 @@ const {
|
|
|
21
21
|
isCoupleLines,
|
|
22
22
|
isStringAndArray,
|
|
23
23
|
isIdentifierAndIdentifier,
|
|
24
|
-
|
|
24
|
+
isSimpleAndNotEmptyObject,
|
|
25
25
|
} = require('../../is');
|
|
26
26
|
|
|
27
27
|
const {round} = Math;
|
|
@@ -62,7 +62,7 @@ module.exports.isMultiLine = (path, {elements, maxElementsInOneLine}) => {
|
|
|
62
62
|
if (elements.length > 3 && !isObjectExpression(elements[0]))
|
|
63
63
|
return MULTI_LINE;
|
|
64
64
|
|
|
65
|
-
if (
|
|
65
|
+
if (isSimpleAndNotEmptyObject(elements))
|
|
66
66
|
return MULTI_LINE;
|
|
67
67
|
|
|
68
68
|
if (isOneSimple(path))
|
package/lib/tokenize/is.js
CHANGED
|
@@ -67,7 +67,7 @@ function isStringAndIdentifier([a, b]) {
|
|
|
67
67
|
return isStringLiteral(a) && isIdentifier(b);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
module.exports.
|
|
70
|
+
module.exports.isSimpleAndNotEmptyObject = ([a, b]) => {
|
|
71
71
|
if (!isIdentifier(a) && !isSpreadElement(a) && !isArrayExpression(a))
|
|
72
72
|
return false;
|
|
73
73
|
|
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const {isNext} = require('../../is');
|
|
3
|
+
const {isNext, isParentLast} = require('../../is');
|
|
4
4
|
|
|
5
5
|
module.exports.TryStatement = {
|
|
6
6
|
print(path, {print}) {
|
|
7
7
|
const finalizer = path.get('finalizer');
|
|
8
8
|
print.indent();
|
|
9
|
-
print('try
|
|
9
|
+
print('try');
|
|
10
|
+
print.space();
|
|
10
11
|
print('__block');
|
|
11
12
|
print('__handler');
|
|
12
13
|
|
|
13
14
|
if (finalizer.node) {
|
|
14
|
-
print(
|
|
15
|
+
print.space();
|
|
15
16
|
print('finally');
|
|
16
|
-
print(
|
|
17
|
+
print.space();
|
|
17
18
|
print(finalizer);
|
|
18
19
|
print.newline();
|
|
19
20
|
}
|
|
@@ -25,18 +26,25 @@ module.exports.TryStatement = {
|
|
|
25
26
|
},
|
|
26
27
|
};
|
|
27
28
|
|
|
28
|
-
module.exports.CatchClause = (path, {print}) => {
|
|
29
|
+
module.exports.CatchClause = (path, {print, maybe}) => {
|
|
29
30
|
const param = path.get('param');
|
|
30
31
|
const body = path.get('body');
|
|
31
32
|
|
|
32
|
-
print(
|
|
33
|
-
print('catch
|
|
33
|
+
print.space();
|
|
34
|
+
print('catch');
|
|
35
|
+
print.space();
|
|
34
36
|
|
|
35
37
|
if (param.node) {
|
|
36
38
|
print('(');
|
|
37
39
|
print(param);
|
|
38
|
-
print(')
|
|
40
|
+
print(')');
|
|
41
|
+
print.space();
|
|
39
42
|
}
|
|
40
43
|
|
|
41
44
|
print(body);
|
|
45
|
+
maybe.print.newline(isInsideBlock(path));
|
|
42
46
|
};
|
|
47
|
+
|
|
48
|
+
function isInsideBlock(path) {
|
|
49
|
+
return path.parentPath.parentPath.isBlockStatement();
|
|
50
|
+
}
|
package/package.json
CHANGED