2 * @fileoverview Rule to flag variable leak in CatchClauses in IE 8 and earlier
3 * @author Ian Christian Myers
4 * @deprecated in ESLint v5.1.0
9 //------------------------------------------------------------------------------
11 //------------------------------------------------------------------------------
13 const astUtils = require("./utils/ast-utils");
15 //------------------------------------------------------------------------------
17 //------------------------------------------------------------------------------
24 description: "disallow `catch` clause parameters from shadowing variables in the outer scope",
25 category: "Variables",
27 url: "https://eslint.org/docs/rules/no-catch-shadow"
30 replacedBy: ["no-shadow"],
36 mutable: "Value of '{{name}}' may be overwritten in IE 8 and earlier."
42 //--------------------------------------------------------------------------
44 //--------------------------------------------------------------------------
47 * Check if the parameters are been shadowed
48 * @param {Object} scope current scope
49 * @param {string} name parameter name
50 * @returns {boolean} True is its been shadowed
52 function paramIsShadowing(scope, name) {
53 return astUtils.getVariableByName(scope, name) !== null;
56 //--------------------------------------------------------------------------
58 //--------------------------------------------------------------------------
62 "CatchClause[param!=null]"(node) {
63 let scope = context.getScope();
66 * When ecmaVersion >= 6, CatchClause creates its own scope
67 * so start from one upper scope to exclude the current node
69 if (scope.block === node) {
73 if (paramIsShadowing(scope, node.param.name)) {
74 context.report({ node, messageId: "mutable", data: { name: node.param.name } });