mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-17 21:06:50 -05:00
Merge remote-tracking branch 'origin/master' into moduleAugmentations
This commit is contained in:
@@ -5518,10 +5518,8 @@ namespace ts {
|
||||
};
|
||||
}
|
||||
|
||||
function isImportOrExportSpecifierImportSymbol(symbol: Symbol) {
|
||||
return (symbol.flags & SymbolFlags.Alias) && forEach(symbol.declarations, declaration => {
|
||||
return declaration.kind === SyntaxKind.ImportSpecifier || declaration.kind === SyntaxKind.ExportSpecifier;
|
||||
});
|
||||
function isImportSpecifierSymbol(symbol: Symbol) {
|
||||
return (symbol.flags & SymbolFlags.Alias) && !!getDeclarationOfKind(symbol, SyntaxKind.ImportSpecifier);
|
||||
}
|
||||
|
||||
function getInternedName(symbol: Symbol, location: Node, declarations: Declaration[]): string {
|
||||
@@ -5965,8 +5963,17 @@ namespace ts {
|
||||
let result = [symbol];
|
||||
|
||||
// If the symbol is an alias, add what it alaises to the list
|
||||
if (isImportOrExportSpecifierImportSymbol(symbol)) {
|
||||
result.push(typeChecker.getAliasedSymbol(symbol));
|
||||
if (isImportSpecifierSymbol(symbol)) {
|
||||
result.push(typeChecker.getAliasedSymbol(symbol));
|
||||
}
|
||||
|
||||
// For export specifiers, the exported name can be refering to a local symbol, e.g.:
|
||||
// import {a} from "mod";
|
||||
// export {a as somethingElse}
|
||||
// We want the *local* declaration of 'a' as declared in the import,
|
||||
// *not* as declared within "mod" (or farther)
|
||||
if (location.parent.kind === SyntaxKind.ExportSpecifier) {
|
||||
result.push(typeChecker.getExportSpecifierLocalTargetSymbol(<ExportSpecifier>location.parent));
|
||||
}
|
||||
|
||||
// If the location is in a context sensitive location (i.e. in an object literal) try
|
||||
@@ -6012,14 +6019,38 @@ namespace ts {
|
||||
|
||||
// Add symbol of properties/methods of the same name in base classes and implemented interfaces definitions
|
||||
if (rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
|
||||
getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result);
|
||||
getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result, /*previousIterationSymbolsCache*/ {});
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
function getPropertySymbolsFromBaseTypes(symbol: Symbol, propertyName: string, result: Symbol[]): void {
|
||||
/**
|
||||
* Find symbol of the given property-name and add the symbol to the given result array
|
||||
* @param symbol a symbol to start searching for the given propertyName
|
||||
* @param propertyName a name of property to serach for
|
||||
* @param result an array of symbol of found property symbols
|
||||
* @param previousIterationSymbolsCache a cache of symbol from previous iterations of calling this function to prevent infinite revisitng of the same symbol.
|
||||
* The value of previousIterationSymbol is undefined when the function is first called.
|
||||
*/
|
||||
function getPropertySymbolsFromBaseTypes(symbol: Symbol, propertyName: string, result: Symbol[],
|
||||
previousIterationSymbolsCache: SymbolTable): void {
|
||||
// If the current symbol is the same as the previous-iteration symbol, we can just return the symbol that has already been visited
|
||||
// This is particularly important for the following cases, so that we do not infinitely visit the same symbol.
|
||||
// For example:
|
||||
// interface C extends C {
|
||||
// /*findRef*/propName: string;
|
||||
// }
|
||||
// The first time getPropertySymbolsFromBaseTypes is called when finding-all-references at propName,
|
||||
// the symbol argument will be the symbol of an interface "C" and previousIterationSymbol is undefined,
|
||||
// the function will add any found symbol of the property-name, then its sub-routine will call
|
||||
// getPropertySymbolsFromBaseTypes again to walk up any base types to prevent revisiting already
|
||||
// visited symbol, interface "C", the sub-routine will pass the current symbol as previousIterationSymbol.
|
||||
if (hasProperty(previousIterationSymbolsCache, symbol.name)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (symbol && symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
|
||||
forEach(symbol.getDeclarations(), declaration => {
|
||||
if (declaration.kind === SyntaxKind.ClassDeclaration) {
|
||||
@@ -6043,7 +6074,8 @@ namespace ts {
|
||||
}
|
||||
|
||||
// Visit the typeReference as well to see if it directly or indirectly use that property
|
||||
getPropertySymbolsFromBaseTypes(type.symbol, propertyName, result);
|
||||
previousIterationSymbolsCache[symbol.name] = symbol;
|
||||
getPropertySymbolsFromBaseTypes(type.symbol, propertyName, result, previousIterationSymbolsCache);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6056,13 +6088,24 @@ namespace ts {
|
||||
|
||||
// If the reference symbol is an alias, check if what it is aliasing is one of the search
|
||||
// symbols.
|
||||
if (isImportOrExportSpecifierImportSymbol(referenceSymbol)) {
|
||||
if (isImportSpecifierSymbol(referenceSymbol)) {
|
||||
const aliasedSymbol = typeChecker.getAliasedSymbol(referenceSymbol);
|
||||
if (searchSymbols.indexOf(aliasedSymbol) >= 0) {
|
||||
return aliasedSymbol;
|
||||
}
|
||||
}
|
||||
|
||||
// For export specifiers, it can be a local symbol, e.g.
|
||||
// import {a} from "mod";
|
||||
// export {a as somethingElse}
|
||||
// We want the local target of the export (i.e. the import symbol) and not the final target (i.e. "mod".a)
|
||||
if (referenceLocation.parent.kind === SyntaxKind.ExportSpecifier) {
|
||||
const aliasedSymbol = typeChecker.getExportSpecifierLocalTargetSymbol(<ExportSpecifier>referenceLocation.parent);
|
||||
if (searchSymbols.indexOf(aliasedSymbol) >= 0) {
|
||||
return aliasedSymbol;
|
||||
}
|
||||
}
|
||||
|
||||
// If the reference location is in an object literal, try to get the contextual type for the
|
||||
// object literal, lookup the property symbol in the contextual type, and use this symbol to
|
||||
// compare to our searchSymbol
|
||||
@@ -6084,7 +6127,7 @@ namespace ts {
|
||||
// see if any is in the list
|
||||
if (rootSymbol.parent && rootSymbol.parent.flags & (SymbolFlags.Class | SymbolFlags.Interface)) {
|
||||
const result: Symbol[] = [];
|
||||
getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result);
|
||||
getPropertySymbolsFromBaseTypes(rootSymbol.parent, rootSymbol.getName(), result, /*previousIterationSymbolsCache*/ {});
|
||||
return forEach(result, s => searchSymbols.indexOf(s) >= 0 ? s : undefined);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user