Don't filter away private completions if in the same context

Fixes #34405, which was introduced in PR #16953.
This commit is contained in:
Eli Barzilay
2019-10-29 19:12:39 -04:00
parent c84afa1b9e
commit d6bd3ac552
2 changed files with 30 additions and 2 deletions

View File

@@ -1826,8 +1826,14 @@ namespace ts.Completions {
if (canGetType) {
const typeForObject = typeChecker.getTypeAtLocation(objectLikeContainer);
if (!typeForObject) return GlobalsSearch.Fail;
// In a binding pattern, get only known properties. Everywhere else we will get all possible properties.
typeMembers = typeChecker.getPropertiesOfType(typeForObject).filter((symbol) => !(getDeclarationModifierFlagsFromSymbol(symbol) & ModifierFlags.NonPublicAccessibilityModifier));
// In a binding pattern, get only known properties (unless in the same scope).
// Everywhere else we will get all possible properties.
const containerClass = getContainingClass(objectLikeContainer);
typeMembers = typeChecker.getPropertiesOfType(typeForObject).filter(symbol =>
// either public
!(getDeclarationModifierFlagsFromSymbol(symbol) & ModifierFlags.NonPublicAccessibilityModifier)
// or we're in it
|| containerClass && contains(typeForObject.symbol.declarations, containerClass));
existingMembers = objectLikeContainer.elements;
}
}