From 1d10ab66b1f15bbc273ca0c8467cb05e5d9e7b00 Mon Sep 17 00:00:00 2001 From: fergald Date: Sat, 24 Aug 2019 17:12:15 +0900 Subject: [PATCH] Support private properties in no-invalid-this (#183) * add failing test * support ClassPrivateProperty --- rules/no-invalid-this.js | 7 ++++--- tests/rules/no-invalid-this.js | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/rules/no-invalid-this.js b/rules/no-invalid-this.js index ab12ca5..994499e 100644 --- a/rules/no-invalid-this.js +++ b/rules/no-invalid-this.js @@ -5,17 +5,18 @@ const eslint = require('eslint'); const noInvalidThisRule = new eslint.Linter().getRules().get('no-invalid-this'); module.exports = ruleComposer.filterReports( - noInvalidThisRule, + noInvalidThisRule, (problem, metadata) => { let inClassProperty = false; let node = problem.node; while (node) { - if (node.type === "ClassProperty") { + if (node.type === "ClassProperty" || + node.type === "ClassPrivateProperty") { inClassProperty = true; return; } - + node = node.parent; } diff --git a/tests/rules/no-invalid-this.js b/tests/rules/no-invalid-this.js index 3ab5da5..e28c77a 100644 --- a/tests/rules/no-invalid-this.js +++ b/tests/rules/no-invalid-this.js @@ -602,6 +602,21 @@ const patterns = [ valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], invalid: [] }, + + // Class Private Instance Properties. + { + code: "class A {#a = this.b;};", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [] + }, + + { + code: "class A {#a = () => {return this.b;};};", + parserOptions: { ecmaVersion: 6 }, + valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], + invalid: [] + }, ]; const ruleTester = new RuleTester();