Umama-at-Bluchip/Quick-UI
0
1/**2 * @fileoverview Rule to flag variable leak in CatchClauses in IE 8 and earlier3 * @author Ian Christian Myers4 * @deprecated in ESLint v5.1.05 */6 7"use strict";8 9//------------------------------------------------------------------------------10// Requirements11//------------------------------------------------------------------------------12 13const astUtils = require("./utils/ast-utils");14 15//------------------------------------------------------------------------------16// Rule Definition17//------------------------------------------------------------------------------18 19/** @type {import('../shared/types').Rule} */20module.exports = {21 meta: {22 type: "suggestion",23 24 docs: {25 description: "Disallow `catch` clause parameters from shadowing variables in the outer scope",26 recommended: false,27 url: "https://eslint.org/docs/latest/rules/no-catch-shadow"28 },29 30 replacedBy: ["no-shadow"],31 32 deprecated: true,33 schema: [],34 35 messages: {36 mutable: "Value of '{{name}}' may be overwritten in IE 8 and earlier."37 }38 },39 40 create(context) {41 42 const sourceCode = context.sourceCode;43 44 //--------------------------------------------------------------------------45 // Helpers46 //--------------------------------------------------------------------------47 48 /**49 * Check if the parameters are been shadowed50 * @param {Object} scope current scope51 * @param {string} name parameter name52 * @returns {boolean} True is its been shadowed53 */54 function paramIsShadowing(scope, name) {55 return astUtils.getVariableByName(scope, name) !== null;56 }57 58 //--------------------------------------------------------------------------59 // Public API60 //--------------------------------------------------------------------------61 62 return {63 64 "CatchClause[param!=null]"(node) {65 let scope = sourceCode.getScope(node);66 67 /*68 * When ecmaVersion >= 6, CatchClause creates its own scope69 * so start from one upper scope to exclude the current node70 */71 if (scope.block === node) {72 scope = scope.upper;73 }74 75 if (paramIsShadowing(scope, node.param.name)) {76 context.report({ node, messageId: "mutable", data: { name: node.param.name } });77 }78 }79 };80 81 }82};83 