@putout/printer 18.37.1 → 18.37.2
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
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {types} from '@putout/babel';
|
|
2
|
+
import {createTypeChecker} from '#type-checker';
|
|
2
3
|
import {hasTrailingComment} from '#is';
|
|
3
4
|
|
|
4
5
|
const {
|
|
@@ -8,21 +9,13 @@ const {
|
|
|
8
9
|
|
|
9
10
|
const {assign} = Object;
|
|
10
11
|
|
|
11
|
-
const isCallee = (call, member) => {
|
|
12
|
-
if (!isCallExpression(call))
|
|
13
|
-
return false;
|
|
14
|
-
|
|
15
|
-
return call.node.callee === member.node;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
12
|
export const chain = (path) => {
|
|
19
|
-
const
|
|
13
|
+
const properties = [
|
|
20
14
|
...down(path),
|
|
21
15
|
...up(path),
|
|
22
16
|
];
|
|
23
17
|
|
|
24
|
-
const
|
|
25
|
-
const root = all.at(-1);
|
|
18
|
+
const root = properties.pop();
|
|
26
19
|
|
|
27
20
|
return [root, properties];
|
|
28
21
|
};
|
|
@@ -33,13 +26,8 @@ function down(path) {
|
|
|
33
26
|
let current = path.get('object');
|
|
34
27
|
|
|
35
28
|
while (!current.isIdentifier()) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
if (isFn)
|
|
40
|
-
current = current.get('callee');
|
|
41
|
-
|
|
42
|
-
properties.unshift(prop);
|
|
29
|
+
properties.unshift(buildProperty(current));
|
|
30
|
+
current = stepIntoCallee(current);
|
|
43
31
|
|
|
44
32
|
if (!current.isMemberExpression())
|
|
45
33
|
break;
|
|
@@ -50,38 +38,54 @@ function down(path) {
|
|
|
50
38
|
return properties;
|
|
51
39
|
}
|
|
52
40
|
|
|
41
|
+
function stepIntoCallee(current) {
|
|
42
|
+
if (current.isCallExpression())
|
|
43
|
+
return current.get('callee');
|
|
44
|
+
|
|
45
|
+
return current;
|
|
46
|
+
}
|
|
47
|
+
|
|
53
48
|
function up(current) {
|
|
54
49
|
const properties = [];
|
|
55
50
|
|
|
56
51
|
while (current.isMemberExpression()) {
|
|
57
52
|
if (hasTrailingComment(current.get('object')))
|
|
58
|
-
properties.push(
|
|
59
|
-
type: 'CommentLine',
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
const member = current;
|
|
63
|
-
current = current.parentPath;
|
|
53
|
+
properties.push(commentProperty());
|
|
64
54
|
|
|
65
|
-
|
|
66
|
-
properties.push(build(current));
|
|
67
|
-
current = current.parentPath;
|
|
68
|
-
}
|
|
55
|
+
current = stepOutOfChain(current, properties);
|
|
69
56
|
|
|
70
57
|
if (!isMemberExpression(current))
|
|
71
58
|
break;
|
|
72
59
|
}
|
|
73
60
|
|
|
74
|
-
properties.push(
|
|
75
|
-
type: current.type,
|
|
76
|
-
});
|
|
61
|
+
properties.push(rootProperty(current));
|
|
77
62
|
|
|
78
63
|
return properties;
|
|
79
64
|
}
|
|
80
65
|
|
|
81
|
-
function
|
|
82
|
-
const
|
|
66
|
+
function stepOutOfChain(member, properties) {
|
|
67
|
+
const parent = member.parentPath;
|
|
68
|
+
|
|
69
|
+
if (!isMemberOwnCallee(member))
|
|
70
|
+
return parent;
|
|
71
|
+
|
|
72
|
+
properties.push(buildProperty(parent));
|
|
73
|
+
|
|
74
|
+
return parent.parentPath;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function isPathOwnCallee({node, parentPath}) {
|
|
78
|
+
return node === parentPath.node.callee;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
const isMemberOwnCallee = createTypeChecker([
|
|
82
|
+
['-: parentPath -> !CallExpression'],
|
|
83
|
+
['+', isPathOwnCallee],
|
|
84
|
+
]);
|
|
85
|
+
|
|
86
|
+
function buildProperty(path) {
|
|
83
87
|
const prop = {
|
|
84
|
-
type,
|
|
88
|
+
type: path.type,
|
|
85
89
|
};
|
|
86
90
|
|
|
87
91
|
if (isCallExpression(path)) {
|
|
@@ -100,3 +104,10 @@ function build(path) {
|
|
|
100
104
|
return prop;
|
|
101
105
|
}
|
|
102
106
|
|
|
107
|
+
const commentProperty = () => ({
|
|
108
|
+
type: 'CommentLine',
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const rootProperty = (path) => ({
|
|
112
|
+
type: path.type,
|
|
113
|
+
});
|
package/package.json
CHANGED