Skip to content

Commit e2178ec

Browse files
author
Andy
authored
In getSymbolAtLocation, return undefined instead of unknownSymbol (#21774)
* In getSymbolAtLocation, return undefined instead of unknownSymbol * Update check in completions to look for undefined instead of unknownSymbol
1 parent 16f3b93 commit e2178ec

File tree

60 files changed

+37
-372
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+37
-372
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24628,7 +24628,8 @@ namespace ts {
2462824628

2462924629
if (entityName.kind === SyntaxKind.Identifier) {
2463024630
if (isJSXTagName(entityName) && isJsxIntrinsicIdentifier(entityName)) {
24631-
return getIntrinsicTagSymbol(<JsxOpeningLikeElement>entityName.parent);
24631+
const symbol = getIntrinsicTagSymbol(<JsxOpeningLikeElement>entityName.parent);
24632+
return symbol === unknownSymbol ? undefined : symbol;
2463224633
}
2463324634

2463424635
return resolveEntityName(entityName, SymbolFlags.Value, /*ignoreErrors*/ false, /*dontResolveAlias*/ true);

src/services/completions.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -923,9 +923,8 @@ namespace ts.Completions {
923923
}
924924
else if (isStartingCloseTag) {
925925
const tagName = (<JsxElement>contextToken.parent.parent).openingElement.tagName;
926-
const tagSymbol = Debug.assertDefined(typeChecker.getSymbolAtLocation(tagName));
927-
928-
if (!typeChecker.isUnknownSymbol(tagSymbol)) {
926+
const tagSymbol = typeChecker.getSymbolAtLocation(tagName);
927+
if (tagSymbol) {
929928
symbols = [tagSymbol];
930929
}
931930
completionKind = CompletionKind.MemberLike;
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
=== tests/cases/compiler/conflictMarkerTrivia3.tsx ===
22
const x = <div>
33
>x : Symbol(x, Decl(conflictMarkerTrivia3.tsx, 0, 5))
4-
>div : Symbol(unknown)
54

65
<<<<<<< HEAD

tests/baselines/reference/es3-jsx-preserve.symbols

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ const React: any = null;
44

55
const elem = <div></div>;
66
>elem : Symbol(elem, Decl(es3-jsx-preserve.tsx, 2, 5))
7-
>div : Symbol(unknown)
8-
>div : Symbol(unknown)
97

108

tests/baselines/reference/es3-jsx-react-native.symbols

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ const React: any = null;
44

55
const elem = <div></div>;
66
>elem : Symbol(elem, Decl(es3-jsx-react-native.tsx, 2, 5))
7-
>div : Symbol(unknown)
8-
>div : Symbol(unknown)
97

108

tests/baselines/reference/es3-jsx-react.symbols

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,5 @@ const React: any = null;
44

55
const elem = <div></div>;
66
>elem : Symbol(elem, Decl(es3-jsx-react.tsx, 2, 5))
7-
>div : Symbol(unknown)
8-
>div : Symbol(unknown)
97

108

tests/baselines/reference/importHelpersInTsx.symbols

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ declare var o: any;
77

88
export const x = <span {...o} />
99
>x : Symbol(x, Decl(external.tsx, 2, 12))
10-
>span : Symbol(unknown)
1110
>o : Symbol(o, Decl(external.tsx, 1, 11))
1211

1312
=== tests/cases/compiler/script.tsx ===
@@ -19,7 +18,6 @@ declare var o: any;
1918

2019
const x = <span {...o} />
2120
>x : Symbol(x, Decl(script.tsx, 2, 5))
22-
>span : Symbol(unknown)
2321
>o : Symbol(o, Decl(script.tsx, 1, 11))
2422

2523
=== tests/cases/compiler/tslib.d.ts ===

tests/baselines/reference/jsFileCompilationTypeAssertions.symbols

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
0 as number;
33
var v = <string>undefined;
44
>v : Symbol(v, Decl(a.js, 1, 3))
5-
>string : Symbol(unknown)
65

tests/baselines/reference/jsxAndTypeAssertion.symbols

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,53 +10,23 @@ var x: any;
1010

1111
x = <any> { test: <any></any> };
1212
>x : Symbol(x, Decl(jsxAndTypeAssertion.tsx, 4, 3))
13-
>any : Symbol(unknown)
14-
>any : Symbol(unknown)
15-
>any : Symbol(unknown)
1613

1714
x = <any><any></any>;
18-
>any : Symbol(unknown)
19-
>any : Symbol(unknown)
20-
>any : Symbol(unknown)
2115

2216
x = <foo>hello {<foo>{}} </foo>;
23-
>foo : Symbol(unknown)
24-
>foo : Symbol(unknown)
25-
>foo : Symbol(unknown)
2617

2718
x = <foo test={<foo>{}}>hello</foo>;
28-
>foo : Symbol(unknown)
2919
>test : Symbol(test, Decl(jsxAndTypeAssertion.tsx, 11, 8))
30-
>foo : Symbol(unknown)
31-
>foo : Symbol(unknown)
3220

3321
x = <foo test={<foo>{}}>hello{<foo>{}}</foo>;
34-
>foo : Symbol(unknown)
3522
>test : Symbol(test, Decl(jsxAndTypeAssertion.tsx, 13, 8))
36-
>foo : Symbol(unknown)
37-
>foo : Symbol(unknown)
38-
>foo : Symbol(unknown)
3923

4024
x = <foo>x</foo>, x = <foo/>;
41-
>foo : Symbol(unknown)
42-
>foo : Symbol(unknown)
43-
>foo : Symbol(unknown)
4425

4526
<foo>{<foo><foo>{/foo/.test(x) ? <foo><foo></foo> : <foo><foo></foo>}</foo>}</foo>
46-
>foo : Symbol(unknown)
47-
>foo : Symbol(unknown)
48-
>foo : Symbol(unknown)
4927
>/foo/.test : Symbol(RegExp.test, Decl(lib.d.ts, --, --))
5028
>test : Symbol(RegExp.test, Decl(lib.d.ts, --, --))
5129
>x : Symbol(x, Decl(jsxAndTypeAssertion.tsx, 4, 3))
52-
>foo : Symbol(unknown)
53-
>foo : Symbol(unknown)
54-
>foo : Symbol(unknown)
55-
>foo : Symbol(unknown)
56-
>foo : Symbol(unknown)
57-
>foo : Symbol(unknown)
58-
>foo : Symbol(unknown)
59-
>foo : Symbol(unknown)
6030

6131

6232

tests/baselines/reference/jsxEmitAttributeWithPreserve.symbols

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,5 @@ declare var React: any;
33
>React : Symbol(React, Decl(jsxEmitAttributeWithPreserve.tsx, 0, 11))
44

55
<foo data/>
6-
>foo : Symbol(unknown)
76
>data : Symbol(data, Decl(jsxEmitAttributeWithPreserve.tsx, 1, 4))
87

tests/baselines/reference/jsxEmitWithAttributes.symbols

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,15 @@ class A {
9999

100100
return [
101101
<meta content="helloworld"></meta>,
102-
>meta : Symbol(unknown)
103102
>content : Symbol(content, Decl(test.tsx, 11, 8))
104-
>meta : Symbol(unknown)
105103

106104
<meta content={c.a!.b}></meta>
107-
>meta : Symbol(unknown)
108105
>content : Symbol(content, Decl(test.tsx, 12, 8))
109106
>c.a!.b : Symbol(b, Decl(test.tsx, 3, 6))
110107
>c.a : Symbol(a, Decl(test.tsx, 2, 8))
111108
>c : Symbol(c, Decl(test.tsx, 2, 3))
112109
>a : Symbol(a, Decl(test.tsx, 2, 8))
113110
>b : Symbol(b, Decl(test.tsx, 3, 6))
114-
>meta : Symbol(unknown)
115111

116112
];
117113
}

tests/baselines/reference/jsxEsprimaFbTestSuite.symbols

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,12 @@ declare var props;
2121
>props : Symbol(props, Decl(jsxEsprimaFbTestSuite.tsx, 6, 11))
2222

2323
<a />;
24-
>a : Symbol(unknown)
2524

2625
//<n:a n:v />; Namespace unsuported
2726

2827
//<a n:foo="bar"> {value} <b><c /></b></a>; Namespace unsuported
2928

3029
<a b={" "} c=" " d="&amp;" e="id=1&group=2" f="&#123456789" g="&#123*;" h="&#x;" />;
31-
>a : Symbol(unknown)
3230
>b : Symbol(b, Decl(jsxEsprimaFbTestSuite.tsx, 14, 2))
3331
>c : Symbol(c, Decl(jsxEsprimaFbTestSuite.tsx, 14, 10))
3432
>d : Symbol(d, Decl(jsxEsprimaFbTestSuite.tsx, 14, 16))
@@ -38,12 +36,9 @@ declare var props;
3836
>h : Symbol(h, Decl(jsxEsprimaFbTestSuite.tsx, 14, 71))
3937

4038
<a b="&notanentity;" />;
41-
>a : Symbol(unknown)
4239
>b : Symbol(b, Decl(jsxEsprimaFbTestSuite.tsx, 16, 2))
4340

4441
<a
45-
>a : Symbol(unknown)
46-
4742
/>;
4843

4944
<日本語></日本語>;
@@ -62,36 +57,21 @@ baz
6257
>AbC_def : Symbol(AbC_def, Decl(jsxEsprimaFbTestSuite.tsx, 2, 11))
6358

6459
<a b={x ? <c /> : <d />} />;
65-
>a : Symbol(unknown)
6660
>b : Symbol(b, Decl(jsxEsprimaFbTestSuite.tsx, 28, 2))
6761
>x : Symbol(x, Decl(jsxEsprimaFbTestSuite.tsx, 4, 11))
68-
>c : Symbol(unknown)
69-
>d : Symbol(unknown)
7062

7163
<a>{}</a>;
72-
>a : Symbol(unknown)
73-
>a : Symbol(unknown)
7464

7565
<a>{/* this is a comment */}</a>;
76-
>a : Symbol(unknown)
77-
>a : Symbol(unknown)
7866

7967
<div>@test content</div>;
80-
>div : Symbol(unknown)
81-
>div : Symbol(unknown)
8268

8369
<div><br />7x invalid-js-identifier</div>;
84-
>div : Symbol(unknown)
85-
>br : Symbol(unknown)
86-
>div : Symbol(unknown)
8770

8871
<LeftRight left=<a /> right=<b>monkeys /> gorillas</b> />;
8972
>LeftRight : Symbol(LeftRight, Decl(jsxEsprimaFbTestSuite.tsx, 3, 11))
9073
>left : Symbol(left, Decl(jsxEsprimaFbTestSuite.tsx, 38, 10))
91-
>a : Symbol(unknown)
9274
>right : Symbol(right, Decl(jsxEsprimaFbTestSuite.tsx, 38, 21))
93-
>b : Symbol(unknown)
94-
>b : Symbol(unknown)
9575

9676
<a.b></a.b>;
9777
>a : Symbol(a, Decl(jsxEsprimaFbTestSuite.tsx, 5, 11))
@@ -102,26 +82,19 @@ baz
10282
>a : Symbol(a, Decl(jsxEsprimaFbTestSuite.tsx, 5, 11))
10383

10484
(<div />) < x;
105-
>div : Symbol(unknown)
10685
>x : Symbol(x, Decl(jsxEsprimaFbTestSuite.tsx, 4, 11))
10786

10887
<div {...props} />;
109-
>div : Symbol(unknown)
11088
>props : Symbol(props, Decl(jsxEsprimaFbTestSuite.tsx, 6, 11))
11189

11290
<div {...props} post="attribute" />;
113-
>div : Symbol(unknown)
11491
>props : Symbol(props, Decl(jsxEsprimaFbTestSuite.tsx, 6, 11))
11592
>post : Symbol(post, Decl(jsxEsprimaFbTestSuite.tsx, 48, 15))
11693

11794
<div pre="leading" pre2="attribute" {...props}></div>;
118-
>div : Symbol(unknown)
11995
>pre : Symbol(pre, Decl(jsxEsprimaFbTestSuite.tsx, 50, 4))
12096
>pre2 : Symbol(pre2, Decl(jsxEsprimaFbTestSuite.tsx, 50, 18))
12197
>props : Symbol(props, Decl(jsxEsprimaFbTestSuite.tsx, 6, 11))
122-
>div : Symbol(unknown)
12398

12499
<a> </a>;
125-
>a : Symbol(unknown)
126-
>a : Symbol(unknown)
127100

tests/baselines/reference/jsxFactoryAndFragment.symbols

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,3 @@ declare var h: any;
44

55
<></>;
66
<><span>1</span><><span>2.1</span><span>2.2</span></></>;
7-
>span : Symbol(unknown)
8-
>span : Symbol(unknown)
9-
>span : Symbol(unknown)
10-
>span : Symbol(unknown)
11-
>span : Symbol(unknown)
12-
>span : Symbol(unknown)
13-

tests/baselines/reference/jsxFactoryAndReactNamespace.symbols

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,15 @@ class A {
9999

100100
return [
101101
<meta content="helloworld"></meta>,
102-
>meta : Symbol(unknown)
103102
>content : Symbol(content, Decl(test.tsx, 11, 8))
104-
>meta : Symbol(unknown)
105103

106104
<meta content={c.a!.b}></meta>
107-
>meta : Symbol(unknown)
108105
>content : Symbol(content, Decl(test.tsx, 12, 8))
109106
>c.a!.b : Symbol(b, Decl(test.tsx, 3, 6))
110107
>c.a : Symbol(a, Decl(test.tsx, 2, 8))
111108
>c : Symbol(c, Decl(test.tsx, 2, 3))
112109
>a : Symbol(a, Decl(test.tsx, 2, 8))
113110
>b : Symbol(b, Decl(test.tsx, 3, 6))
114-
>meta : Symbol(unknown)
115111

116112
];
117113
}

tests/baselines/reference/jsxFactoryIdentifier.symbols

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,15 @@ class A {
105105

106106
return [
107107
<meta content="helloworld"></meta>,
108-
>meta : Symbol(unknown)
109108
>content : Symbol(content, Decl(test.tsx, 11, 8))
110-
>meta : Symbol(unknown)
111109

112110
<meta content={c.a!.b}></meta>
113-
>meta : Symbol(unknown)
114111
>content : Symbol(content, Decl(test.tsx, 12, 8))
115112
>c.a!.b : Symbol(b, Decl(test.tsx, 3, 6))
116113
>c.a : Symbol(a, Decl(test.tsx, 2, 8))
117114
>c : Symbol(c, Decl(test.tsx, 2, 3))
118115
>a : Symbol(a, Decl(test.tsx, 2, 8))
119116
>b : Symbol(b, Decl(test.tsx, 3, 6))
120-
>meta : Symbol(unknown)
121117

122118
];
123119
}

tests/baselines/reference/jsxFactoryIdentifierAsParameter.symbols

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ export class AppComponent {
1818
>createElement : Symbol(createElement, Decl(test.tsx, 7, 11))
1919

2020
return <div />;
21-
>div : Symbol(unknown)
2221
}
2322
}
2423

tests/baselines/reference/jsxFactoryIdentifierWithAbsentParameter.symbols

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ export class AppComponent {
1717
>render : Symbol(AppComponent.render, Decl(test.tsx, 6, 27))
1818

1919
return <div />;
20-
>div : Symbol(unknown)
2120
}
2221
}
2322

tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName.symbols

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,15 @@ class A {
9999

100100
return [
101101
<meta content="helloworld"></meta>,
102-
>meta : Symbol(unknown)
103102
>content : Symbol(content, Decl(test.tsx, 11, 8))
104-
>meta : Symbol(unknown)
105103

106104
<meta content={c.a!.b}></meta>
107-
>meta : Symbol(unknown)
108105
>content : Symbol(content, Decl(test.tsx, 12, 8))
109106
>c.a!.b : Symbol(b, Decl(test.tsx, 3, 6))
110107
>c.a : Symbol(a, Decl(test.tsx, 2, 8))
111108
>c : Symbol(c, Decl(test.tsx, 2, 3))
112109
>a : Symbol(a, Decl(test.tsx, 2, 8))
113110
>b : Symbol(b, Decl(test.tsx, 3, 6))
114-
>meta : Symbol(unknown)
115111

116112
];
117113
}

tests/baselines/reference/jsxFactoryNotIdentifierOrQualifiedName2.symbols

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,15 @@ class A {
9999

100100
return [
101101
<meta content="helloworld"></meta>,
102-
>meta : Symbol(unknown)
103102
>content : Symbol(content, Decl(test.tsx, 11, 8))
104-
>meta : Symbol(unknown)
105103

106104
<meta content={c.a!.b}></meta>
107-
>meta : Symbol(unknown)
108105
>content : Symbol(content, Decl(test.tsx, 12, 8))
109106
>c.a!.b : Symbol(b, Decl(test.tsx, 3, 6))
110107
>c.a : Symbol(a, Decl(test.tsx, 2, 8))
111108
>c : Symbol(c, Decl(test.tsx, 2, 3))
112109
>a : Symbol(a, Decl(test.tsx, 2, 8))
113110
>b : Symbol(b, Decl(test.tsx, 3, 6))
114-
>meta : Symbol(unknown)
115111

116112
];
117113
}

tests/baselines/reference/jsxFactoryQualifiedName.symbols

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,19 +99,15 @@ class A {
9999

100100
return [
101101
<meta content="helloworld"></meta>,
102-
>meta : Symbol(unknown)
103102
>content : Symbol(content, Decl(test.tsx, 11, 8))
104-
>meta : Symbol(unknown)
105103

106104
<meta content={c.a!.b}></meta>
107-
>meta : Symbol(unknown)
108105
>content : Symbol(content, Decl(test.tsx, 12, 8))
109106
>c.a!.b : Symbol(b, Decl(test.tsx, 3, 6))
110107
>c.a : Symbol(a, Decl(test.tsx, 2, 8))
111108
>c : Symbol(c, Decl(test.tsx, 2, 3))
112109
>a : Symbol(a, Decl(test.tsx, 2, 8))
113110
>b : Symbol(b, Decl(test.tsx, 3, 6))
114-
>meta : Symbol(unknown)
115111

116112
];
117113
}

tests/baselines/reference/jsxFactoryQualifiedNameResolutionError.symbols

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,5 @@ export class AppComponent {
1818
>createElement : Symbol(createElement, Decl(test.tsx, 7, 11))
1919

2020
return <div />;
21-
>div : Symbol(unknown)
2221
}
2322
}

tests/baselines/reference/jsxFactoryQualifiedNameWithEs5.symbols

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,5 @@ class Component {
1616
>renderCallback : Symbol(Component.renderCallback, Decl(index.tsx, 5, 17))
1717

1818
return <div>test</div>;
19-
>div : Symbol(unknown)
20-
>div : Symbol(unknown)
2119
}
2220
};

0 commit comments

Comments
 (0)