Skip to content

Commit 7c99c8f

Browse files
committed
Merge pull request #7622 from Microsoft/findAllReferencesForJSXTagNames
Fix issue with find references for jsx tags
2 parents 4e06457 + d5c3a0a commit 7c99c8f

12 files changed

+78
-4
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8749,6 +8749,9 @@ namespace ts {
87498749
if (isJsxIntrinsicIdentifier(node.tagName)) {
87508750
return getIntrinsicTagSymbol(node);
87518751
}
8752+
else if (node.tagName.kind === SyntaxKind.Identifier) {
8753+
return resolveEntityName(node.tagName, SymbolFlags.Value | SymbolFlags.Alias);
8754+
}
87528755
else {
87538756
return checkExpression(node.tagName).symbol;
87548757
}

tests/baselines/reference/jsxReactTestSuite.symbols

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ declare var hasOwnProperty:any;
5656
>div : Symbol(unknown)
5757

5858
<Component>{foo}<br />{bar}</Component>
59+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
5960
>foo : Symbol(foo, Decl(jsxReactTestSuite.tsx, 7, 11))
6061
>br : Symbol(unknown)
6162
>bar : Symbol(bar, Decl(jsxReactTestSuite.tsx, 8, 11))
63+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
6264

6365
<br />
6466
>br : Symbol(unknown)
@@ -68,12 +70,20 @@ declare var hasOwnProperty:any;
6870

6971

7072
<Composite>
73+
>Composite : Symbol(Composite, Decl(jsxReactTestSuite.tsx, 3, 11))
74+
7175
{this.props.children}
7276
</Composite>;
77+
>Composite : Symbol(Composite, Decl(jsxReactTestSuite.tsx, 3, 11))
7378

7479
<Composite>
80+
>Composite : Symbol(Composite, Decl(jsxReactTestSuite.tsx, 3, 11))
81+
7582
<Composite2 />
83+
>Composite2 : Symbol(Composite2, Decl(jsxReactTestSuite.tsx, 4, 11))
84+
7685
</Composite>;
86+
>Composite : Symbol(Composite, Decl(jsxReactTestSuite.tsx, 3, 11))
7787

7888
var x =
7989
>x : Symbol(x, Decl(jsxReactTestSuite.tsx, 10, 11), Decl(jsxReactTestSuite.tsx, 35, 3))
@@ -164,62 +174,76 @@ var x =
164174
>hasOwnProperty : Symbol(unknown)
165175

166176
<Component constructor="foo" />;
177+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
167178
>constructor : Symbol(unknown)
168179

169180
<Namespace.Component />;
170181

171182
<Namespace.DeepNamespace.Component />;
172183

173184
<Component { ... x } y
185+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
174186
>x : Symbol(x, Decl(jsxReactTestSuite.tsx, 10, 11), Decl(jsxReactTestSuite.tsx, 35, 3))
175187
>y : Symbol(unknown)
176188

177189
={2 } z />;
178190
>z : Symbol(unknown)
179191

180192
<Component
193+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
194+
181195
{...this.props} sound="moo" />;
182196
>sound : Symbol(unknown)
183197

184198
<font-face />;
185199
>font-face : Symbol(unknown)
186200

187201
<Component x={y} />;
202+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
188203
>x : Symbol(unknown)
189204
>y : Symbol(y, Decl(jsxReactTestSuite.tsx, 9, 11))
190205

191206
<x-component />;
192207
>x-component : Symbol(unknown)
193208

194209
<Component {...x} />;
210+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
195211
>x : Symbol(x, Decl(jsxReactTestSuite.tsx, 10, 11), Decl(jsxReactTestSuite.tsx, 35, 3))
196212

197213
<Component { ...x } y={2} />;
214+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
198215
>x : Symbol(x, Decl(jsxReactTestSuite.tsx, 10, 11), Decl(jsxReactTestSuite.tsx, 35, 3))
199216
>y : Symbol(unknown)
200217

201218
<Component { ... x } y={2} z />;
219+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
202220
>x : Symbol(x, Decl(jsxReactTestSuite.tsx, 10, 11), Decl(jsxReactTestSuite.tsx, 35, 3))
203221
>y : Symbol(unknown)
204222
>z : Symbol(unknown)
205223

206224
<Component x={1} {...y} />;
225+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
207226
>x : Symbol(unknown)
208227
>y : Symbol(y, Decl(jsxReactTestSuite.tsx, 9, 11))
209228

210229

211230
<Component x={1} y="2" {...z} {...z}><Child /></Component>;
231+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
212232
>x : Symbol(unknown)
213233
>y : Symbol(unknown)
214234
>z : Symbol(z, Decl(jsxReactTestSuite.tsx, 11, 11))
215235
>z : Symbol(z, Decl(jsxReactTestSuite.tsx, 11, 11))
236+
>Child : Symbol(Child, Decl(jsxReactTestSuite.tsx, 5, 11))
237+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
216238

217239
<Component x="1" {...(z = { y: 2 }, z)} z={3}>Text</Component>;
240+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
218241
>x : Symbol(unknown)
219242
>z : Symbol(z, Decl(jsxReactTestSuite.tsx, 11, 11))
220243
>y : Symbol(y, Decl(jsxReactTestSuite.tsx, 113, 27))
221244
>z : Symbol(z, Decl(jsxReactTestSuite.tsx, 11, 11))
222245
>z : Symbol(unknown)
246+
>Component : Symbol(Component, Decl(jsxReactTestSuite.tsx, 2, 11))
223247

224248

225249

tests/baselines/reference/reactNamespaceJSXEmit.symbols

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@ declare var x: any;
1717
>data : Symbol(unknown)
1818

1919
<Bar x={x} />;
20+
>Bar : Symbol(Bar, Decl(reactNamespaceJSXEmit.tsx, 3, 11))
2021
>x : Symbol(unknown)
2122
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 4, 11))
2223

2324
<x-component />;
2425
>x-component : Symbol(unknown)
2526

2627
<Bar {...x} />;
28+
>Bar : Symbol(Bar, Decl(reactNamespaceJSXEmit.tsx, 3, 11))
2729
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 4, 11))
2830

2931
<Bar { ...x } y={2} />;
32+
>Bar : Symbol(Bar, Decl(reactNamespaceJSXEmit.tsx, 3, 11))
3033
>x : Symbol(x, Decl(reactNamespaceJSXEmit.tsx, 4, 11))
3134
>y : Symbol(unknown)
3235

tests/baselines/reference/tsxElementResolution19.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,5 @@ import {MyClass} from './file1';
2424
>MyClass : Symbol(MyClass, Decl(file2.tsx, 3, 8))
2525

2626
<MyClass />;
27-
>MyClass : Symbol(MyClass, Decl(file1.tsx, 2, 1))
27+
>MyClass : Symbol(MyClass, Decl(file2.tsx, 3, 8))
2828

tests/baselines/reference/tsxExternalModuleEmit1.symbols

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export class App extends React.Component<any, any> {
2525
>render : Symbol(App.render, Decl(app.tsx, 5, 52))
2626

2727
return <Button />;
28-
>Button : Symbol(Button, Decl(button.tsx, 0, 31))
28+
>Button : Symbol(Button, Decl(app.tsx, 3, 8))
2929
}
3030

3131
}

tests/baselines/reference/tsxExternalModuleEmit2.symbols

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,15 @@ declare var Foo, React;
1818

1919
// Should see mod_1['default'] in emit here
2020
<Foo handler={Main}></Foo>;
21+
>Foo : Symbol(Foo, Decl(app.tsx, 1, 11))
2122
>handler : Symbol(unknown)
2223
>Main : Symbol(Main, Decl(app.tsx, 0, 6))
24+
>Foo : Symbol(Foo, Decl(app.tsx, 1, 11))
2325

2426
// Should see mod_1['default'] in emit here
2527
<Foo {...Main}></Foo>;
28+
>Foo : Symbol(Foo, Decl(app.tsx, 1, 11))
2629
>Main : Symbol(Main, Decl(app.tsx, 0, 6))
30+
>Foo : Symbol(Foo, Decl(app.tsx, 1, 11))
2731

2832

tests/baselines/reference/tsxGenericArrowFunctionParsing.symbols

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ var T, T1, T2;
1515
// This is an element
1616
var x1 = <T>() => {}</T>;
1717
>x1 : Symbol(x1, Decl(file.tsx, 7, 3))
18+
>T : Symbol(T, Decl(file.tsx, 4, 3))
19+
>T : Symbol(T, Decl(file.tsx, 4, 3))
1820

1921
x1.isElement;
2022
>x1.isElement : Symbol(JSX.Element.isElement, Decl(file.tsx, 1, 20))
@@ -41,7 +43,9 @@ x3();
4143
// This is an element
4244
var x4 = <T extends={true}>() => {}</T>;
4345
>x4 : Symbol(x4, Decl(file.tsx, 19, 3))
46+
>T : Symbol(T, Decl(file.tsx, 4, 3))
4447
>extends : Symbol(unknown)
48+
>T : Symbol(T, Decl(file.tsx, 4, 3))
4549

4650
x4.isElement;
4751
>x4.isElement : Symbol(JSX.Element.isElement, Decl(file.tsx, 1, 20))
@@ -51,7 +55,9 @@ x4.isElement;
5155
// This is an element
5256
var x5 = <T extends>() => {}</T>;
5357
>x5 : Symbol(x5, Decl(file.tsx, 23, 3))
58+
>T : Symbol(T, Decl(file.tsx, 4, 3))
5459
>extends : Symbol(unknown)
60+
>T : Symbol(T, Decl(file.tsx, 4, 3))
5561

5662
x5.isElement;
5763
>x5.isElement : Symbol(JSX.Element.isElement, Decl(file.tsx, 1, 20))

tests/baselines/reference/tsxPreserveEmit1.symbols

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import Route = ReactRouter.Route;
1313

1414
var routes1 = <Route />;
1515
>routes1 : Symbol(routes1, Decl(test.tsx, 6, 3))
16+
>Route : Symbol(Route, Decl(test.tsx, 2, 45))
1617

1718
module M {
1819
>M : Symbol(M, Decl(test.tsx, 6, 24), Decl(test.tsx, 10, 1))
@@ -26,6 +27,8 @@ module M {
2627
// Should emit 'M.X' in both opening and closing tags
2728
var y = <X></X>;
2829
>y : Symbol(y, Decl(test.tsx, 13, 4))
30+
>X : Symbol(X, Decl(test.tsx, 9, 11))
31+
>X : Symbol(X, Decl(test.tsx, 9, 11))
2932
}
3033

3134
=== tests/cases/conformance/jsx/react.d.ts ===

tests/baselines/reference/tsxPreserveEmit2.symbols

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ var Route: any;
66

77
var routes1 = <Route />;
88
>routes1 : Symbol(routes1, Decl(test.tsx, 3, 3))
9+
>Route : Symbol(Route, Decl(test.tsx, 2, 3))
910

tests/baselines/reference/tsxReactEmit3.symbols

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,11 @@ declare var Foo, Bar, baz;
1313
>baz : Symbol(baz, Decl(test.tsx, 4, 21))
1414

1515
<Foo> <Bar> q </Bar> <Bar/> s <Bar/><Bar/></Foo>;
16+
>Foo : Symbol(Foo, Decl(test.tsx, 4, 11))
17+
>Bar : Symbol(Bar, Decl(test.tsx, 4, 16))
18+
>Bar : Symbol(Bar, Decl(test.tsx, 4, 16))
19+
>Bar : Symbol(Bar, Decl(test.tsx, 4, 16))
20+
>Bar : Symbol(Bar, Decl(test.tsx, 4, 16))
21+
>Bar : Symbol(Bar, Decl(test.tsx, 4, 16))
22+
>Foo : Symbol(Foo, Decl(test.tsx, 4, 11))
23+

tests/baselines/reference/tsxStatelessFunctionComponents3.symbols

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const Foo = (props: any) => <div/>;
1111
// Should be OK
1212
const foo = <Foo />;
1313
>foo : Symbol(foo, Decl(file.tsx, 5, 5))
14-
>Foo : Symbol((Anonymous function), Decl(file.tsx, 3, 11))
14+
>Foo : Symbol(Foo, Decl(file.tsx, 3, 5))
1515

1616

1717
// Should be OK
@@ -40,7 +40,7 @@ var App: React.StatelessComponent<{ children }> = ({children}) => (
4040
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 927, 45))
4141

4242
<MainMenu/>
43-
>MainMenu : Symbol(React.StatelessComponent, Decl(react.d.ts, 139, 5))
43+
>MainMenu : Symbol(MainMenu, Decl(file.tsx, 9, 3))
4444

4545
</div>
4646
>div : Symbol(JSX.IntrinsicElements.div, Decl(react.d.ts, 927, 45))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @Filename: index.tsx
4+
////import { /*1*/SubmissionComp } from "./RedditSubmission"
5+
////function displaySubreddit(subreddit: string) {
6+
//// let components = submissions
7+
//// .map((value, index) => </*2*/SubmissionComp key={ index } elementPosition= { index } {...value.data} />);
8+
////}
9+
10+
// @Filename: RedditSubmission.ts
11+
////export const /*3*/SubmissionComp = (submission: SubmissionProps) =>
12+
//// <div style={{ fontFamily: "sans-serif" }}></div>;
13+
14+
15+
goTo.marker("1");
16+
verify.referencesCountIs(3);
17+
18+
goTo.marker("2");
19+
verify.referencesCountIs(3);
20+
21+
goTo.marker("3");
22+
verify.referencesCountIs(3);

0 commit comments

Comments
 (0)