mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Handle localness in special cases by checking exported variable assignment (#43851)
* Handle localness in special cases by checking exported variable assignment Fixes #42976 * Fix existing tests where arrow now behaves similar to function expression * Update src/services/goToDefinition.ts
This commit is contained in:
@@ -326,10 +326,41 @@ namespace ts.GoToDefinition {
|
||||
sourceFile,
|
||||
FindAllReferences.getContextNode(declaration)
|
||||
),
|
||||
isLocal: !checker.isDeclarationVisible(declaration)
|
||||
isLocal: !isDefinitionVisible(checker, declaration)
|
||||
};
|
||||
}
|
||||
|
||||
function isDefinitionVisible(checker: TypeChecker, declaration: Declaration): boolean {
|
||||
if (checker.isDeclarationVisible(declaration)) return true;
|
||||
if (!declaration.parent) return false;
|
||||
|
||||
// Variable initializers are visible if variable is visible
|
||||
if (hasInitializer(declaration.parent) && declaration.parent.initializer === declaration) return isDefinitionVisible(checker, declaration.parent as Declaration);
|
||||
|
||||
// Handle some exceptions here like arrow function, members of class and object literal expression which are technically not visible but we want the definition to be determined by its parent
|
||||
switch (declaration.kind) {
|
||||
case SyntaxKind.PropertyDeclaration:
|
||||
case SyntaxKind.GetAccessor:
|
||||
case SyntaxKind.SetAccessor:
|
||||
case SyntaxKind.MethodDeclaration:
|
||||
// Private/protected properties/methods are not visible
|
||||
if (hasEffectiveModifier(declaration, ModifierFlags.Private)) return false;
|
||||
// Public properties/methods are visible if its parents are visible, so:
|
||||
// falls through
|
||||
|
||||
case SyntaxKind.Constructor:
|
||||
case SyntaxKind.PropertyAssignment:
|
||||
case SyntaxKind.ShorthandPropertyAssignment:
|
||||
case SyntaxKind.ObjectLiteralExpression:
|
||||
case SyntaxKind.ClassExpression:
|
||||
case SyntaxKind.ArrowFunction:
|
||||
case SyntaxKind.FunctionExpression:
|
||||
return isDefinitionVisible(checker, declaration.parent as Declaration);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function createDefinitionFromSignatureDeclaration(typeChecker: TypeChecker, decl: SignatureDeclaration): DefinitionInfo {
|
||||
return createDefinitionInfo(decl, typeChecker, decl.symbol, decl);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user