@putout/printer 18.0.8 → 18.0.10
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 +14 -0
- package/lib/tokenize/expressions/new-expression/new-expression.js +6 -7
- package/lib/tokenize/expressions/object-expression/object-expression.js +24 -40
- package/lib/tokenize/is.js +3 -0
- package/lib/tokenize/statements/variable-declaration/variable-declaration.js +1 -2
- package/package.json +1 -1
- package/lib/tokenize/expressions/object-expression/is-third-object-inside-array.js +0 -16
package/ChangeLog
CHANGED
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
2026.03.05, v18.0.10
|
|
2
|
+
|
|
3
|
+
feature:
|
|
4
|
+
- d29c6de @putout/printer: ObjectExpression: isInsideTupleLike: simplify
|
|
5
|
+
- e4ee1c0 @putout/printer: ObjectExpression: isMemberExpressionCallee: simplify
|
|
6
|
+
- e1df5a9 @putout/printer: isThirdObjectInsideArray: rm
|
|
7
|
+
- c90efb6 ObjectExpression: isInsideExpression: reuse from NewExpression
|
|
8
|
+
- 84b86bb @putout/printer: VariableDeclaration: isInsideBody: reuse in ObjectExpression
|
|
9
|
+
|
|
10
|
+
2026.03.05, v18.0.9
|
|
11
|
+
|
|
12
|
+
feature:
|
|
13
|
+
- 5b851ca @putout/printer: VariableDeclaration: isInsideBody: simplify
|
|
14
|
+
|
|
1
15
|
2026.03.05, v18.0.8
|
|
2
16
|
|
|
3
17
|
feature:
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
exists,
|
|
4
|
+
isInsideExpression,
|
|
5
|
+
} from '#is';
|
|
3
6
|
import {isMarkedAfter} from '#mark';
|
|
4
7
|
|
|
5
|
-
const {
|
|
6
|
-
isExpressionStatement,
|
|
7
|
-
isMemberExpression,
|
|
8
|
-
} = types;
|
|
8
|
+
const {isMemberExpression} = types;
|
|
9
9
|
|
|
10
|
-
const isInsideExpressionStatement = ({parentPath}) => isExpressionStatement(parentPath);
|
|
11
10
|
const notFirst = ({parentPath}) => exists(parentPath.getPrevSibling());
|
|
12
11
|
const isInsideMember = ({parentPath}) => isMemberExpression(parentPath);
|
|
13
12
|
|
|
@@ -22,7 +21,7 @@ const getPrev = ({parentPath}) => {
|
|
|
22
21
|
|
|
23
22
|
export const NewExpression = {
|
|
24
23
|
beforeIf(path) {
|
|
25
|
-
if (!
|
|
24
|
+
if (!isInsideExpression(path))
|
|
26
25
|
return false;
|
|
27
26
|
|
|
28
27
|
const [exists, prev] = getPrev(path);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
+
import {createTypeChecker} from '#type-checker';
|
|
2
3
|
import {
|
|
3
4
|
isCoupleLines,
|
|
4
5
|
isForOf,
|
|
@@ -9,51 +10,41 @@ import {
|
|
|
9
10
|
hasLeadingComment,
|
|
10
11
|
exists,
|
|
11
12
|
isInsideCall,
|
|
13
|
+
isInsideBody,
|
|
14
|
+
isInsideExpression,
|
|
12
15
|
} from '#is';
|
|
13
16
|
import {parseComments} from '../../comment/comment.js';
|
|
14
17
|
import {isInsideTuple} from './is-inside-tuple.js';
|
|
15
18
|
import {isLooksLikeChain} from '../member-expression/is-looks-like-chain.js';
|
|
16
|
-
import {isThirdObjectInsideArray} from './is-third-object-inside-array.js';
|
|
17
19
|
|
|
18
20
|
const {
|
|
19
|
-
isStringLiteral,
|
|
20
|
-
isArrayExpression,
|
|
21
21
|
isSpreadElement,
|
|
22
|
+
isMemberExpression,
|
|
22
23
|
} = types;
|
|
23
24
|
|
|
24
|
-
const isBodyOfArrow = (path) => path.parentPath.node.body === path.node;
|
|
25
25
|
const isLogical = (path) => path.get('argument').isLogicalExpression();
|
|
26
26
|
const isValue = (path) => path.get('properties.0.value').node;
|
|
27
|
-
const isParentExpression = (path) => path.parentPath.isExpressionStatement();
|
|
28
27
|
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
return false;
|
|
32
|
-
|
|
33
|
-
const callee = parentPath.get('callee');
|
|
34
|
-
|
|
35
|
-
if (!callee.isMemberExpression())
|
|
36
|
-
return false;
|
|
37
|
-
|
|
38
|
-
return isLooksLikeChain(callee);
|
|
39
|
-
};
|
|
28
|
+
const isParens = createTypeChecker([isInsideBody, isInsideExpression]);
|
|
29
|
+
const getCallee = (fn) => (a) => fn(a.get('callee'));
|
|
40
30
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
return false;
|
|
47
|
-
|
|
48
|
-
return isInsideCall(parentPath.parentPath);
|
|
49
|
-
}
|
|
31
|
+
const isMemberExpressionCallee = createTypeChecker([
|
|
32
|
+
'-: parentPath -> !CallExpression',
|
|
33
|
+
['-: parentPath -> !', getCallee(isMemberExpression)],
|
|
34
|
+
['+: parentPath', getCallee(isLooksLikeChain)],
|
|
35
|
+
]);
|
|
50
36
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
37
|
+
const isInsideNestedArrayCall = createTypeChecker([
|
|
38
|
+
isInsideTuple,
|
|
39
|
+
'-: parentPath -> !ArrayExpression',
|
|
40
|
+
'-: parentPath.parentPath -> !ArrayExpression',
|
|
41
|
+
['+: parentPath.parentPath', isInsideCall],
|
|
42
|
+
]);
|
|
43
|
+
|
|
44
|
+
const isInsideTupleLike = createTypeChecker([
|
|
45
|
+
['+', isInsideTuple],
|
|
46
|
+
'+: parentPath.parentPath.node.elements.0 -> StringLiteral',
|
|
47
|
+
]);
|
|
57
48
|
|
|
58
49
|
export const ObjectExpression = (path, printer, semantics) => {
|
|
59
50
|
const {trailingComma} = semantics;
|
|
@@ -63,7 +54,7 @@ export const ObjectExpression = (path, printer, semantics) => {
|
|
|
63
54
|
indent,
|
|
64
55
|
} = printer;
|
|
65
56
|
|
|
66
|
-
const insideNestedArrayCall =
|
|
57
|
+
const insideNestedArrayCall = isInsideNestedArrayCall(path);
|
|
67
58
|
|
|
68
59
|
maybe.indent.inc(!insideNestedArrayCall);
|
|
69
60
|
|
|
@@ -114,7 +105,7 @@ export const ObjectExpression = (path, printer, semantics) => {
|
|
|
114
105
|
if (!insideNestedArrayCall) {
|
|
115
106
|
indent.dec();
|
|
116
107
|
maybe.indent(manyLines);
|
|
117
|
-
} else if (
|
|
108
|
+
} else if (isInsideTupleLike(path)) {
|
|
118
109
|
indent.dec();
|
|
119
110
|
indent();
|
|
120
111
|
indent.inc();
|
|
@@ -182,10 +173,3 @@ export function isOneLine(path) {
|
|
|
182
173
|
|
|
183
174
|
return !isValue(path);
|
|
184
175
|
}
|
|
185
|
-
|
|
186
|
-
function isParens(path) {
|
|
187
|
-
if (isBodyOfArrow(path))
|
|
188
|
-
return true;
|
|
189
|
-
|
|
190
|
-
return isParentExpression(path);
|
|
191
|
-
}
|
package/lib/tokenize/is.js
CHANGED
|
@@ -16,11 +16,14 @@ const {
|
|
|
16
16
|
isBlockStatement,
|
|
17
17
|
isTSModuleBlock,
|
|
18
18
|
isSwitchCase,
|
|
19
|
+
isExpressionStatement,
|
|
19
20
|
} = types;
|
|
20
21
|
|
|
21
22
|
export const isInsideProgram = (path) => isProgram(path.parentPath);
|
|
22
23
|
export const isInsideBlock = (path) => isBlockStatement(path.parentPath);
|
|
23
24
|
export const isInsideSwitchCase = (path) => isSwitchCase(path.parentPath);
|
|
25
|
+
export const isInsideBody = ({node, parentPath}) => node === parentPath.node.body;
|
|
26
|
+
export const isInsideExpression = ({parentPath}) => isExpressionStatement(parentPath);
|
|
24
27
|
|
|
25
28
|
export const isInsideTSModuleBlock = ({parentPath}) => isTSModuleBlock(parentPath);
|
|
26
29
|
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
isInsideTSModuleBlock,
|
|
14
14
|
isInsideProgram,
|
|
15
15
|
isInsideSwitchCase,
|
|
16
|
+
isInsideBody,
|
|
16
17
|
} from '#is';
|
|
17
18
|
import {maybeSpaceAfterKeyword} from './maybe-space-after-keyword.js';
|
|
18
19
|
import {isConcatenation} from '../../expressions/binary-expression/concatenate.js';
|
|
@@ -21,8 +22,6 @@ import {maybeDeclare} from '../../maybe/maybe-declare.js';
|
|
|
21
22
|
|
|
22
23
|
const {isExportDeclaration} = types;
|
|
23
24
|
|
|
24
|
-
const isInsideBody = (path) => path.node === path.parentPath.node.body;
|
|
25
|
-
|
|
26
25
|
const isInsideBlockLike = createTypeChecker([
|
|
27
26
|
isInsideProgram,
|
|
28
27
|
isInsideBlock,
|
package/package.json
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import {types} from '@putout/babel';
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
isArrayExpression,
|
|
5
|
-
isCallExpression,
|
|
6
|
-
isIdentifier,
|
|
7
|
-
} = types;
|
|
8
|
-
|
|
9
|
-
export const isThirdObjectInsideArray = ({parentPath}) => {
|
|
10
|
-
if (!isArrayExpression(parentPath))
|
|
11
|
-
return false;
|
|
12
|
-
|
|
13
|
-
const [, second] = parentPath.node.elements;
|
|
14
|
-
|
|
15
|
-
return isCallExpression(second) && !!isIdentifier(second);
|
|
16
|
-
};
|