@@ -1758,15 +1758,23 @@ namespace ts {
1758
1758
return false;
1759
1759
}
1760
1760
1761
- function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags): SymbolAccessibilityResult {
1761
+ /**
1762
+ * Check if the given symbol in given enclosing declaration is accessible and mark all associated alias to be visible if requested
1763
+ *
1764
+ * @param symbol a Symbol to check if accessible
1765
+ * @param enclosingDeclaration a Node containing the symbol
1766
+ * @param meaning a SymbolFlags to check if such meaning of the symbol is accessible
1767
+ * @param shouldComputeAliasToMarkVisible a boolean value to indicate whether to return aliases to be mark visible in case the symbol is accessible
1768
+ */
1769
+ function isSymbolAccessible(symbol: Symbol, enclosingDeclaration: Node, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean): SymbolAccessibilityResult {
1762
1770
if (symbol && enclosingDeclaration && !(symbol.flags & SymbolFlags.TypeParameter)) {
1763
1771
const initialSymbol = symbol;
1764
1772
let meaningToLook = meaning;
1765
1773
while (symbol) {
1766
1774
// Symbol is accessible if it by itself is accessible
1767
1775
const accessibleSymbolChain = getAccessibleSymbolChain(symbol, enclosingDeclaration, meaningToLook, /*useOnlyExternalAliasing*/ false);
1768
1776
if (accessibleSymbolChain) {
1769
- const hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0]);
1777
+ const hasAccessibleDeclarations = hasVisibleDeclarations(accessibleSymbolChain[0], shouldComputeAliasesToMakeVisible );
1770
1778
if (!hasAccessibleDeclarations) {
1771
1779
return <SymbolAccessibilityResult>{
1772
1780
accessibility: SymbolAccessibility.NotAccessible,
@@ -1830,7 +1838,7 @@ namespace ts {
1830
1838
return isAmbientModule(declaration) || (declaration.kind === SyntaxKind.SourceFile && isExternalOrCommonJsModule(<SourceFile>declaration));
1831
1839
}
1832
1840
1833
- function hasVisibleDeclarations(symbol: Symbol): SymbolVisibilityResult {
1841
+ function hasVisibleDeclarations(symbol: Symbol, shouldComputeAliasToMarkVisible: boolean ): SymbolVisibilityResult {
1834
1842
let aliasesToMakeVisible: AnyImportSyntax[];
1835
1843
if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) {
1836
1844
return undefined;
@@ -1846,14 +1854,16 @@ namespace ts {
1846
1854
if (anyImportSyntax &&
1847
1855
!(getModifierFlags(anyImportSyntax) & ModifierFlags.Export) && // import clause without export
1848
1856
isDeclarationVisible(<Declaration>anyImportSyntax.parent)) {
1849
- getNodeLinks(declaration).isVisible = true;
1850
- if (aliasesToMakeVisible) {
1851
- if (!contains(aliasesToMakeVisible, anyImportSyntax)) {
1852
- aliasesToMakeVisible.push(anyImportSyntax);
1857
+ if (shouldComputeAliasToMarkVisible) {
1858
+ getNodeLinks(declaration).isVisible = true;
1859
+ if (aliasesToMakeVisible) {
1860
+ if (!contains(aliasesToMakeVisible, anyImportSyntax)) {
1861
+ aliasesToMakeVisible.push(anyImportSyntax);
1862
+ }
1863
+ }
1864
+ else {
1865
+ aliasesToMakeVisible = [anyImportSyntax];
1853
1866
}
1854
- }
1855
- else {
1856
- aliasesToMakeVisible = [anyImportSyntax];
1857
1867
}
1858
1868
return true;
1859
1869
}
@@ -1888,7 +1898,7 @@ namespace ts {
1888
1898
const symbol = resolveName(enclosingDeclaration, (<Identifier>firstIdentifier).text, meaning, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
1889
1899
1890
1900
// Verify if the symbol is accessible
1891
- return (symbol && hasVisibleDeclarations(symbol)) || <SymbolVisibilityResult>{
1901
+ return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMarkVisible*/ true )) || <SymbolVisibilityResult>{
1892
1902
accessibility: SymbolAccessibility.NotAccessible,
1893
1903
errorSymbolName: getTextOfNode(firstIdentifier),
1894
1904
errorNode: firstIdentifier
@@ -2163,7 +2173,9 @@ namespace ts {
2163
2173
// The specified symbol flags need to be reinterpreted as type flags
2164
2174
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags);
2165
2175
}
2166
- else if (!(flags & TypeFormatFlags.InTypeAlias) && type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol) {
2176
+ else if (!(flags & TypeFormatFlags.InTypeAlias) && type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol &&
2177
+ isSymbolAccessible(type.aliasSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible) {
2178
+ // Only write out inferred type with its corresponding type-alias if type-alias is visible
2167
2179
const typeArguments = type.aliasTypeArguments;
2168
2180
writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, nextFlags);
2169
2181
}
0 commit comments