@@ -914,8 +914,8 @@ namespace ts {
914
914
}
915
915
}
916
916
917
- // If we're in an external module, we can't reference symbols created from UMD export declarations
918
- if (result && isInExternalModule) {
917
+ // If we're in an external module, we can't reference value symbols created from UMD export declarations
918
+ if (result && isInExternalModule && (meaning & SymbolFlags.Value) === SymbolFlags.Value ) {
919
919
const decls = result.declarations;
920
920
if (decls && decls.length === 1 && decls[0].kind === SyntaxKind.NamespaceExportDeclaration) {
921
921
error(errorLocation, Diagnostics.Identifier_0_must_be_imported_from_a_module, name);
@@ -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 reference to the symbol
1766
+ * @param meaning a SymbolFlags to check if such meaning of the symbol is accessible
1767
+ * @param shouldComputeAliasToMakeVisible 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, shouldComputeAliasToMakeVisible: boolean ): SymbolVisibilityResult {
1834
1842
let aliasesToMakeVisible: AnyImportSyntax[];
1835
1843
if (forEach(symbol.declarations, declaration => !getIsDeclarationVisible(declaration))) {
1836
1844
return undefined;
@@ -1846,14 +1854,19 @@ 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
+ // In function "buildTypeDisplay" where we decide whether to write type-alias or serialize types,
1858
+ // we want to just check if type- alias is accessible or not but we don't care about emitting those alias at that time
1859
+ // since we will do the emitting later in trackSymbol.
1860
+ if (shouldComputeAliasToMakeVisible) {
1861
+ getNodeLinks(declaration).isVisible = true;
1862
+ if (aliasesToMakeVisible) {
1863
+ if (!contains(aliasesToMakeVisible, anyImportSyntax)) {
1864
+ aliasesToMakeVisible.push(anyImportSyntax);
1865
+ }
1866
+ }
1867
+ else {
1868
+ aliasesToMakeVisible = [anyImportSyntax];
1853
1869
}
1854
- }
1855
- else {
1856
- aliasesToMakeVisible = [anyImportSyntax];
1857
1870
}
1858
1871
return true;
1859
1872
}
@@ -1888,7 +1901,7 @@ namespace ts {
1888
1901
const symbol = resolveName(enclosingDeclaration, (<Identifier>firstIdentifier).text, meaning, /*nodeNotFoundErrorMessage*/ undefined, /*nameArg*/ undefined);
1889
1902
1890
1903
// Verify if the symbol is accessible
1891
- return (symbol && hasVisibleDeclarations(symbol)) || <SymbolVisibilityResult>{
1904
+ return (symbol && hasVisibleDeclarations(symbol, /*shouldComputeAliasToMakeVisible*/ true )) || <SymbolVisibilityResult>{
1892
1905
accessibility: SymbolAccessibility.NotAccessible,
1893
1906
errorSymbolName: getTextOfNode(firstIdentifier),
1894
1907
errorNode: firstIdentifier
@@ -2163,7 +2176,9 @@ namespace ts {
2163
2176
// The specified symbol flags need to be reinterpreted as type flags
2164
2177
buildSymbolDisplay(type.symbol, writer, enclosingDeclaration, SymbolFlags.Type, SymbolFormatFlags.None, nextFlags);
2165
2178
}
2166
- else if (!(flags & TypeFormatFlags.InTypeAlias) && type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol) {
2179
+ else if (!(flags & TypeFormatFlags.InTypeAlias) && type.flags & (TypeFlags.Anonymous | TypeFlags.UnionOrIntersection) && type.aliasSymbol &&
2180
+ isSymbolAccessible(type.aliasSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false).accessibility === SymbolAccessibility.Accessible) {
2181
+ // Only write out inferred type with its corresponding type-alias if type-alias is visible
2167
2182
const typeArguments = type.aliasTypeArguments;
2168
2183
writeSymbolTypeReference(type.aliasSymbol, typeArguments, 0, typeArguments ? typeArguments.length : 0, nextFlags);
2169
2184
}
@@ -5653,12 +5668,13 @@ namespace ts {
5653
5668
case SyntaxKind.JSDocThisType:
5654
5669
case SyntaxKind.JSDocOptionalType:
5655
5670
return getTypeFromTypeNode((<ParenthesizedTypeNode | JSDocTypeReferencingNode>node).type);
5671
+ case SyntaxKind.JSDocRecordType:
5672
+ return getTypeFromTypeNode((node as JSDocRecordType).literal);
5656
5673
case SyntaxKind.FunctionType:
5657
5674
case SyntaxKind.ConstructorType:
5658
5675
case SyntaxKind.TypeLiteral:
5659
5676
case SyntaxKind.JSDocTypeLiteral:
5660
5677
case SyntaxKind.JSDocFunctionType:
5661
- case SyntaxKind.JSDocRecordType:
5662
5678
return getTypeFromTypeLiteralOrFunctionOrConstructorTypeNode(node, aliasSymbol, aliasTypeArguments);
5663
5679
// This function assumes that an identifier or qualified name is a type expression
5664
5680
// Callers should first ensure this by calling isTypeNode
0 commit comments