@putout/printer 18.7.7 → 18.7.9
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/comments/parse-trailing-comments.js +1 -1
- package/lib/tokenize/expressions/member-expression/is-looks-like-chain/check-calls-count.js +19 -0
- package/lib/tokenize/expressions/member-expression/{is-looks-like-chain.js → is-looks-like-chain/index.js} +3 -13
- package/lib/tokenize/expressions/member-expression/member-expressions.js +1 -1
- package/lib/tokenize/expressions/object-expression/object-expression.js +1 -1
- package/lib/tokenize/expressions/object-pattern/comma.js +28 -0
- package/lib/tokenize/expressions/object-pattern/is.js +0 -11
- package/lib/tokenize/expressions/object-pattern/object-pattern.js +3 -11
- package/lib/tokenize/statements/block-statement/is-call-inside-chain.js +1 -1
- package/package.json +1 -1
package/ChangeLog
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
isCoupleLines,
|
|
5
5
|
isNext,
|
|
6
6
|
} from '#is';
|
|
7
|
-
import {isLooksLikeChain} from '../expressions/member-expression/is-looks-like-chain.js';
|
|
7
|
+
import {isLooksLikeChain} from '../expressions/member-expression/is-looks-like-chain/index.js';
|
|
8
8
|
import {
|
|
9
9
|
printTrailingComments,
|
|
10
10
|
hasTrailingCommentsPrinter,
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {createTypeChecker} from '#type-checker';
|
|
3
|
+
|
|
4
|
+
const {isCallExpression} = types;
|
|
5
|
+
|
|
6
|
+
export const checkCallsCount = (path, {properties}) => {
|
|
7
|
+
const calls = properties.filter(isCallExpression);
|
|
8
|
+
return checkFilteredCalls(calls);
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const isTwoCallsWithoutName = createTypeChecker([
|
|
12
|
+
['-: length -> !', '=', 2],
|
|
13
|
+
['+: 0.name -> -'],
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
const checkFilteredCalls = createTypeChecker([
|
|
17
|
+
['-', isTwoCallsWithoutName],
|
|
18
|
+
['+: length', '>', 1],
|
|
19
|
+
]);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
2
|
import {createTypeChecker} from '#type-checker';
|
|
3
|
-
import {chain} from '
|
|
3
|
+
import {chain} from '../chain.js';
|
|
4
|
+
import {checkCallsCount} from './check-calls-count.js';
|
|
4
5
|
|
|
5
6
|
const hasPropertyWithComment = (properties) => {
|
|
6
7
|
return properties.find(hasComment);
|
|
@@ -37,9 +38,8 @@ const isLastArgInCall = createTypeChecker([
|
|
|
37
38
|
['+', isPathLastArg],
|
|
38
39
|
]);
|
|
39
40
|
|
|
40
|
-
const isCall = (a) => a.type === 'CallExpression';
|
|
41
|
-
|
|
42
41
|
const callWithRoot = (fn) => (a, {root}) => fn(root);
|
|
42
|
+
|
|
43
43
|
const isExcludedFromChain = createTypeChecker([
|
|
44
44
|
'+: -> UnaryExpression',
|
|
45
45
|
'+: -> IfStatement',
|
|
@@ -57,16 +57,6 @@ const isInsideMemberCall = createTypeChecker([
|
|
|
57
57
|
const callWithProperties = (fn) => (a, {properties}) => fn(properties);
|
|
58
58
|
const isFindUpIf = (path) => path.find(isIfUp);
|
|
59
59
|
|
|
60
|
-
const checkCallsCount = (path, {properties}) => {
|
|
61
|
-
const calls = properties.filter(isCall);
|
|
62
|
-
const [firstCall] = calls;
|
|
63
|
-
|
|
64
|
-
if (calls.length === 2 && !firstCall.name)
|
|
65
|
-
return false;
|
|
66
|
-
|
|
67
|
-
return calls.length > 1;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
60
|
export const isLooksLikeChain = (path) => {
|
|
71
61
|
const [root, properties] = chain(path);
|
|
72
62
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {maybeParens} from '#maybe-parens';
|
|
2
2
|
import {createTypeChecker} from '#type-checker';
|
|
3
3
|
import {maybePrintComputed} from '../object-expression/maybe-print-computed.js';
|
|
4
|
-
import {isLooksLikeChain} from './is-looks-like-chain.js';
|
|
4
|
+
import {isLooksLikeChain} from './is-looks-like-chain/index.js';
|
|
5
5
|
|
|
6
6
|
const isObjectInsideArrow = createTypeChecker([
|
|
7
7
|
'-: node.object -> !ObjectExpression',
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
hasTrailingComment,
|
|
13
13
|
} from '#is';
|
|
14
14
|
import {isInsideTuple} from './is-inside-tuple.js';
|
|
15
|
-
import {isLooksLikeChain} from '../member-expression/is-looks-like-chain.js';
|
|
15
|
+
import {isLooksLikeChain} from '../member-expression/is-looks-like-chain/index.js';
|
|
16
16
|
import {isCommaAfterSpread} from './comma.js';
|
|
17
17
|
import {isMultilineOption} from '../array-expression/is.js';
|
|
18
18
|
import {isLinebreakAfterProperty} from './linebreak.js';
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import {types} from '@putout/babel';
|
|
2
|
+
import {createTypeChecker} from '#type-checker';
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
isForOfStatement,
|
|
6
|
+
isAssignmentPattern,
|
|
7
|
+
} = types;
|
|
8
|
+
|
|
9
|
+
const isCoupleOption = (a, {couple}) => couple;
|
|
10
|
+
|
|
11
|
+
export function isInsideForOf({parentPath}) {
|
|
12
|
+
return isForOfStatement(parentPath.parentPath.parentPath);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export function isPrevAssign(path) {
|
|
16
|
+
const prev = path.getPrevSibling();
|
|
17
|
+
|
|
18
|
+
return isAssignmentPattern(prev.node.value);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const isCommaAfterProperty = createTypeChecker([
|
|
22
|
+
['+', isCoupleOption],
|
|
23
|
+
['-: key -> -'],
|
|
24
|
+
['-', isPrevAssign],
|
|
25
|
+
['-: parentPath', isInsideForOf],
|
|
26
|
+
['+: node.value.right -> ObjectExpression'],
|
|
27
|
+
]);
|
|
28
|
+
|
|
@@ -5,7 +5,6 @@ import {hasAssign} from './has.js';
|
|
|
5
5
|
const {
|
|
6
6
|
isObjectExpression,
|
|
7
7
|
isAssignmentPattern,
|
|
8
|
-
isForOfStatement,
|
|
9
8
|
isFunction,
|
|
10
9
|
isVariableDeclarator,
|
|
11
10
|
isObjectProperty,
|
|
@@ -38,16 +37,6 @@ export const isCoupleProperties = ({path, valuePath, property}) => {
|
|
|
38
37
|
return !isObjectProperty(parentPath);
|
|
39
38
|
};
|
|
40
39
|
|
|
41
|
-
export function isInsideForOf({parentPath}) {
|
|
42
|
-
return isForOfStatement(parentPath.parentPath.parentPath);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
export function isPrevAssign(path) {
|
|
46
|
-
const prev = path.getPrevSibling();
|
|
47
|
-
|
|
48
|
-
return isAssignmentPattern(prev.node.value);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
40
|
export function isPrevAssignObject(path) {
|
|
52
41
|
const prev = path.getPrevSibling();
|
|
53
42
|
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {types} from '@putout/babel';
|
|
2
1
|
import {wrongShorthand} from './wrong-shorthand.js';
|
|
3
2
|
import {maybeTypeAnnotation} from '../../maybe/maybe-type-annotation.js';
|
|
4
3
|
import {printKey} from '../object-expression/print-key.js';
|
|
@@ -12,18 +11,15 @@ import {
|
|
|
12
11
|
hasAssignObject,
|
|
13
12
|
hasObjectPattern,
|
|
14
13
|
} from './has.js';
|
|
14
|
+
import {isCommaAfterProperty} from './comma.js';
|
|
15
15
|
import {
|
|
16
16
|
isCoupleProperties,
|
|
17
17
|
isIndent,
|
|
18
18
|
isInsideFn,
|
|
19
|
-
isInsideForOf,
|
|
20
19
|
isNextAssignObject,
|
|
21
|
-
isPrevAssign,
|
|
22
20
|
isPrevAssignObject,
|
|
23
21
|
} from './is.js';
|
|
24
22
|
|
|
25
|
-
const {isObjectExpression} = types;
|
|
26
|
-
|
|
27
23
|
export const ObjectPattern = {
|
|
28
24
|
print: maybeTypeAnnotation((path, printer, semantics) => {
|
|
29
25
|
const shouldIndent = isIndent(path);
|
|
@@ -97,12 +93,7 @@ export const ObjectPattern = {
|
|
|
97
93
|
} else if (isAssign) {
|
|
98
94
|
print(valuePath);
|
|
99
95
|
|
|
100
|
-
|
|
101
|
-
maybe.print.newline(couple);
|
|
102
|
-
|
|
103
|
-
const {right} = valuePath.node;
|
|
104
|
-
|
|
105
|
-
if (i && !isPrevAssign(property) && !isInsideForOf(path) && isObjectExpression(right)) {
|
|
96
|
+
if (isCommaAfterProperty(property, {couple})) {
|
|
106
97
|
print(',');
|
|
107
98
|
print.newline();
|
|
108
99
|
continue;
|
|
@@ -137,3 +128,4 @@ export const ObjectPattern = {
|
|
|
137
128
|
print('}');
|
|
138
129
|
}),
|
|
139
130
|
};
|
|
131
|
+
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
2
|
import {createTypeChecker} from '#type-checker';
|
|
3
|
-
import {isLooksLikeChain} from '../../expressions/member-expression/is-looks-like-chain.js';
|
|
3
|
+
import {isLooksLikeChain} from '../../expressions/member-expression/is-looks-like-chain/index.js';
|
|
4
4
|
|
|
5
5
|
const {isCallExpression} = types;
|
|
6
6
|
|
package/package.json
CHANGED