Skip to content

Commit b08fe6f

Browse files
author
Andy Hanson
committed
Use proper method of not resolving alias
1 parent 9e12290 commit b08fe6f

2 files changed

Lines changed: 71 additions & 10 deletions

File tree

src/compiler/checker.ts

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ namespace ts {
12071207
}
12081208

12091209
// Resolves a qualified name and any involved aliases
1210-
function resolveEntityName(name: EntityName | Expression, meaning: SymbolFlags, ignoreErrors?: boolean, dontResolveAlias?: boolean): Symbol {
1210+
function resolveEntityName(name: EntityName | Expression, meaning: SymbolFlags, ignoreErrors = false, dontResolveAlias = false): Symbol {
12111211
if (nodeIsMissing(name)) {
12121212
return undefined;
12131213
}
@@ -16873,10 +16873,7 @@ namespace ts {
1687316873
return getIntrinsicTagSymbol(<JsxOpeningLikeElement>entityName.parent);
1687416874
}
1687516875

16876-
// Include aliases in the meaning, this ensures that we do not follow aliases to where they point and instead
16877-
// return the alias symbol.
16878-
const meaning: SymbolFlags = SymbolFlags.Value | SymbolFlags.Alias;
16879-
return resolveEntityName(<Identifier>entityName, meaning);
16876+
return resolveEntityName(<Identifier>entityName, SymbolFlags.Value, /*ignoreErrors*/ false, /*dontResolveAlias*/ true);
1688016877
}
1688116878
else if (entityName.kind === SyntaxKind.PropertyAccessExpression) {
1688216879
const symbol = getNodeLinks(entityName).resolvedSymbol;
@@ -16894,11 +16891,8 @@ namespace ts {
1689416891
}
1689516892
}
1689616893
else if (isTypeReferenceIdentifier(<EntityName>entityName)) {
16897-
let meaning = (entityName.parent.kind === SyntaxKind.TypeReference || entityName.parent.kind === SyntaxKind.JSDocTypeReference) ? SymbolFlags.Type : SymbolFlags.Namespace;
16898-
// Include aliases in the meaning, this ensures that we do not follow aliases to where they point and instead
16899-
// return the alias symbol.
16900-
meaning |= SymbolFlags.Alias;
16901-
return resolveEntityName(<EntityName>entityName, meaning);
16894+
const meaning = (entityName.parent.kind === SyntaxKind.TypeReference || entityName.parent.kind === SyntaxKind.JSDocTypeReference) ? SymbolFlags.Type : SymbolFlags.Namespace;
16895+
return resolveEntityName(<EntityName>entityName, meaning, /*ignoreErrors*/ false, /*dontResolveAlias*/true);
1690216896
}
1690316897
else if (entityName.parent.kind === SyntaxKind.JsxAttribute) {
1690416898
return getJsxAttributePropertySymbol(<JsxAttribute>entityName.parent);
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
///<reference path="fourslash.ts" />
2+
3+
// Testing that quickInfo gets information with a corresponding meaning: values to values, types to types.
4+
// For quick info purposes, we don't resolve past aliases.
5+
// However, when we have an alias for a type, the quickInfo for a value with the same should skip the alias, and vice versa.
6+
// goToDefinition should work the same way.
7+
8+
// @Filename: foo.d.ts
9+
////declare const /*foo_value_declaration*/foo: number;
10+
////declare module "foo_module" {
11+
//// interface I { x: number; y: number }
12+
//// export = I;
13+
////}
14+
15+
// @Filename: foo_user.ts
16+
///////<reference path="foo.d.ts" />
17+
/////*foo_type_declaration*/import foo = require("foo_module");
18+
////const x = foo/*foo_value*/;
19+
////const i: foo/*foo_type*/ = { x: 1, y: 2 };
20+
21+
verify.numberOfErrorsInCurrentFile(0);
22+
23+
verify.navigationItemsListCount(2, "foo", "exact");
24+
verify.navigationItemsListContains("foo", "alias", "foo", "exact");
25+
verify.navigationItemsListContains("foo", "const", "foo", "exact");
26+
27+
goTo.marker("foo_value");
28+
verify.quickInfoIs("const foo: number");
29+
goTo.definition();
30+
verify.caretAtMarker("foo_value_declaration");
31+
32+
goTo.marker("foo_type");
33+
verify.quickInfoIs("import foo = require(\"foo_module\")");
34+
goTo.definition();
35+
verify.caretAtMarker("foo_type_declaration");
36+
37+
38+
// Above tested for global const and imported interface. Now test with global interface and imported const.
39+
40+
41+
// @Filename: bar.d.ts
42+
/////*bar_type_declaration*/declare interface bar { x: number; y: number }
43+
////declare module "bar_module" {
44+
//// const x: number;
45+
//// export = x;
46+
////}
47+
48+
// @Filename: bar_user.ts
49+
///////<reference path="bar.d.ts" />
50+
/////*bar_value_declaration*/import bar = require("bar_module");
51+
////const x = bar/*bar_value*/;
52+
////const i: bar/*bar_type*/ = { x: 1, y: 2 };
53+
54+
verify.numberOfErrorsInCurrentFile(0);
55+
verify.navigationItemsListCount(2, "bar", "exact");
56+
verify.navigationItemsListContains("bar", "alias", "bar", "exact");
57+
verify.navigationItemsListContains("bar", "interface", "bar", "exact");
58+
59+
goTo.marker("bar_value");
60+
verify.quickInfoIs("import bar = require(\"bar_module\")");
61+
goTo.definition();
62+
verify.caretAtMarker("bar_value_declaration");
63+
64+
goTo.marker("bar_type");
65+
verify.quickInfoIs("interface bar");
66+
goTo.definition();
67+
verify.caretAtMarker("bar_type_declaration");

0 commit comments

Comments
 (0)