mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-03-02 23:45:51 -06:00
Fixed a regression in declaration emit of computed non-dynamic names (#59110)
This commit is contained in:
parent
ded36b21ac
commit
65baa7df9d
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
@ -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;
|
||||
};
|
||||
}
|
||||
@ -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))
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
@ -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"
|
||||
> : ^^^^^^^^^
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
27
tests/cases/compiler/declarationEmitComputedPropertyName1.ts
Normal file
27
tests/cases/compiler/declarationEmitComputedPropertyName1.ts
Normal 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;
|
||||
};
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user