Skip to content
Merged
Prev Previous commit
Next Next commit
Modify node builder to have the same unresolved computed name retaini…
…ng behavior
  • Loading branch information
weswigham committed May 4, 2024
commit 02b65ac096f520f2e6080e1dfdfaa8ac6165b264
4 changes: 3 additions & 1 deletion src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8459,7 +8459,9 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
);
}
if (isNamedDeclaration(node) && node.name.kind === SyntaxKind.ComputedPropertyName && !isLateBindableName(node.name)) {
return undefined;
if (!(context.flags & NodeBuilderFlags.AllowUnresolvedComputedNames && hasDynamicName(node) && isEntityNameExpression(node.name.expression) && checkComputedPropertyName(node.name).flags & TypeFlags.Any)) {
return undefined;
}
}
if (
(isFunctionLike(node) && !node.type)
Expand Down
1 change: 1 addition & 0 deletions src/compiler/transformers/declarations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ const declarationEmitNodeBuilderFlags = NodeBuilderFlags.MultilineObjectLiterals
NodeBuilderFlags.UseTypeOfFunction |
NodeBuilderFlags.UseStructuralFallback |
NodeBuilderFlags.AllowEmptyTuple |
NodeBuilderFlags.AllowUnresolvedComputedNames |
NodeBuilderFlags.GenerateNamesForShadowedTypeParams |
NodeBuilderFlags.NoTruncation;

Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5433,6 +5433,7 @@ export const enum NodeBuilderFlags {
// Errors (cont.)
AllowNodeModulesRelativePaths = 1 << 26,
/** @internal */ DoNotIncludeSymbolChain = 1 << 27, // Skip looking up and printing an accessible symbol chain
/** @internal */ AllowUnresolvedComputedNames = 1 << 32,

IgnoreErrors = AllowThisInObjectLiteral | AllowQualifiedNameInPlaceOfIdentifier | AllowAnonymousIdentifier | AllowEmptyUnionOrIntersection | AllowEmptyTuple | AllowEmptyIndexInfoType | AllowNodeModulesRelativePaths,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ import {Foo} from './a';
export type Bar = {
[Foo.A]: 1;
[Foo.B]: 2;
}
}

export const valBar = null as any as {
[Foo.A]: 1;
[Foo.B]: 2;
};
//// [declarationTypeWithComputedName.d.ts] ////
import { Foo } from './a';
export type Bar = {
[Foo.A]: 1;
[Foo.B]: 2;
};
export declare const valBar: {
[Foo.A]: 1;
[Foo.B]: 2;
};
7 changes: 6 additions & 1 deletion tests/cases/transpile/declarationTypeWithComputedName.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,9 @@ import {Foo} from './a';
export type Bar = {
[Foo.A]: 1;
[Foo.B]: 2;
}
}

export const valBar = null as any as {
[Foo.A]: 1;
[Foo.B]: 2;
};