Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(scope-manager): fix visiting of TSImportType #3008

Merged
merged 1 commit into from Feb 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
],
},
],
}
`;