@@ -7211,29 +7211,25 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
7211
7211
function indexInfoToObjectComputedNamesOrSignatureDeclaration(indexInfo: IndexInfo, context: NodeBuilderContext, typeNode: TypeNode | undefined): [IndexSignatureDeclaration] | PropertySignature[] {
7212
7212
if (indexInfo.components) {
7213
7213
// Index info is derived from object or class computed property names (plus explicit named members) - we can clone those instead of writing out the result computed index signature
7214
- let unusableResult = false;
7215
- const result = map(indexInfo.components, e => {
7216
- if (e.name && isComputedPropertyName(e.name) && isEntityNameExpression(e.name.expression)) {
7217
- trackComputedName(e.name.expression, context.enclosingDeclaration, context);
7218
- }
7219
- else {
7220
- // Computed name didn't take the form `[a.b.c]: something` - bail on using the computed name.
7221
- // TODO: Issue isolated declarations error on this fallback?
7222
- unusableResult = true;
7223
- }
7224
- return setTextRange(
7225
- context,
7226
- factory.createPropertySignature(
7227
- indexInfo.isReadonly ? [factory.createModifier(SyntaxKind.ReadonlyKeyword)] : undefined,
7228
- e.name,
7229
- /*questionToken*/ undefined,
7230
- typeNode || typeToTypeNodeHelper(getTypeOfSymbol(e.symbol), context),
7231
- ),
7232
- e,
7233
- );
7214
+ const allComponentComputedNamesSerializable = every(indexInfo.components, e => {
7215
+ return !!(e.name && isComputedPropertyName(e.name) && isEntityNameExpression(e.name.expression) && context.enclosingDeclaration && isEntityNameVisible(e.name.expression, context.enclosingDeclaration, /*shouldComputeAliasToMakeVisible*/ false)?.accessibility === SymbolAccessibility.Accessible);
7234
7216
});
7235
- if (!unusableResult) {
7236
- return result;
7217
+ if (allComponentComputedNamesSerializable) {
7218
+ // Only use computed name serialization form if all components are visible and take the `a.b.c` form
7219
+ return map(indexInfo.components, e => {
7220
+ // Still need to track visibility even if we've already checked it to paint references as used
7221
+ trackComputedName(e.name.expression as EntityNameExpression, context.enclosingDeclaration, context);
7222
+ return setTextRange(
7223
+ context,
7224
+ factory.createPropertySignature(
7225
+ indexInfo.isReadonly ? [factory.createModifier(SyntaxKind.ReadonlyKeyword)] : undefined,
7226
+ e.name,
7227
+ /*questionToken*/ undefined,
7228
+ typeNode || typeToTypeNodeHelper(getTypeOfSymbol(e.symbol), context),
7229
+ ),
7230
+ e,
7231
+ );
7232
+ });
7237
7233
}
7238
7234
}
7239
7235
return [indexInfoToIndexSignatureDeclarationHelper(indexInfo, context, typeNode)];
0 commit comments