-
-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathindex.js
44 lines (34 loc) · 1.03 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import {operator} from 'putout';
const {remove} = operator;
const getNode = (a) => a.node;
export const report = () => `Merge variables`;
export const fix = ({path, vars}) => {
path.node.declarations = vars.map(getNode);
for (const path of vars.slice(1)) {
remove(path.parentPath);
}
};
export const traverse = ({push, uplist}) => ({
VariableDeclarator: (path) => {
if (path.parentPath.node.declarations.length !== 1)
return;
if (path.parentPath.node.kind === 'let')
return;
if (path.get('init').isAwaitExpression())
return;
uplist(path.scope.uid, path);
},
Program: {
exit() {
for (const vars of uplist()) {
if (vars.length < 2)
continue;
const [path] = vars;
push({
path: path.parentPath,
vars,
});
}
},
},
});