Support private properties in no-invalid-this (babel/eslint-plugin-babel#183)

* add failing test

* support ClassPrivateProperty
This commit is contained in:
fergald 2019-08-24 17:12:15 +09:00
parent 693fa1aa0d
commit f3e2752df3
2 changed files with 19 additions and 3 deletions

View File

@ -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;
}

View File

@ -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();