@@ -3855,8 +3855,8 @@ namespace ts {
3855
3855
return false;
3856
3856
}
3857
3857
3858
- function isTypeSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node | undefined, allowModules: boolean ): boolean {
3859
- const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false, allowModules);
3858
+ function isTypeSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node | undefined): boolean {
3859
+ const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false, /* allowModules*/ true );
3860
3860
return access.accessibility === SymbolAccessibility.Accessible;
3861
3861
}
3862
3862
@@ -3865,6 +3865,11 @@ namespace ts {
3865
3865
return access.accessibility === SymbolAccessibility.Accessible;
3866
3866
}
3867
3867
3868
+ function isSymbolAccessibleByFlags(typeSymbol: Symbol, enclosingDeclaration: Node | undefined, flags: SymbolFlags): boolean {
3869
+ const access = isSymbolAccessibleWorker(typeSymbol, enclosingDeclaration, flags, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ false);
3870
+ return access.accessibility === SymbolAccessibility.Accessible;
3871
+ }
3872
+
3868
3873
function isAnySymbolAccessible(symbols: Symbol[] | undefined, enclosingDeclaration: Node | undefined, initialSymbol: Symbol, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean, allowModules: boolean): SymbolAccessibilityResult | undefined {
3869
3874
if (!length(symbols)) return;
3870
3875
@@ -4335,7 +4340,7 @@ namespace ts {
4335
4340
return createThis();
4336
4341
}
4337
4342
4338
- if (!inTypeAlias && type.aliasSymbol && (context.flags & NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope || isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration, /*allowModules*/ true ))) {
4343
+ if (!inTypeAlias && type.aliasSymbol && (context.flags & NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope || isTypeSymbolAccessible(type.aliasSymbol, context.enclosingDeclaration))) {
4339
4344
const typeArgumentNodes = mapToTypeNodes(type.aliasTypeArguments, context);
4340
4345
if (isReservedMemberName(type.aliasSymbol.escapedName) && !(type.aliasSymbol.flags & SymbolFlags.Class)) return createTypeReferenceNode(createIdentifier(""), typeArgumentNodes);
4341
4346
return symbolToTypeNode(type.aliasSymbol, context, SymbolFlags.Type, typeArgumentNodes);
@@ -4354,7 +4359,7 @@ namespace ts {
4354
4359
}
4355
4360
if (context.flags & NodeBuilderFlags.GenerateNamesForShadowedTypeParams &&
4356
4361
type.flags & TypeFlags.TypeParameter &&
4357
- !isTypeSymbolAccessible(type.symbol, context.enclosingDeclaration, /*allowModules*/ true )) {
4362
+ !isTypeSymbolAccessible(type.symbol, context.enclosingDeclaration)) {
4358
4363
const name = typeParameterToName(type, context);
4359
4364
context.approximateLength += idText(name).length;
4360
4365
return createTypeReferenceNode(createIdentifier(idText(name)), /*typeArguments*/ undefined);
@@ -4602,7 +4607,7 @@ namespace ts {
4602
4607
else if (context.flags & NodeBuilderFlags.WriteClassExpressionAsTypeLiteral &&
4603
4608
type.symbol.valueDeclaration &&
4604
4609
isClassLike(type.symbol.valueDeclaration) &&
4605
- !isValueSymbolAccessible(type.symbol, context.enclosingDeclaration)
4610
+ !isValueSymbolAccessible(type.symbol, context.enclosingDeclaration)
4606
4611
) {
4607
4612
return createAnonymousTypeNode(type);
4608
4613
}
@@ -6126,7 +6131,7 @@ namespace ts {
6126
6131
const constructSignatures = serializeSignatures(SignatureKind.Construct, interfaceType, baseType, SyntaxKind.ConstructSignature) as ConstructSignatureDeclaration[];
6127
6132
const indexSignatures = serializeIndexSignatures(interfaceType, baseType);
6128
6133
6129
- const heritageClauses = !length(baseTypes) ? undefined : [createHeritageClause(SyntaxKind.ExtendsKeyword, mapDefined(baseTypes, b => trySerializeAsTypeReference(b)))];
6134
+ const heritageClauses = !length(baseTypes) ? undefined : [createHeritageClause(SyntaxKind.ExtendsKeyword, mapDefined(baseTypes, b => trySerializeAsTypeReference(b, SymbolFlags.Value )))];
6130
6135
addResult(createInterfaceDeclaration(
6131
6136
/*decorators*/ undefined,
6132
6137
/*modifiers*/ undefined,
@@ -6833,7 +6838,7 @@ namespace ts {
6833
6838
}
6834
6839
6835
6840
function serializeBaseType(t: Type, staticType: Type, rootName: string) {
6836
- const ref = trySerializeAsTypeReference(t);
6841
+ const ref = trySerializeAsTypeReference(t, SymbolFlags.Value );
6837
6842
if (ref) {
6838
6843
return ref;
6839
6844
}
@@ -6845,16 +6850,17 @@ namespace ts {
6845
6850
return createExpressionWithTypeArguments(/*typeArgs*/ undefined, createIdentifier(tempName));
6846
6851
}
6847
6852
6848
- function trySerializeAsTypeReference(t: Type) {
6853
+ function trySerializeAsTypeReference(t: Type, flags: SymbolFlags ) {
6849
6854
let typeArgs: TypeNode[] | undefined;
6850
6855
let reference: Expression | undefined;
6856
+
6851
6857
// We don't use `isValueSymbolAccessible` below. since that considers alternative containers (like modules)
6852
6858
// which we can't write out in a syntactically valid way as an expression
6853
- if ((t as TypeReference).target && getAccessibleSymbolChain ((t as TypeReference).target.symbol, enclosingDeclaration, SymbolFlags.Value, /*useOnlyExternalAliasing*/ false )) {
6859
+ if ((t as TypeReference).target && isSymbolAccessibleByFlags ((t as TypeReference).target.symbol, enclosingDeclaration, flags )) {
6854
6860
typeArgs = map(getTypeArguments(t as TypeReference), t => typeToTypeNodeHelper(t, context));
6855
6861
reference = symbolToExpression((t as TypeReference).target.symbol, context, SymbolFlags.Type);
6856
6862
}
6857
- else if (t.symbol && getAccessibleSymbolChain (t.symbol, enclosingDeclaration, SymbolFlags.Value, /*useOnlyExternalAliasing*/ false )) {
6863
+ else if (t.symbol && isSymbolAccessibleByFlags (t.symbol, enclosingDeclaration, flags )) {
6858
6864
reference = symbolToExpression(t.symbol, context, SymbolFlags.Type);
6859
6865
}
6860
6866
if (reference) {
@@ -6863,25 +6869,11 @@ namespace ts {
6863
6869
}
6864
6870
6865
6871
function serializeImplementedType(t: Type) {
6866
- let typeArgs: TypeNode[] | undefined;
6867
- let reference: Expression | undefined;
6868
- if ((t as TypeReference).target && isTypeSymbolAccessible((t as TypeReference).target.symbol, enclosingDeclaration, /*allowModules*/ false)) {
6869
- typeArgs = map(getTypeArguments(t as TypeReference), t => typeToTypeNodeHelper(t, context));
6870
- reference = symbolToExpression((t as TypeReference).target.symbol, context, SymbolFlags.Type);
6871
- }
6872
- else if (t.symbol && isTypeSymbolAccessible(t.symbol, enclosingDeclaration, /*allowModules*/ false)) {
6873
- reference = symbolToExpression(t.symbol, context, SymbolFlags.Type);
6874
- }
6875
- if (reference) {
6876
- return createExpressionWithTypeArguments(typeArgs, reference);
6877
- }
6878
- else if (context.tracker.reportInaccessibleBaseType) {
6879
- context.tracker.reportInaccessibleBaseType();
6880
- return createExpressionWithTypeArguments(/*typeArgs*/ undefined, symbolToExpression(t.symbol, context, SymbolFlags.Type));
6881
- }
6882
- else {
6883
- Debug.fail("context.tracker missing some error reporting methods");
6872
+ const ref = trySerializeAsTypeReference(t, SymbolFlags.Type);
6873
+ if (ref) {
6874
+ return ref;
6884
6875
}
6876
+ return createExpressionWithTypeArguments(/*typeArgs*/ undefined, symbolToExpression(t.symbol, context, SymbolFlags.Type));
6885
6877
}
6886
6878
6887
6879
function getUnusedName(input: string, symbol?: Symbol): string {
0 commit comments