Skip to content

Commit

Permalink
fix(scope-manager): fix visiting of TSImportType (#3008)
Browse files Browse the repository at this point in the history
Fixes #3006
  • Loading branch information
bradzacher committed Feb 6, 2021
1 parent 3cb3aad commit ce4fcbf
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/eslint-plugin/tests/eslint-rules/no-undef.test.ts
Expand Up @@ -235,6 +235,10 @@ declare function deco(...param: any): (...param: any) => any;
})
class Foo {}
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/3006
`
export type AppState = typeof import('./src/store/reducers').default;
`,
],
invalid: [
{
Expand Down
6 changes: 6 additions & 0 deletions packages/scope-manager/src/referencer/TypeVisitor.ts
Expand Up @@ -116,6 +116,12 @@ class TypeVisitor extends Visitor {
this.visitFunctionType(node);
}

protected TSImportType(node: TSESTree.TSImportType): void {
// the TS parser allows any type to be the parameter, but it's a syntax error - so we can ignore it
this.visit(node.typeParameters);
// the qualifier is just part of a standard EntityName, so it should not be visited
}

protected TSIndexSignature(node: TSESTree.TSIndexSignature): void {
for (const param of node.parameters) {
if (param.type === AST_NODE_TYPES.Identifier) {
Expand Down
@@ -0,0 +1 @@
type T = import('').default;
@@ -0,0 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`type-declaration import-type-with-qualifier 1`] = `
ScopeManager {
variables: Array [
ImplicitGlobalConstTypeVariable,
Variable$2 {
defs: Array [
TypeDefinition$1 {
name: Identifier<"T">,
node: TSTypeAliasDeclaration$1,
},
],
name: "T",
references: Array [],
isValueVariable: false,
isTypeVariable: true,
},
],
scopes: Array [
GlobalScope$1 {
block: Program$2,
isStrict: false,
references: Array [],
set: Map {
"const" => ImplicitGlobalConstTypeVariable,
"T" => Variable$2,
},
type: "global",
upper: null,
variables: Array [
ImplicitGlobalConstTypeVariable,
Variable$2,
],
},
],
}
`;
@@ -0,0 +1,2 @@
type Param = string;
type T = import('').foo<Param>;
@@ -0,0 +1,63 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`type-declaration import-type-with-type-params 1`] = `
ScopeManager {
variables: Array [
ImplicitGlobalConstTypeVariable,
Variable$2 {
defs: Array [
TypeDefinition$1 {
name: Identifier<"Param">,
node: TSTypeAliasDeclaration$1,
},
],
name: "Param",
references: Array [
Reference$1 {
identifier: Identifier<"Param">,
isRead: true,
isTypeReference: true,
isValueReference: false,
isWrite: false,
resolved: Variable$2,
},
],
isValueVariable: false,
isTypeVariable: true,
},
Variable$3 {
defs: Array [
TypeDefinition$2 {
name: Identifier<"T">,
node: TSTypeAliasDeclaration$2,
},
],
name: "T",
references: Array [],
isValueVariable: false,
isTypeVariable: true,
},
],
scopes: Array [
GlobalScope$1 {
block: Program$3,
isStrict: false,
references: Array [
Reference$1,
],
set: Map {
"const" => ImplicitGlobalConstTypeVariable,
"Param" => Variable$2,
"T" => Variable$3,
},
type: "global",
upper: null,
variables: Array [
ImplicitGlobalConstTypeVariable,
Variable$2,
Variable$3,
],
},
],
}
`;
@@ -0,0 +1 @@
type T = import('');
@@ -0,0 +1,38 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`type-declaration import-type 1`] = `
ScopeManager {
variables: Array [
ImplicitGlobalConstTypeVariable,
Variable$2 {
defs: Array [
TypeDefinition$1 {
name: Identifier<"T">,
node: TSTypeAliasDeclaration$1,
},
],
name: "T",
references: Array [],
isValueVariable: false,
isTypeVariable: true,
},
],
scopes: Array [
GlobalScope$1 {
block: Program$2,
isStrict: false,
references: Array [],
set: Map {
"const" => ImplicitGlobalConstTypeVariable,
"T" => Variable$2,
},
type: "global",
upper: null,
variables: Array [
ImplicitGlobalConstTypeVariable,
Variable$2,
],
},
],
}
`;

0 comments on commit ce4fcbf

Please sign in to comment.