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

@ -11,7 +11,8 @@ module.exports = ruleComposer.filterReports(
let node = problem.node; let node = problem.node;
while (node) { while (node) {
if (node.type === "ClassProperty") { if (node.type === "ClassProperty" ||
node.type === "ClassPrivateProperty") {
inClassProperty = true; inClassProperty = true;
return; return;
} }

View File

@ -602,6 +602,21 @@ const patterns = [
valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES], valid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES],
invalid: [] 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(); const ruleTester = new RuleTester();