-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
76 lines (60 loc) · 1.71 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
export default function transformer(file, api) {
const j = api.jscodeshift;
const f = j(file.source);
let createArrayTypeAnnotation = () => {
return j.genericTypeAnnotation(
j.identifier('Array'),
j.typeParameterInstantiation([
j.anyTypeAnnotation()
])
);
};
let createNodeTypeAnnotation = () => {
};
let createElementTypeAnnotation = () => {
};
let conversions = {
any : () => j.anyTypeAnnotation(),
number : () => j.numberTypeAnnotation(),
string : () => j.stringTypeAnnotation(),
bool : () => j.booleanTypeAnnotation(),
func : () => j.identifier('Function'),
object : () => j.identifier('Object'),
symbol : () => false,
array : () => createArrayTypeAnnotation(),
node : () => createNodeTypeAnnotation(),
element : () => createElementTypeAnnotation(),
instanceOf: () => {},
oneOf: () => {},
oneOfType: () => {},
arrayOf: () => {},
objectOf: () => {},
shape: () => {},
};
let isReact = node => {
return node.type === 'Identifier' && node.name === 'React';
};
let resolvePropType = node => {
let prop = node.property;
let name = prop.name;
let conversion = conversions[name];
let result = conversion(prop);
return result;
};
let propTypes = f.find(j.ClassProperty, node => {
return (
node.static &&
!node.computed &&
node.key.name === 'propTypes' &&
node.value.type === 'ObjectExpression'
);
});
propTypes.forEach(propType => {
let obj = {};
propType.node.value.properties.forEach(property => {
obj[property.key.name] = resolvePropType(property.value);
});
console.log(obj);
});
return f.toSource();
}