Skip to content
Permalink
Browse files

fix(scope-manager): correct analysis of abstract class properties (#2420

)
  • Loading branch information
bradzacher committed Aug 29, 2020
1 parent 3a7ec9b commit cd84549beba3cf471d75cfd9ba26f80366842ed5
@@ -757,6 +757,14 @@ export default function (@Optional() value = []) {
function Optional() {
return () => {};
}
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/2417
`
import { FooType } from './fileA';
export abstract class Foo {
protected abstract readonly type: FooType;
}
`,
],
@@ -139,6 +139,13 @@ class Referencer extends Visitor {
this.close(node);
}

protected visitClassProperty(
node: TSESTree.TSAbstractClassProperty | TSESTree.ClassProperty,
): void {
this.visitProperty(node);
this.visitType(node.typeAnnotation);
}

protected visitForIn(
node: TSESTree.ForInStatement | TSESTree.ForOfStatement,
): void {
@@ -413,8 +420,7 @@ class Referencer extends Visitor {
}

protected ClassProperty(node: TSESTree.ClassProperty): void {
this.visitProperty(node);
this.visitType(node.typeAnnotation);
this.visitClassProperty(node);
}

protected ContinueStatement(): void {
@@ -562,7 +568,7 @@ class Referencer extends Visitor {
protected TSAbstractClassProperty(
node: TSESTree.TSAbstractClassProperty,
): void {
this.visitProperty(node);
this.visitClassProperty(node);
}

protected TSAbstractMethodDefinition(
@@ -0,0 +1,5 @@
type T = 1;

abstract class Foo {
protected abstract readonly prop: T;
}
@@ -0,0 +1,85 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`class declaration abstract-property 1`] = `
ScopeManager {
variables: Array [
Variable$1 {
defs: Array [
TypeDefinition$1 {
name: Identifier<"T">,
node: TSTypeAliasDeclaration$1,
},
],
name: "T",
references: Array [
Reference$1 {
identifier: Identifier<"T">,
isRead: true,
isTypeReference: true,
isValueReference: false,
isWrite: false,
resolved: Variable$1,
},
],
isValueVariable: false,
isTypeVariable: true,
},
Variable$2 {
defs: Array [
ClassNameDefinition$2 {
name: Identifier<"Foo">,
node: ClassDeclaration$2,
},
],
name: "Foo",
references: Array [],
isValueVariable: true,
isTypeVariable: true,
},
Variable$3 {
defs: Array [
ClassNameDefinition$3 {
name: Identifier<"Foo">,
node: ClassDeclaration$2,
},
],
name: "Foo",
references: Array [],
isValueVariable: true,
isTypeVariable: true,
},
],
scopes: Array [
GlobalScope$1 {
block: Program$3,
isStrict: false,
references: Array [],
set: Map {
"T" => Variable$1,
"Foo" => Variable$2,
},
type: "global",
upper: null,
variables: Array [
Variable$1,
Variable$2,
],
},
ClassScope$2 {
block: ClassDeclaration$2,
isStrict: true,
references: Array [
Reference$1,
],
set: Map {
"Foo" => Variable$3,
},
type: "class",
upper: GlobalScope$1,
variables: Array [
Variable$3,
],
},
],
}
`;

0 comments on commit cd84549

Please sign in to comment.