Fixed a regression in declaration emit of computed non-dynamic names (#59110)

This commit is contained in:
Mateusz Burzyński 2024-07-09 20:21:52 +02:00 committed by GitHub
parent ded36b21ac
commit 65baa7df9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 232 additions and 1 deletions

View File

@ -8836,7 +8836,10 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
);
}
if (isNamedDeclaration(node) && node.name.kind === SyntaxKind.ComputedPropertyName && !isLateBindableName(node.name)) {
if (!(context.flags & NodeBuilderFlags.AllowUnresolvedNames && hasDynamicName(node) && isEntityNameExpression(node.name.expression) && checkComputedPropertyName(node.name).flags & TypeFlags.Any)) {
if (!hasDynamicName(node)) {
return visitEachChild(node, visitExistingNodeTreeSymbols);
}
if (!(context.flags & NodeBuilderFlags.AllowUnresolvedNames && isEntityNameExpression(node.name.expression) && checkComputedPropertyName(node.name).flags & TypeFlags.Any)) {
return undefined;
}
}

View File

@ -0,0 +1,49 @@
//// [tests/cases/compiler/declarationEmitComputedPropertyName1.ts] ////
//// [declarationEmitComputedPropertyName1.ts]
// https://github.com/microsoft/TypeScript/issues/59107
declare function create<T extends {}>(): T;
export const c = create<{
data: {
["a_b_c"]: string;
["sss"]: string;
s_d: string;
queryData?: string;
["foo bar"]: string;
};
["a_b_c"]: string;
}>();
export interface IData {
["a_b_c"]: string;
nested: {
["d_e_f"]: string;
value: string;
["qwe rty"]: string;
};
}
//// [declarationEmitComputedPropertyName1.d.ts]
export declare const c: {
data: {
["a_b_c"]: string;
["sss"]: string;
s_d: string;
queryData?: string;
["foo bar"]: string;
};
a_b_c: string;
};
export interface IData {
["a_b_c"]: string;
nested: {
["d_e_f"]: string;
value: string;
["qwe rty"]: string;
};
}

View File

@ -0,0 +1,66 @@
//// [tests/cases/compiler/declarationEmitComputedPropertyName1.ts] ////
=== declarationEmitComputedPropertyName1.ts ===
// https://github.com/microsoft/TypeScript/issues/59107
declare function create<T extends {}>(): T;
>create : Symbol(create, Decl(declarationEmitComputedPropertyName1.ts, 0, 0))
>T : Symbol(T, Decl(declarationEmitComputedPropertyName1.ts, 2, 24))
>T : Symbol(T, Decl(declarationEmitComputedPropertyName1.ts, 2, 24))
export const c = create<{
>c : Symbol(c, Decl(declarationEmitComputedPropertyName1.ts, 4, 12))
>create : Symbol(create, Decl(declarationEmitComputedPropertyName1.ts, 0, 0))
data: {
>data : Symbol(data, Decl(declarationEmitComputedPropertyName1.ts, 4, 25))
["a_b_c"]: string;
>["a_b_c"] : Symbol(["a_b_c"], Decl(declarationEmitComputedPropertyName1.ts, 5, 9))
>"a_b_c" : Symbol(["a_b_c"], Decl(declarationEmitComputedPropertyName1.ts, 5, 9))
["sss"]: string;
>["sss"] : Symbol(["sss"], Decl(declarationEmitComputedPropertyName1.ts, 6, 22))
>"sss" : Symbol(["sss"], Decl(declarationEmitComputedPropertyName1.ts, 6, 22))
s_d: string;
>s_d : Symbol(s_d, Decl(declarationEmitComputedPropertyName1.ts, 7, 20))
queryData?: string;
>queryData : Symbol(queryData, Decl(declarationEmitComputedPropertyName1.ts, 8, 16))
["foo bar"]: string;
>["foo bar"] : Symbol(["foo bar"], Decl(declarationEmitComputedPropertyName1.ts, 9, 23))
>"foo bar" : Symbol(["foo bar"], Decl(declarationEmitComputedPropertyName1.ts, 9, 23))
};
["a_b_c"]: string;
>["a_b_c"] : Symbol(["a_b_c"], Decl(declarationEmitComputedPropertyName1.ts, 11, 4))
>"a_b_c" : Symbol(["a_b_c"], Decl(declarationEmitComputedPropertyName1.ts, 11, 4))
}>();
export interface IData {
>IData : Symbol(IData, Decl(declarationEmitComputedPropertyName1.ts, 13, 5))
["a_b_c"]: string;
>["a_b_c"] : Symbol(IData["a_b_c"], Decl(declarationEmitComputedPropertyName1.ts, 15, 24))
>"a_b_c" : Symbol(IData["a_b_c"], Decl(declarationEmitComputedPropertyName1.ts, 15, 24))
nested: {
>nested : Symbol(IData.nested, Decl(declarationEmitComputedPropertyName1.ts, 16, 20))
["d_e_f"]: string;
>["d_e_f"] : Symbol(["d_e_f"], Decl(declarationEmitComputedPropertyName1.ts, 17, 11))
>"d_e_f" : Symbol(["d_e_f"], Decl(declarationEmitComputedPropertyName1.ts, 17, 11))
value: string;
>value : Symbol(value, Decl(declarationEmitComputedPropertyName1.ts, 18, 22))
["qwe rty"]: string;
>["qwe rty"] : Symbol(["qwe rty"], Decl(declarationEmitComputedPropertyName1.ts, 19, 18))
>"qwe rty" : Symbol(["qwe rty"], Decl(declarationEmitComputedPropertyName1.ts, 19, 18))
};
}

View File

@ -0,0 +1,86 @@
//// [tests/cases/compiler/declarationEmitComputedPropertyName1.ts] ////
=== declarationEmitComputedPropertyName1.ts ===
// https://github.com/microsoft/TypeScript/issues/59107
declare function create<T extends {}>(): T;
>create : <T extends {}>() => T
> : ^ ^^^^^^^^^ ^^^^^^^
export const c = create<{
>c : { data: { ["a_b_c"]: string; ["sss"]: string; s_d: string; queryData?: string; ["foo bar"]: string; }; a_b_c: string; }
> : ^^^^^^^^ ^^^^^^^^^ ^^^
>create<{ data: { ["a_b_c"]: string; ["sss"]: string; s_d: string; queryData?: string; ["foo bar"]: string; }; ["a_b_c"]: string;}>() : { data: { ["a_b_c"]: string; ["sss"]: string; s_d: string; queryData?: string; ["foo bar"]: string; }; a_b_c: string; }
> : ^^^^^^^^ ^^^^^^^^^ ^^^
>create : <T extends {}>() => T
> : ^ ^^^^^^^^^ ^^^^^^^
data: {
>data : { a_b_c: string; sss: string; s_d: string; queryData?: string; "foo bar": string; }
> : ^^^^^^^^^ ^^^^^^^ ^^^^^^^ ^^^^^^^^^^^^^^ ^^^^^^^^^^^^^ ^^^
["a_b_c"]: string;
>["a_b_c"] : string
> : ^^^^^^
>"a_b_c" : "a_b_c"
> : ^^^^^^^
["sss"]: string;
>["sss"] : string
> : ^^^^^^
>"sss" : "sss"
> : ^^^^^
s_d: string;
>s_d : string
> : ^^^^^^
queryData?: string;
>queryData : string | undefined
> : ^^^^^^^^^^^^^^^^^^
["foo bar"]: string;
>["foo bar"] : string
> : ^^^^^^
>"foo bar" : "foo bar"
> : ^^^^^^^^^
};
["a_b_c"]: string;
>["a_b_c"] : string
> : ^^^^^^
>"a_b_c" : "a_b_c"
> : ^^^^^^^
}>();
export interface IData {
["a_b_c"]: string;
>["a_b_c"] : string
> : ^^^^^^
>"a_b_c" : "a_b_c"
> : ^^^^^^^
nested: {
>nested : { d_e_f: string; value: string; "qwe rty": string; }
> : ^^^^^^^^^ ^^^^^^^^^ ^^^^^^^^^^^^^ ^^^
["d_e_f"]: string;
>["d_e_f"] : string
> : ^^^^^^
>"d_e_f" : "d_e_f"
> : ^^^^^^^
value: string;
>value : string
> : ^^^^^^
["qwe rty"]: string;
>["qwe rty"] : string
> : ^^^^^^
>"qwe rty" : "qwe rty"
> : ^^^^^^^^^
};
}

View File

@ -0,0 +1,27 @@
// @strict: true
// @declaration: true
// @emitDeclarationOnly: true
// https://github.com/microsoft/TypeScript/issues/59107
declare function create<T extends {}>(): T;
export const c = create<{
data: {
["a_b_c"]: string;
["sss"]: string;
s_d: string;
queryData?: string;
["foo bar"]: string;
};
["a_b_c"]: string;
}>();
export interface IData {
["a_b_c"]: string;
nested: {
["d_e_f"]: string;
value: string;
["qwe rty"]: string;
};
}