1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 | "use strict";
|
11 |
|
12 | function markArrayElementsAsUsed(context, node, expression) {
|
13 | if (expression.type != "ArrayExpression") {
|
14 | context.report({
|
15 | node,
|
16 | message: "Unexpected assignment of non-Array to EXPORTED_SYMBOLS"
|
17 | });
|
18 | return;
|
19 | }
|
20 |
|
21 | for (let element of expression.elements) {
|
22 | context.markVariableAsUsed(element.value);
|
23 | }
|
24 |
|
25 | context.markVariableAsUsed("EXPORTED_SYMBOLS");
|
26 | }
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 | module.exports = function(context) {
|
33 |
|
34 |
|
35 |
|
36 | function isGlobalScope() {
|
37 | return !context.getScope().upper;
|
38 | }
|
39 |
|
40 |
|
41 |
|
42 |
|
43 |
|
44 | return {
|
45 | AssignmentExpression(node, parents) {
|
46 | if (node.operator === "=" &&
|
47 | node.left.type === "MemberExpression" &&
|
48 | node.left.object.type === "ThisExpression" &&
|
49 | node.left.property.name === "EXPORTED_SYMBOLS" &&
|
50 | isGlobalScope()) {
|
51 | markArrayElementsAsUsed(context, node, node.right);
|
52 | }
|
53 | },
|
54 |
|
55 | VariableDeclaration(node, parents) {
|
56 | if (!isGlobalScope()) {
|
57 | return;
|
58 | }
|
59 |
|
60 | for (let item of node.declarations) {
|
61 | if (item.id &&
|
62 | item.id.type == "Identifier" &&
|
63 | item.id.name === "EXPORTED_SYMBOLS") {
|
64 | if (node.kind === "let") {
|
65 |
|
66 |
|
67 | context.report({
|
68 | node,
|
69 | message: "EXPORTED_SYMBOLS cannot be declared via `let`. Use `var` or `this.EXPORTED_SYMBOLS =`"
|
70 | });
|
71 | }
|
72 |
|
73 | markArrayElementsAsUsed(context, node, item.init);
|
74 | }
|
75 | }
|
76 | }
|
77 | };
|
78 | };
|