Filter protected members from the completion list

This commit is contained in:
Mohamed Hegazy
2014-09-26 14:37:17 -07:00
parent 3e08af41fe
commit 8089673066
13 changed files with 512 additions and 14 deletions
+21 -1
View File
@@ -92,7 +92,8 @@ module ts {
getContextualType: getContextualType,
getFullyQualifiedName: getFullyQualifiedName,
getResolvedSignature: getResolvedSignature,
getEnumMemberValue: getEnumMemberValue
getEnumMemberValue: getEnumMemberValue,
isValidPropertyAccess: isValidPropertyAccess
};
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
@@ -4239,6 +4240,25 @@ module ts {
return anyType;
}
function isValidPropertyAccess(node: PropertyAccess, propertyName: string): boolean {
var type = checkExpression(node.left);
if (type !== unknownType && type !== anyType) {
var apparentType = getApparentType(getWidenedType(type));
var prop = getPropertyOfApparentType(apparentType, propertyName);
if (prop && prop.parent && prop.parent.flags & SymbolFlags.Class) {
if (node.left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) {
return false;
}
else {
var diagnosticsCount = diagnostics.length;
checkClassPropertyAccess(node, type, prop);
return diagnostics.length === diagnosticsCount
}
}
}
return true;
}
function checkIndexedAccess(node: IndexedAccess): Type {
var objectType = checkExpression(node.object);
var indexType = checkExpression(node.index);
+2
View File
@@ -655,6 +655,8 @@ module ts {
// Returns the constant value of this enum member, or 'undefined' if the enum member has a
// computed value.
getEnumMemberValue(node: EnumMember): number;
isValidPropertyAccess(node: PropertyAccess, propertyName: string): boolean;
}
export interface TextWriter {
+2 -12
View File
@@ -2038,15 +2038,6 @@ module ts {
return (SyntaxKind.FirstPunctuation <= kind && kind <= SyntaxKind.LastPunctuation);
}
function isVisibleWithinClassDeclaration(symbol: Symbol, containingClass: Declaration): boolean {
var declaration = symbol.declarations && symbol.declarations[0];
if (declaration && (declaration.flags & NodeFlags.Private)) {
var declarationClass = getAncestor(declaration, SyntaxKind.ClassDeclaration);
return containingClass === declarationClass;
}
return true;
}
function filterContextualMembersList(contextualMemberSymbols: Symbol[], existingMembers: Declaration[]): Symbol[] {
if (!existingMembers || existingMembers.length === 0) {
return contextualMemberSymbols;
@@ -2150,7 +2141,6 @@ module ts {
// Right of dot member completion list
if (isRightOfDot) {
var symbols: Symbol[] = [];
var containingClass = getAncestor(mappedNode, SyntaxKind.ClassDeclaration);
isMemberCompletion = true;
if (mappedNode.kind === SyntaxKind.Identifier || mappedNode.kind === SyntaxKind.QualifiedName || mappedNode.kind === SyntaxKind.PropertyAccess) {
@@ -2158,7 +2148,7 @@ module ts {
if (symbol && symbol.flags & SymbolFlags.HasExports) {
// Extract module or enum members
forEachValue(symbol.exports, symbol => {
if (isVisibleWithinClassDeclaration(symbol, containingClass)) {
if (typeInfoResolver.isValidPropertyAccess(<PropertyAccess>(mappedNode.parent), symbol.name)) {
symbols.push(symbol);
}
});
@@ -2170,7 +2160,7 @@ module ts {
if (apparentType) {
// Filter private properties
forEach(apparentType.getApparentProperties(), symbol => {
if (isVisibleWithinClassDeclaration(symbol, containingClass)) {
if (typeInfoResolver.isValidPropertyAccess(<PropertyAccess>(mappedNode.parent), symbol.name)) {
symbols.push(symbol);
}
});