Skip to content

Commit

Permalink
fix: do not filter report from functions within class elements (#13106)
Browse files Browse the repository at this point in the history
  • Loading branch information
JLHwung committed Apr 5, 2021
1 parent 61e866f commit 7bc72bb
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
8 changes: 7 additions & 1 deletion eslint/babel-eslint-plugin/src/rules/no-invalid-this.js
Expand Up @@ -17,7 +17,13 @@ export default ruleComposer.filterReports(noInvalidThisRule, problem => {
node.key.type === "PrivateIdentifier")
) {
inClassMember = true;
return;
break;
} else if (
node.type === "FunctionDeclaration" ||
node.type === "FunctionExpression"
) {
inClassMember = false;
break;
}

node = node.parent;
Expand Down
48 changes: 48 additions & 0 deletions eslint/babel-eslint-plugin/test/rules/no-invalid-this.js
Expand Up @@ -93,6 +93,30 @@ const patterns = [
invalid: [],
},

{
code: "class A {a = () => { function b() { return this.b;} };};",
parserOptions: { ecmaVersion: 6 },
valid: [],
invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES],
errors: [
{
message: "Unexpected 'this'.",
},
],
},

{
code: "class A {a = () => { (function b() { return this.b;}); };};",
parserOptions: { ecmaVersion: 6 },
valid: [],
invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES],
errors: [
{
message: "Unexpected 'this'.",
},
],
},

// Class Private methods
{
code: "class A {#a = this.b;};",
Expand All @@ -108,6 +132,30 @@ const patterns = [
invalid: [],
},

{
code: "class A {#a = () => { function b() { return this.b;} };};",
parserOptions: { ecmaVersion: 6 },
valid: [],
invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES],
errors: [
{
message: "Unexpected 'this'.",
},
],
},

{
code: "class A {#a = () => { (function b() { return this.b;}); };};",
parserOptions: { ecmaVersion: 6 },
valid: [],
invalid: [NORMAL, USE_STRICT, IMPLIED_STRICT, MODULES],
errors: [
{
message: "Unexpected 'this'.",
},
],
},

{
code: "class A {#a() {return this.b;};};",
parserOptions: { ecmaVersion: 6 },
Expand Down

0 comments on commit 7bc72bb

Please sign in to comment.