UNPKG

2.06 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6var schema = exports.schema = [];
7
8exports.default = function (context) {
9 var globalScope = void 0;
10
11 // do nearly the same thing that eslint does for config globals
12 // https://github.com/eslint/eslint/blob/v2.0.0/lib/eslint.js#L118-L194
13 var makeDefined = function makeDefined(ident) {
14 var ii = void 0;
15
16 // start from the right since we're going to remove items from the array
17 for (ii = globalScope.through.length - 1; ii >= 0; ii--) {
18 var ref = globalScope.through[ii];
19
20 if (ref.identifier.name === ident.name) {
21 // use "__defineGeneric" since we don't have a reference to "escope.Variable"
22 globalScope.__defineGeneric( // eslint-disable-line no-underscore-dangle
23 ident.name, globalScope.set, globalScope.variables);
24 var variable = globalScope.set.get(ident.name);
25
26 variable.writeable = false;
27 // "through" contains all references whose definition cannot be found
28 // so we need to update references and remove the ones that were added
29 globalScope.through.splice(ii, 1);
30 ref.resolved = variable;
31 variable.references.push(ref);
32 }
33 }
34 };
35
36 return {
37 ClassImplements: function ClassImplements(node) {
38 makeDefined(node.id);
39 },
40 GenericTypeAnnotation: function GenericTypeAnnotation(node) {
41 if (node.id.type === 'Identifier') {
42 makeDefined(node.id);
43 } else if (node.id.type === 'QualifiedTypeIdentifier') {
44 var qid = void 0;
45
46 qid = node.id;
47 do {
48 qid = qid.qualification;
49 } while (qid.qualification);
50
51 makeDefined(qid);
52 }
53 },
54 InterfaceDeclaration: function InterfaceDeclaration(node) {
55 makeDefined(node.id);
56 },
57 Program: function Program() {
58 globalScope = context.getScope();
59 },
60 TypeParameterDeclaration: function TypeParameterDeclaration(node) {
61 node.params.forEach(function (param) {
62 makeDefined(param);
63 });
64 }
65 };
66};
\No newline at end of file