Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f1fcd56

Browse files
committedOct 1, 2024·
More tests, only use computed name emit when all names are visible
1 parent 22c5c89 commit f1fcd56

File tree

44 files changed

+828
-168
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+828
-168
lines changed
 

‎src/compiler/checker.ts

+18-22
Original file line numberDiff line numberDiff line change
@@ -7211,29 +7211,25 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
72117211
function indexInfoToObjectComputedNamesOrSignatureDeclaration(indexInfo: IndexInfo, context: NodeBuilderContext, typeNode: TypeNode | undefined): [IndexSignatureDeclaration] | PropertySignature[] {
72127212
if (indexInfo.components) {
72137213
// 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);
72347216
});
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+
});
72377233
}
72387234
}
72397235
return [indexInfoToIndexSignatureDeclarationHelper(indexInfo, context, typeNode)];

‎tests/baselines/reference/FunctionDeclaration8_es6.types

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
=== FunctionDeclaration8_es6.ts ===
44
var v = { [yield]: foo }
5-
>v : { [yield]: any; }
6-
> : ^^ ^^^ ^^
7-
>{ [yield]: foo } : { [yield]: any; }
8-
> : ^^ ^^^ ^^
5+
>v : { [x: number]: any; }
6+
> : ^^^^^^^^^^^^^^^^^^^^^
7+
>{ [yield]: foo } : { [x: number]: any; }
8+
> : ^^^^^^^^^^^^^^^^^^^^^
99
>[yield] : any
1010
> : ^^^
1111
>yield : any

0 commit comments

Comments
 (0)
Please sign in to comment.