findAllReferences: Type parameter is not globally visible (#16419)

* findAllReferences: Type parameter is not globally visible

* Add test for merged interface

* Clean up comment
This commit is contained in:
Andy 2017-08-09 13:53:54 -07:00 committed by GitHub
parent 39e0cc61a7
commit e73d58e21c
2 changed files with 16 additions and 5 deletions

View file

@ -652,10 +652,15 @@ namespace ts.FindAllReferences.Core {
return undefined;
}
// If the symbol has a parent, it's globally visible.
// Unless that parent is an external module, then we should only search in the module (and recurse on the export later).
// But if the parent is a module that has `export as namespace`, then the symbol *is* globally visible.
if (parent && !((parent.flags & SymbolFlags.Module) && isExternalModuleSymbol(parent) && !parent.globalExports)) {
/*
If the symbol has a parent, it's globally visible unless:
- It's a private property (handled above).
- It's a type parameter.
- The parent is an external module: then we should only search in the module (and recurse on the export later).
- But if the parent has `export as namespace`, the symbol is globally visible through that namespace.
*/
const exposedByParent = parent && !(symbol.flags & SymbolFlags.TypeParameter);
if (exposedByParent && !((parent.flags & SymbolFlags.Module) && isExternalModuleSymbol(parent) && !parent.globalExports)) {
return undefined;
}
@ -682,7 +687,7 @@ namespace ts.FindAllReferences.Core {
// declare module "a" { export type T = number; }
// declare module "b" { import { T } from "a"; export const x: T; }
// So we must search the whole source file. (Because we will mark the source file as seen, we we won't return to it when searching for imports.)
return parent ? scope.getSourceFile() : scope;
return exposedByParent ? scope.getSourceFile() : scope;
}
function getPossibleSymbolReferencePositions(sourceFile: SourceFile, symbolName: string, container: Node = sourceFile): number[] {

View file

@ -0,0 +1,6 @@
/// <reference path='fourslash.ts' />
////interface I<[|{| "isWriteAccess": true, "isDefinition": true |}T|]> { a: [|T|] }
////interface I<[|{| "isWriteAccess": true, "isDefinition": true |}T|]> { b: [|T|] }
verify.singleReferenceGroup("(type parameter) T in I<T>");