1 | /**
|
2 | * @fileoverview Rule to flag variable leak in CatchClauses in IE 8 and earlier
|
3 | * @author Ian Christian Myers
|
4 | */
|
5 |
|
6 | //------------------------------------------------------------------------------
|
7 | // Rule Definition
|
8 | //------------------------------------------------------------------------------
|
9 |
|
10 | module.exports = function(context) {
|
11 |
|
12 | ;
|
13 |
|
14 | //--------------------------------------------------------------------------
|
15 | // Helpers
|
16 | //--------------------------------------------------------------------------
|
17 |
|
18 | function paramIsShadowing(scope, name) {
|
19 | var found = scope.variables.some(function(variable) {
|
20 | return variable.name === name;
|
21 | });
|
22 |
|
23 | if (found) {
|
24 | return true;
|
25 | }
|
26 |
|
27 | if (scope.upper) {
|
28 | return paramIsShadowing(scope.upper, name);
|
29 | }
|
30 |
|
31 | return false;
|
32 | }
|
33 |
|
34 | //--------------------------------------------------------------------------
|
35 | // Public API
|
36 | //--------------------------------------------------------------------------
|
37 |
|
38 | return {
|
39 |
|
40 | "CatchClause": function(node) {
|
41 | var scope = context.getScope();
|
42 |
|
43 | if (paramIsShadowing(scope, node.param.name)) {
|
44 | context.report(node, "Value of '{{name}}' may be overwritten in IE 8 and earlier.",
|
45 | { name: node.param.name });
|
46 | }
|
47 | }
|
48 | };
|
49 |
|
50 | };
|