Skip to content

Commit aaf6b83

Browse files
author
Andy Hanson
committed
Don't goto aliased symbol with no declarations; and update tests
1 parent d6fa91e commit aaf6b83

File tree

6 files changed

+16
-13
lines changed

6 files changed

+16
-13
lines changed

src/services/goToDefinition.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ namespace ts.GoToDefinition {
5151
// import {A, B} from "mod";
5252
// to jump to the implementation directly.
5353
if (symbol.flags & SymbolFlags.Alias && shouldSkipAlias(node, symbol.declarations[0])) {
54-
symbol = typeChecker.getAliasedSymbol(symbol);
54+
const aliased = typeChecker.getAliasedSymbol(symbol);
55+
if (aliased.declarations) {
56+
symbol = aliased;
57+
}
5558
}
5659

5760
// Because name in short-hand property assignment has two different meanings: property name and property value,

tests/cases/fourslash/ambientShorthandGotoDefinition.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
verify.quickInfoAt("useFoo", "import foo");
1414
verify.goToDefinition({
15-
useFoo: "importFoo",
15+
useFoo: "module",
1616
importFoo: "module"
1717
});
1818

@@ -27,6 +27,6 @@ verify.goToDefinition({
2727

2828
verify.quickInfoAt("useBang", "import bang = require(\"jquery\")");
2929
verify.goToDefinition({
30-
useBang: "importBang",
30+
useBang: "module",
3131
importBang: "module"
3232
});

tests/cases/fourslash/goToDefinition_untypedModule.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
////not read
55

66
// @Filename: /a.ts
7-
////import { f } from "foo";
8-
/////**/f();
7+
////import { /*def*/f } from "foo";
8+
/////*use*/f();
99

10-
verify.goToDefinition("", []);
10+
verify.goToDefinition("use", "def");

tests/cases/fourslash/quickInfoMeaning.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
// @Filename: foo.d.ts
99
////declare const /*foo_value_declaration*/foo: number;
1010
////declare module "foo_module" {
11-
//// interface I { x: number; y: number }
11+
//// interface /*foo_type_declaration*/I { x: number; y: number }
1212
//// export = I;
1313
////}
1414

1515
// @Filename: foo_user.ts
1616
///////<reference path="foo.d.ts" />
17-
////import /*foo_type_declaration*/foo = require("foo_module");
17+
////import foo = require("foo_module");
1818
////const x = foo/*foo_value*/;
1919
////const i: foo/*foo_type*/ = { x: 1, y: 2 };
2020

@@ -39,13 +39,13 @@ verify.goToDefinitionIs("foo_type_declaration");
3939
// @Filename: bar.d.ts
4040
////declare interface /*bar_type_declaration*/bar { x: number; y: number }
4141
////declare module "bar_module" {
42-
//// const x: number;
42+
//// const /*bar_value_declaration*/x: number;
4343
//// export = x;
4444
////}
4545

4646
// @Filename: bar_user.ts
4747
///////<reference path="bar.d.ts" />
48-
////import /*bar_value_declaration*/bar = require("bar_module");
48+
////import bar = require("bar_module");
4949
////const x = bar/*bar_value*/;
5050
////const i: bar/*bar_type*/ = { x: 1, y: 2 };
5151

tests/cases/fourslash/tsxGoToDefinitionClassInDifferentFile.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// @jsx: preserve
44

55
// @Filename: C.tsx
6-
////export default class C {}
6+
////export default class /*def*/C {}
77

88
// @Filename: a.tsx
9-
////import /*def*/C from "./C";
9+
////import C from "./C";
1010
////const foo = </*use*/C />;
1111

1212
verify.noErrors();

tests/cases/fourslash/untypedModuleImport.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ const [r0, r1, r2] = test.ranges();
1717
verify.singleReferenceGroup('"foo"', [r1]);
1818

1919
goTo.marker("foo");
20-
verify.goToDefinitionIs([]);
20+
verify.goToDefinitionIs("foo");
2121
verify.quickInfoIs("import foo");
2222
verify.singleReferenceGroup("import foo", [r0, r2]);

0 commit comments

Comments
 (0)