Skip to content

Commit a2686c0

Browse files
authored
fix(scope-manager): support tagged template string generic type parameters (#2492)
1 parent 9d8b4c4 commit a2686c0

File tree

4 files changed

+166
-0
lines changed

4 files changed

+166
-0
lines changed

Diff for: packages/eslint-plugin/tests/rules/no-unused-vars.test.ts

+8
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,14 @@ export type F<A extends unknown[]> = (...a: A) => unknown;
775775
import { Foo } from './bar';
776776
export type F<A extends unknown[]> = (...a: Foo<A>) => unknown;
777777
`,
778+
// https://github.com/typescript-eslint/typescript-eslint/issues/2452
779+
`
780+
type StyledPaymentProps = {
781+
isValid: boolean;
782+
};
783+
784+
export const StyledPayment = styled.div<StyledPaymentProps>\`\`;
785+
`,
778786
],
779787

780788
invalid: [

Diff for: packages/scope-manager/src/referencer/Referencer.ts

+8
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,14 @@ class Referencer extends Visitor {
565565
this.close(node);
566566
}
567567

568+
protected TaggedTemplateExpression(
569+
node: TSESTree.TaggedTemplateExpression,
570+
): void {
571+
this.visit(node.tag);
572+
this.visit(node.quasi);
573+
this.visitType(node.typeParameters);
574+
}
575+
568576
protected TSAbstractClassProperty(
569577
node: TSESTree.TSAbstractClassProperty,
570578
): void {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
type StyledPaymentProps = {
2+
isValid: boolean;
3+
};
4+
function div<T>(arg: any): void {}
5+
6+
const StyledPayment = div<StyledPaymentProps>``;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`type-declaration type-parameters tagged-template 1`] = `
4+
ScopeManager {
5+
variables: Array [
6+
Variable$1 {
7+
defs: Array [
8+
TypeDefinition$1 {
9+
name: Identifier<"StyledPaymentProps">,
10+
node: TSTypeAliasDeclaration$1,
11+
},
12+
],
13+
name: "StyledPaymentProps",
14+
references: Array [
15+
Reference$3 {
16+
identifier: Identifier<"StyledPaymentProps">,
17+
isRead: true,
18+
isTypeReference: true,
19+
isValueReference: false,
20+
isWrite: false,
21+
resolved: Variable$1,
22+
},
23+
],
24+
isValueVariable: false,
25+
isTypeVariable: true,
26+
},
27+
Variable$2 {
28+
defs: Array [
29+
FunctionNameDefinition$2 {
30+
name: Identifier<"div">,
31+
node: FunctionDeclaration$2,
32+
},
33+
],
34+
name: "div",
35+
references: Array [
36+
Reference$2 {
37+
identifier: Identifier<"div">,
38+
isRead: true,
39+
isTypeReference: false,
40+
isValueReference: true,
41+
isWrite: false,
42+
resolved: Variable$2,
43+
},
44+
],
45+
isValueVariable: true,
46+
isTypeVariable: false,
47+
},
48+
Variable$3 {
49+
defs: Array [],
50+
name: "arguments",
51+
references: Array [],
52+
isValueVariable: true,
53+
isTypeVariable: true,
54+
},
55+
Variable$4 {
56+
defs: Array [
57+
ParameterDefinition$3 {
58+
name: Identifier<"arg">,
59+
node: FunctionDeclaration$2,
60+
},
61+
],
62+
name: "arg",
63+
references: Array [],
64+
isValueVariable: true,
65+
isTypeVariable: false,
66+
},
67+
Variable$5 {
68+
defs: Array [
69+
TypeDefinition$4 {
70+
name: Identifier<"T">,
71+
node: TSTypeParameter$3,
72+
},
73+
],
74+
name: "T",
75+
references: Array [],
76+
isValueVariable: false,
77+
isTypeVariable: true,
78+
},
79+
Variable$6 {
80+
defs: Array [
81+
VariableDefinition$5 {
82+
name: Identifier<"StyledPayment">,
83+
node: VariableDeclarator$4,
84+
},
85+
],
86+
name: "StyledPayment",
87+
references: Array [
88+
Reference$1 {
89+
identifier: Identifier<"StyledPayment">,
90+
init: true,
91+
isRead: false,
92+
isTypeReference: false,
93+
isValueReference: true,
94+
isWrite: true,
95+
resolved: Variable$6,
96+
writeExpr: TaggedTemplateExpression$5,
97+
},
98+
],
99+
isValueVariable: true,
100+
isTypeVariable: false,
101+
},
102+
],
103+
scopes: Array [
104+
GlobalScope$1 {
105+
block: Program$6,
106+
isStrict: false,
107+
references: Array [
108+
Reference$1,
109+
Reference$2,
110+
Reference$3,
111+
],
112+
set: Map {
113+
"StyledPaymentProps" => Variable$1,
114+
"div" => Variable$2,
115+
"StyledPayment" => Variable$6,
116+
},
117+
type: "global",
118+
upper: null,
119+
variables: Array [
120+
Variable$1,
121+
Variable$2,
122+
Variable$6,
123+
],
124+
},
125+
FunctionScope$2 {
126+
block: FunctionDeclaration$2,
127+
isStrict: false,
128+
references: Array [],
129+
set: Map {
130+
"arguments" => Variable$3,
131+
"arg" => Variable$4,
132+
"T" => Variable$5,
133+
},
134+
type: "function",
135+
upper: GlobalScope$1,
136+
variables: Array [
137+
Variable$3,
138+
Variable$4,
139+
Variable$5,
140+
],
141+
},
142+
],
143+
}
144+
`;

0 commit comments

Comments
 (0)