-
Notifications
You must be signed in to change notification settings - Fork 11
/
defineFlowType.js
81 lines (74 loc) · 1.88 KB
/
defineFlowType.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
77
78
79
80
81
const schema = [];
const create = (context) => {
let globalScope;
const makeDefined = (variableName) => {
// Add the variable to the global scope
globalScope.through = globalScope.through.filter((ref) => {
if (ref.identifier.name === variableName) {
return false;
}
return true;
});
};
// NOTE: For future contributors, if you ever need to add support for a new identifier,
// use `Identifier(node) {}` to find out which identifiers should be handled.
return {
ClassImplements(node) {
makeDefined(node.id.name);
},
DeclareInterface(node) {
makeDefined(node.id.name);
},
DeclareTypeAlias(node) {
makeDefined(node.id.name);
},
EnumDeclaration(node) {
makeDefined(node.id.name);
},
EnumDefaultedMember(node) {
makeDefined(node.id.name);
},
EnumNumberMember(node) {
makeDefined(node.id.name);
},
EnumStringMember(node) {
makeDefined(node.id.name);
},
GenericTypeAnnotation(node) {
if (node.id.type === 'Identifier') {
makeDefined(node.id.name);
} else if (node.id.type === 'QualifiedTypeIdentifier') {
let qid;
qid = node.id;
while (qid.qualification) {
qid = qid.qualification;
}
makeDefined(qid.name);
}
},
// Can be removed once https://github.com/babel/babel-eslint/pull/696 is published
OpaqueType(node) {
if (node.id.type === 'Identifier') {
makeDefined(node.id.name);
}
},
Program(node) {
if (context.sourceCode?.getScope) {
globalScope = context.sourceCode.getScope(node);
} else {
globalScope = context.getScope();
}
},
TypeParameterDeclaration(node) {
for (const param of node.params) {
makeDefined(param.name);
}
},
};
};
export default {
create,
meta: {
schema,
},
};