mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
support getReferences on object literals
This commit is contained in:
@@ -51,7 +51,8 @@ module ts {
|
||||
getTypeOfExpression: getTypeOfExpression,
|
||||
typeToString: typeToString,
|
||||
symbolToString: symbolToString,
|
||||
getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType
|
||||
getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType,
|
||||
getRootSymbol: getRootSymbol
|
||||
};
|
||||
|
||||
var undefinedSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Transient, "undefined");
|
||||
@@ -3118,6 +3119,7 @@ module ts {
|
||||
symbol.declarations = p.declarations;
|
||||
symbol.parent = p.parent;
|
||||
symbol.type = widenedTypes[index++];
|
||||
symbol.target = p;
|
||||
if (p.valueDeclaration) symbol.valueDeclaration = p.valueDeclaration;
|
||||
members[symbol.name] = symbol;
|
||||
});
|
||||
@@ -3790,6 +3792,7 @@ module ts {
|
||||
prop.parent = member.parent;
|
||||
if (member.valueDeclaration) prop.valueDeclaration = member.valueDeclaration;
|
||||
prop.type = type;
|
||||
prop.target = member;
|
||||
member = prop;
|
||||
}
|
||||
else {
|
||||
@@ -6672,6 +6675,10 @@ module ts {
|
||||
}
|
||||
}
|
||||
|
||||
function getRootSymbol(symbol: Symbol) {
|
||||
return (symbol.flags & SymbolFlags.Transient) ? getSymbolLinks(symbol).target : symbol;
|
||||
}
|
||||
|
||||
// Emitter support
|
||||
|
||||
function isExternalModuleSymbol(symbol: Symbol): boolean {
|
||||
|
||||
@@ -609,6 +609,7 @@ module ts {
|
||||
typeToString(type: Type, enclosingDeclaration?: Node, flags?: TypeFormatFlags): string;
|
||||
symbolToString(symbol: Symbol, enclosingDeclaration?: Node, meaning?: SymbolFlags): string;
|
||||
getAugmentedPropertiesOfApparentType(type: Type): Symbol[];
|
||||
getRootSymbol(symbol:Symbol): Symbol;
|
||||
}
|
||||
|
||||
export interface TextWriter {
|
||||
|
||||
@@ -2123,7 +2123,7 @@ module ts {
|
||||
return getLabelReferencesInNode(labelScope, labelName);
|
||||
}
|
||||
|
||||
var symbol = typeChecker.getSymbolInfo(node);
|
||||
var symbol = typeInfoResolver.getSymbolInfo(node);
|
||||
|
||||
// Could not find a symbol e.g. unknown identifier
|
||||
if (!symbol) {
|
||||
@@ -2253,7 +2253,7 @@ module ts {
|
||||
return;
|
||||
}
|
||||
|
||||
var symbol = typeChecker.getSymbolInfo(node);
|
||||
var symbol = typeInfoResolver.getSymbolInfo(node);
|
||||
|
||||
// Could not find a symbol e.g. node is string or number keyword,
|
||||
// or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
|
||||
@@ -2261,14 +2261,14 @@ module ts {
|
||||
return;
|
||||
}
|
||||
|
||||
if (compareSymbolsForLexicalIdentity(searchSymbol, symbol)) {
|
||||
if (compareSymbolsForLexicalIdentity(searchSymbol, symbol, node)) {
|
||||
result.push(getReferenceEntry(node));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function compareSymbolsForLexicalIdentity(firstSymbol: Symbol, secondSymbol: Symbol): boolean {
|
||||
function compareSymbolsForLexicalIdentity(searchSymbol: Symbol, symbol: Symbol, node: Node): boolean {
|
||||
//// Unwrap modules so that we're always referring to the variable.
|
||||
//if (!firstSymbol.isAlias() && firstSymbol.isContainer()) {
|
||||
// var containerForFirstSymbol = (<TypeScript.PullContainerSymbol>firstSymbol);
|
||||
@@ -2384,7 +2384,12 @@ module ts {
|
||||
// }
|
||||
//}
|
||||
|
||||
return firstSymbol === secondSymbol;
|
||||
var searchSymbolTarget = typeInfoResolver.getRootSymbol(searchSymbol);
|
||||
var symbolTarget = typeInfoResolver.getRootSymbol(symbol);
|
||||
|
||||
if (searchSymbolTarget === symbolTarget) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
function getReferenceEntry(node: Node): ReferenceEntry {
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
// References to an object literal property
|
||||
|
||||
////var x = { /*1*/add: 0, b: "string" };
|
||||
////x["add"];
|
||||
////x./*2*/add;
|
||||
////var y = x;
|
||||
////y.add;
|
||||
|
||||
goTo.marker("1");
|
||||
verify.referencesCountIs(4);
|
||||
|
||||
goTo.marker("2");
|
||||
verify.referencesCountIs(4);
|
||||
@@ -0,0 +1,15 @@
|
||||
/// <reference path='fourslash.ts'/>
|
||||
|
||||
////interface IFoo<T> {
|
||||
//// /*1*/doSomething(v: T): T;
|
||||
////}
|
||||
////
|
||||
////var x: IFoo<string>;
|
||||
////x.doSomething("ss");
|
||||
////
|
||||
////var y: IFoo<number>;
|
||||
////y.doSomething(12);
|
||||
|
||||
|
||||
goTo.marker("1");
|
||||
verify.referencesCountIs(3);
|
||||
Reference in New Issue
Block a user