@@ -3856,16 +3856,21 @@ namespace ts {
3856
3856
}
3857
3857
3858
3858
function isTypeSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node | undefined): boolean {
3859
- const access = isSymbolAccessible (typeSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false);
3859
+ const access = isSymbolAccessibleWorker (typeSymbol, enclosingDeclaration, SymbolFlags.Type, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ true );
3860
3860
return access.accessibility === SymbolAccessibility.Accessible;
3861
3861
}
3862
3862
3863
3863
function isValueSymbolAccessible(typeSymbol: Symbol, enclosingDeclaration: Node | undefined): boolean {
3864
- const access = isSymbolAccessible (typeSymbol, enclosingDeclaration, SymbolFlags.Value, /*shouldComputeAliasesToMakeVisible*/ false);
3864
+ const access = isSymbolAccessibleWorker (typeSymbol, enclosingDeclaration, SymbolFlags.Value, /*shouldComputeAliasesToMakeVisible*/ false, /*allowModules*/ true );
3865
3865
return access.accessibility === SymbolAccessibility.Accessible;
3866
3866
}
3867
3867
3868
- function isAnySymbolAccessible(symbols: Symbol[] | undefined, enclosingDeclaration: Node | undefined, initialSymbol: Symbol, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean): SymbolAccessibilityResult | undefined {
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
+
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
3871
3876
let hadAccessibleChain: Symbol | undefined;
@@ -3880,7 +3885,7 @@ namespace ts {
3880
3885
return hasAccessibleDeclarations;
3881
3886
}
3882
3887
}
3883
- else {
3888
+ else if (allowModules) {
3884
3889
if (some(symbol.declarations, hasNonGlobalAugmentationExternalModuleSymbol)) {
3885
3890
if (shouldComputeAliasesToMakeVisible) {
3886
3891
earlyModuleBail = true;
@@ -3920,7 +3925,7 @@ namespace ts {
3920
3925
containers = [getSymbolOfNode(firstDecl.parent)];
3921
3926
}
3922
3927
}
3923
- const parentResult = isAnySymbolAccessible(containers, enclosingDeclaration, initialSymbol, initialSymbol === symbol ? getQualifiedLeftMeaning(meaning) : meaning, shouldComputeAliasesToMakeVisible);
3928
+ const parentResult = isAnySymbolAccessible(containers, enclosingDeclaration, initialSymbol, initialSymbol === symbol ? getQualifiedLeftMeaning(meaning) : meaning, shouldComputeAliasesToMakeVisible, allowModules );
3924
3929
if (parentResult) {
3925
3930
return parentResult;
3926
3931
}
@@ -3950,8 +3955,12 @@ namespace ts {
3950
3955
* @param shouldComputeAliasToMakeVisible a boolean value to indicate whether to return aliases to be mark visible in case the symbol is accessible
3951
3956
*/
3952
3957
function isSymbolAccessible(symbol: Symbol | undefined, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean): SymbolAccessibilityResult {
3958
+ return isSymbolAccessibleWorker(symbol, enclosingDeclaration, meaning, shouldComputeAliasesToMakeVisible, /*allowModules*/ true);
3959
+ }
3960
+
3961
+ function isSymbolAccessibleWorker(symbol: Symbol | undefined, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, shouldComputeAliasesToMakeVisible: boolean, allowModules: boolean): SymbolAccessibilityResult {
3953
3962
if (symbol && enclosingDeclaration) {
3954
- const result = isAnySymbolAccessible([symbol], enclosingDeclaration, symbol, meaning, shouldComputeAliasesToMakeVisible);
3963
+ const result = isAnySymbolAccessible([symbol], enclosingDeclaration, symbol, meaning, shouldComputeAliasesToMakeVisible, allowModules );
3955
3964
if (result) {
3956
3965
return result;
3957
3966
}
@@ -6211,7 +6220,7 @@ namespace ts {
6211
6220
const constructSignatures = serializeSignatures(SignatureKind.Construct, interfaceType, baseType, SyntaxKind.ConstructSignature) as ConstructSignatureDeclaration[];
6212
6221
const indexSignatures = serializeIndexSignatures(interfaceType, baseType);
6213
6222
6214
- const heritageClauses = !length(baseTypes) ? undefined : [createHeritageClause(SyntaxKind.ExtendsKeyword, mapDefined(baseTypes, b => trySerializeAsTypeReference(b)))];
6223
+ const heritageClauses = !length(baseTypes) ? undefined : [createHeritageClause(SyntaxKind.ExtendsKeyword, mapDefined(baseTypes, b => trySerializeAsTypeReference(b, SymbolFlags.Value )))];
6215
6224
addResult(createInterfaceDeclaration(
6216
6225
/*decorators*/ undefined,
6217
6226
/*modifiers*/ undefined,
@@ -6371,15 +6380,15 @@ namespace ts {
6371
6380
const typeParamDecls = map(localParams, p => typeParameterToDeclaration(p, context));
6372
6381
const classType = getDeclaredTypeOfClassOrInterface(symbol);
6373
6382
const baseTypes = getBaseTypes(classType);
6374
- const implementsTypes = getImplementsTypes(classType);
6383
+ const implementsExpressions = mapDefined( getImplementsTypes(classType), serializeImplementedType );
6375
6384
const staticType = getTypeOfSymbol(symbol);
6376
6385
const isClass = !!staticType.symbol?.valueDeclaration && isClassLike(staticType.symbol.valueDeclaration);
6377
6386
const staticBaseType = isClass
6378
6387
? getBaseConstructorTypeOfClass(staticType as InterfaceType)
6379
6388
: anyType;
6380
6389
const heritageClauses = [
6381
6390
...!length(baseTypes) ? [] : [createHeritageClause(SyntaxKind.ExtendsKeyword, map(baseTypes, b => serializeBaseType(b, staticBaseType, localName)))],
6382
- ...!length(implementsTypes ) ? [] : [createHeritageClause(SyntaxKind.ImplementsKeyword, map(implementsTypes, b => serializeBaseType(b, staticBaseType, localName)) )]
6391
+ ...!length(implementsExpressions ) ? [] : [createHeritageClause(SyntaxKind.ImplementsKeyword, implementsExpressions )]
6383
6392
];
6384
6393
const symbolProps = getNonInterhitedProperties(classType, baseTypes, getPropertiesOfType(classType));
6385
6394
const publicSymbolProps = filter(symbolProps, s => {
@@ -6870,7 +6879,7 @@ namespace ts {
6870
6879
}
6871
6880
6872
6881
function serializeBaseType(t: Type, staticType: Type, rootName: string) {
6873
- const ref = trySerializeAsTypeReference(t);
6882
+ const ref = trySerializeAsTypeReference(t, SymbolFlags.Value );
6874
6883
if (ref) {
6875
6884
return ref;
6876
6885
}
@@ -6882,23 +6891,34 @@ namespace ts {
6882
6891
return createExpressionWithTypeArguments(/*typeArgs*/ undefined, createIdentifier(tempName));
6883
6892
}
6884
6893
6885
- function trySerializeAsTypeReference(t: Type) {
6894
+ function trySerializeAsTypeReference(t: Type, flags: SymbolFlags ) {
6886
6895
let typeArgs: TypeNode[] | undefined;
6887
6896
let reference: Expression | undefined;
6897
+
6888
6898
// We don't use `isValueSymbolAccessible` below. since that considers alternative containers (like modules)
6889
6899
// which we can't write out in a syntactically valid way as an expression
6890
- if ((t as TypeReference).target && getAccessibleSymbolChain ((t as TypeReference).target.symbol, enclosingDeclaration, SymbolFlags.Value, /*useOnlyExternalAliasing*/ false )) {
6900
+ if ((t as TypeReference).target && isSymbolAccessibleByFlags ((t as TypeReference).target.symbol, enclosingDeclaration, flags )) {
6891
6901
typeArgs = map(getTypeArguments(t as TypeReference), t => typeToTypeNodeHelper(t, context));
6892
6902
reference = symbolToExpression((t as TypeReference).target.symbol, context, SymbolFlags.Type);
6893
6903
}
6894
- else if (t.symbol && getAccessibleSymbolChain (t.symbol, enclosingDeclaration, SymbolFlags.Value, /*useOnlyExternalAliasing*/ false )) {
6904
+ else if (t.symbol && isSymbolAccessibleByFlags (t.symbol, enclosingDeclaration, flags )) {
6895
6905
reference = symbolToExpression(t.symbol, context, SymbolFlags.Type);
6896
6906
}
6897
6907
if (reference) {
6898
6908
return createExpressionWithTypeArguments(typeArgs, reference);
6899
6909
}
6900
6910
}
6901
6911
6912
+ function serializeImplementedType(t: Type) {
6913
+ const ref = trySerializeAsTypeReference(t, SymbolFlags.Type);
6914
+ if (ref) {
6915
+ return ref;
6916
+ }
6917
+ if (t.symbol) {
6918
+ return createExpressionWithTypeArguments(/*typeArgs*/ undefined, symbolToExpression(t.symbol, context, SymbolFlags.Type));
6919
+ }
6920
+ }
6921
+
6902
6922
function getUnusedName(input: string, symbol?: Symbol): string {
6903
6923
if (symbol) {
6904
6924
if (context.remappedSymbolNames!.has("" + getSymbolId(symbol))) {
@@ -24063,7 +24083,7 @@ namespace ts {
24063
24083
// if jsx emit was not react as there wont be error being emitted
24064
24084
reactSym.isReferenced = SymbolFlags.All;
24065
24085
24066
- // If react symbol is alias, mark it as refereced
24086
+ // If react symbol is alias, mark it as referenced
24067
24087
if (reactSym.flags & SymbolFlags.Alias && !getTypeOnlyAliasDeclaration(reactSym)) {
24068
24088
markAliasSymbolAsReferenced(reactSym);
24069
24089
}
0 commit comments