Allow isSymbolAccessible to paint object literal declarations as visible (#24668)

* Dont use resolveEntityName for computed property name symbol resolution - use checkExpression and resolvedSymbol instead

* Fix lint
This commit is contained in:
Wesley Wigham
2018-09-05 14:52:47 -07:00
committed by GitHub
parent 69c7e67c88
commit 0b1183a461
5 changed files with 90 additions and 1 deletions

View File

@@ -2871,7 +2871,18 @@ namespace ts {
// we are going to see if c can be accessed in scope directly.
// But it can't, hence the accessible is going to be undefined, but that doesn't mean m.c is inaccessible
// It is accessible if the parent m is accessible because then m.c can be accessed through qualification
const parentResult = isAnySymbolAccessible(getContainersOfSymbol(symbol, enclosingDeclaration), enclosingDeclaration, initialSymbol, initialSymbol === symbol ? getQualifiedLeftMeaning(meaning) : meaning, shouldComputeAliasesToMakeVisible);
let containers = getContainersOfSymbol(symbol, enclosingDeclaration);
// If we're trying to reference some object literal in, eg `var a = { x: 1 }`, the symbol for the literal, `__object`, is distinct
// from the symbol of the declaration it is being assigned to. Since we can use the declaration to refer to the literal, however,
// we'd like to make that connection here - potentially causing us to paint the declararation's visibiility, and therefore the literal.
const firstDecl: Node = first(symbol.declarations);
if (!length(containers) && meaning & SymbolFlags.Value && firstDecl && isObjectLiteralExpression(firstDecl)) {
if (firstDecl.parent && isVariableDeclaration(firstDecl.parent) && firstDecl === firstDecl.parent.initializer) {
containers = [getSymbolOfNode(firstDecl.parent)];
}
}
const parentResult = isAnySymbolAccessible(containers, enclosingDeclaration, initialSymbol, initialSymbol === symbol ? getQualifiedLeftMeaning(meaning) : meaning, shouldComputeAliasesToMakeVisible);
if (parentResult) {
return parentResult;
}