Debian Codegraph @

eslint/babel-eslint-plugin/src/rules/no-invalid-this.cjs

raw symbols SCIP
1 const ruleComposer = require("eslint-rule-composer");
2 const eslint = require("eslint");
3 const eslintVersion = eslint.ESLint.version;
4
5 const noInvalidThisRule = new eslint.Linter().getRules().get("no-invalid-this");
6
7 if (parseInt(eslintVersion, 10) >= 8) {
8 // ESLint 8 supports class properties / private methods natively
9 // so we simply forward the original rule
10 module.exports = noInvalidThisRule;
11 } else {
12 module.exports = ruleComposer.filterReports(noInvalidThisRule, problem => {
13 let inClassMember = false;
14 let node = problem.node;
15
16 while (node) {
17 if (
18 node.type === "ClassPrivateMethod" ||
19 node.type === "ClassPrivateProperty" ||
20 node.type === "ClassProperty" ||
21 node.type === "PropertyDefinition" ||
22 (node.type === "MethodDefinition" &&
23 node.key.type === "PrivateIdentifier")
24 ) {
25 inClassMember = true;
26 break;
27 } else if (
28 node.type === "FunctionDeclaration" ||
29 node.type === "FunctionExpression"
30 ) {
31 inClassMember = false;
32 break;
33 }
34
35 node = node.parent;
36 }
37
38 return !inClassMember;
39 });
40 }