Skip to content
This repository has been archived by the owner on Aug 4, 2020. It is now read-only.

Commit

Permalink
Support private properties in no-invalid-this (#183)
Browse files Browse the repository at this point in the history
* add failing test

* support ClassPrivateProperty
  • Loading branch information
fergald authored and nicolo-ribaudo committed Aug 24, 2019
1 parent 8409232 commit 1d10ab6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
7 changes: 4 additions & 3 deletions rules/no-invalid-this.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
15 changes: 15 additions & 0 deletions tests/rules/no-invalid-this.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 1d10ab6

Please sign in to comment.