Skip to content

Commit

Permalink
feat: visit class property type annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
bradzacher committed May 18, 2020
1 parent 3196762 commit 74d7b08
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/scope-manager/src/referencer/Referencer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,6 @@ class Referencer extends Visitor {
}

const isMethodDefinition = node.type === AST_NODE_TYPES.MethodDefinition;

if (isMethodDefinition) {
previous = this.pushInnerMethodDefinition(true);
}
Expand Down Expand Up @@ -395,6 +394,7 @@ class Referencer extends Visitor {

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

protected ContinueStatement(): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
type T = 1;
class A {
prop: T;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`class declaration properties-type-annotation 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">,
isTypeReference: true,
resolved: Variable$1,
},
],
isValueVariable: false,
isTypeVariable: true,
},
Variable$2 {
defs: Array [
ClassNameDefinition$2 {
name: Identifier<"A">,
node: ClassDeclaration$2,
},
],
name: "A",
references: Array [],
isValueVariable: true,
isTypeVariable: true,
},
Variable$3 {
defs: Array [
ClassNameDefinition$3 {
name: Identifier<"A">,
node: ClassDeclaration$2,
},
],
name: "A",
references: Array [],
isValueVariable: true,
isTypeVariable: true,
},
],
scopes: Array [
GlobalScope$1 {
block: Program$3,
isStrict: false,
references: Array [],
set: Map {
"T" => Variable$1,
"A" => 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 {
"A" => Variable$3,
},
type: "class",
upper: GlobalScope$1,
variables: Array [
Variable$3,
],
},
],
}
`;

0 comments on commit 74d7b08

Please sign in to comment.