Skip to content

Commit 83beae7

Browse files
author
Andy
authored
Merge pull request #15751 from Microsoft/tsx-gotodef
Fix bug for goto-definition on a TSX constructor using an alias declaration
2 parents b1da19a + f05a85d commit 83beae7

File tree

4 files changed

+20
-22
lines changed

4 files changed

+20
-22
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12755,7 +12755,7 @@ namespace ts {
1275512755
* @param node the expression whose contextual type will be returned.
1275612756
* @returns the contextual type of an expression.
1275712757
*/
12758-
function getContextualType(node: Expression): Type {
12758+
function getContextualType(node: Expression): Type | undefined {
1275912759
if (isInsideWithStatementBody(node)) {
1276012760
// We cannot answer semantic questions within a with block, do not proceed any further
1276112761
return undefined;

src/compiler/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2528,7 +2528,7 @@ namespace ts {
25282528
getFullyQualifiedName(symbol: Symbol): string;
25292529
getAugmentedPropertiesOfType(type: Type): Symbol[];
25302530
getRootSymbols(symbol: Symbol): Symbol[];
2531-
getContextualType(node: Expression): Type;
2531+
getContextualType(node: Expression): Type | undefined;
25322532
getResolvedSignature(node: CallLikeExpression, candidatesOutArray?: Signature[]): Signature;
25332533
getSignatureFromDeclaration(declaration: SignatureDeclaration): Signature;
25342534
isImplementationOfOverload(node: FunctionLikeDeclaration): boolean;

src/services/goToDefinition.ts

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -85,17 +85,6 @@ namespace ts.GoToDefinition {
8585
declaration => createDefinitionInfo(declaration, shorthandSymbolKind, shorthandSymbolName, shorthandContainerName));
8686
}
8787

88-
if (isJsxOpeningLikeElement(node.parent)) {
89-
// If there are errors when trying to figure out stateless component function, just return the first declaration
90-
// For example:
91-
// declare function /*firstSource*/MainButton(buttonProps: ButtonProps): JSX.Element;
92-
// declare function /*secondSource*/MainButton(linkProps: LinkProps): JSX.Element;
93-
// declare function /*thirdSource*/MainButton(props: ButtonProps | LinkProps): JSX.Element;
94-
// let opt = <Main/*firstTarget*/Button />; // Error - We get undefined for resolved signature indicating an error, then just return the first declaration
95-
const {symbolName, symbolKind, containerName} = getSymbolInfo(typeChecker, symbol, node);
96-
return [createDefinitionInfo(symbol.valueDeclaration, symbolKind, symbolName, containerName)];
97-
}
98-
9988
// If the current location we want to find its definition is in an object literal, try to get the contextual type for the
10089
// object literal, lookup the property symbol in the contextual type, and use this for goto-definition.
10190
// For example
@@ -106,15 +95,9 @@ namespace ts.GoToDefinition {
10695
// function Foo(arg: Props) {}
10796
// Foo( { pr/*1*/op1: 10, prop2: true })
10897
const element = getContainingObjectLiteralElement(node);
109-
if (element) {
110-
if (typeChecker.getContextualType(element.parent as Expression)) {
111-
const result: DefinitionInfo[] = [];
112-
const propertySymbols = getPropertySymbolsFromContextualType(typeChecker, element);
113-
for (const propertySymbol of propertySymbols) {
114-
result.push(...getDefinitionFromSymbol(typeChecker, propertySymbol, node));
115-
}
116-
return result;
117-
}
98+
if (element && typeChecker.getContextualType(element.parent as Expression)) {
99+
return flatMap(getPropertySymbolsFromContextualType(typeChecker, element), propertySymbol =>
100+
getDefinitionFromSymbol(typeChecker, propertySymbol, node));
118101
}
119102
return getDefinitionFromSymbol(typeChecker, symbol, node);
120103
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference path="fourslash.ts" />
2+
3+
// @jsx: preserve
4+
5+
// @Filename: C.tsx
6+
////export default class C {}
7+
8+
// @Filename: a.tsx
9+
////import /*def*/C from "./C";
10+
////const foo = </*use*/C />;
11+
12+
verify.noErrors();
13+
14+
goTo.marker("use");
15+
verify.goToDefinitionIs("def");

0 commit comments

Comments
 (0)