fix: do not filter report from functions within class elements (#13106)

This commit is contained in:
Huáng Jùnliàng 2021-04-05 16:02:02 -04:00 committed by GitHub
parent 61e866f6b8
commit 7bc72bb451
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 55 additions and 1 deletions

View File

@ -17,7 +17,13 @@ export default ruleComposer.filterReports(noInvalidThisRule, problem => {
node.key.type === "PrivateIdentifier") node.key.type === "PrivateIdentifier")
) { ) {
inClassMember = true; inClassMember = true;
return; break;
} else if (
node.type === "FunctionDeclaration" ||
node.type === "FunctionExpression"
) {
inClassMember = false;
break;
} }
node = node.parent; node = node.parent;

View File

@ -93,6 +93,30 @@ const patterns = [
invalid: [], 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 // Class Private methods
{ {
code: "class A {#a = this.b;};", code: "class A {#a = this.b;};",
@ -108,6 +132,30 @@ const patterns = [
invalid: [], 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;};};", code: "class A {#a() {return this.b;};};",
parserOptions: { ecmaVersion: 6 }, parserOptions: { ecmaVersion: 6 },