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): support tagged template string generic type parameters #2492

Merged
merged 3 commits into from Sep 5, 2020
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
8 changes: 8 additions & 0 deletions packages/eslint-plugin/tests/rules/no-unused-vars.test.ts
Expand Up @@ -775,6 +775,14 @@ export type F<A extends unknown[]> = (...a: A) => unknown;
import { Foo } from './bar';
export type F<A extends unknown[]> = (...a: Foo<A>) => unknown;
`,
// https://github.com/typescript-eslint/typescript-eslint/issues/2452
`
type StyledPaymentProps = {
isValid: boolean;
};

export const StyledPayment = styled.div<StyledPaymentProps>\`\`;
`,
],

invalid: [
Expand Down
8 changes: 8 additions & 0 deletions packages/scope-manager/src/referencer/Referencer.ts
Expand Up @@ -565,6 +565,14 @@ class Referencer extends Visitor {
this.close(node);
}

protected TaggedTemplateExpression(
node: TSESTree.TaggedTemplateExpression,
): void {
this.visit(node.tag);
this.visit(node.quasi);
this.visitType(node.typeParameters);
}

protected TSAbstractClassProperty(
node: TSESTree.TSAbstractClassProperty,
): void {
Expand Down
@@ -0,0 +1,6 @@
type StyledPaymentProps = {
isValid: boolean;
};
function div<T>(arg: any): void {}

const StyledPayment = div<StyledPaymentProps>``;
@@ -0,0 +1,144 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`type-declaration type-parameters tagged-template 1`] = `
ScopeManager {
variables: Array [
Variable$1 {
defs: Array [
TypeDefinition$1 {
name: Identifier<"StyledPaymentProps">,
node: TSTypeAliasDeclaration$1,
},
],
name: "StyledPaymentProps",
references: Array [
Reference$3 {
identifier: Identifier<"StyledPaymentProps">,
isRead: true,
isTypeReference: true,
isValueReference: false,
isWrite: false,
resolved: Variable$1,
},
],
isValueVariable: false,
isTypeVariable: true,
},
Variable$2 {
defs: Array [
FunctionNameDefinition$2 {
name: Identifier<"div">,
node: FunctionDeclaration$2,
},
],
name: "div",
references: Array [
Reference$2 {
identifier: Identifier<"div">,
isRead: true,
isTypeReference: false,
isValueReference: true,
isWrite: false,
resolved: Variable$2,
},
],
isValueVariable: true,
isTypeVariable: false,
},
Variable$3 {
defs: Array [],
name: "arguments",
references: Array [],
isValueVariable: true,
isTypeVariable: true,
},
Variable$4 {
defs: Array [
ParameterDefinition$3 {
name: Identifier<"arg">,
node: FunctionDeclaration$2,
},
],
name: "arg",
references: Array [],
isValueVariable: true,
isTypeVariable: false,
},
Variable$5 {
defs: Array [
TypeDefinition$4 {
name: Identifier<"T">,
node: TSTypeParameter$3,
},
],
name: "T",
references: Array [],
isValueVariable: false,
isTypeVariable: true,
},
Variable$6 {
defs: Array [
VariableDefinition$5 {
name: Identifier<"StyledPayment">,
node: VariableDeclarator$4,
},
],
name: "StyledPayment",
references: Array [
Reference$1 {
identifier: Identifier<"StyledPayment">,
init: true,
isRead: false,
isTypeReference: false,
isValueReference: true,
isWrite: true,
resolved: Variable$6,
writeExpr: TaggedTemplateExpression$5,
},
],
isValueVariable: true,
isTypeVariable: false,
},
],
scopes: Array [
GlobalScope$1 {
block: Program$6,
isStrict: false,
references: Array [
Reference$1,
Reference$2,
Reference$3,
],
set: Map {
"StyledPaymentProps" => Variable$1,
"div" => Variable$2,
"StyledPayment" => Variable$6,
},
type: "global",
upper: null,
variables: Array [
Variable$1,
Variable$2,
Variable$6,
],
},
FunctionScope$2 {
block: FunctionDeclaration$2,
isStrict: false,
references: Array [],
set: Map {
"arguments" => Variable$3,
"arg" => Variable$4,
"T" => Variable$5,
},
type: "function",
upper: GlobalScope$1,
variables: Array [
Variable$3,
Variable$4,
Variable$5,
],
},
],
}
`;