Set syntheticLiteralTypeOrigin on synthetic undefined
-type members (#22216)
* Have getNameOfSymbolAsWritten quote nonidentifier nonnumeric symbols all the time * Revert checker changes * Reuse synthetic origin to indicate that derived declaration name may need to be quoted
This commit is contained in:
parent
1a43ad01a7
commit
b8e0009c9b
|
@ -11150,6 +11150,10 @@ namespace ts {
|
|||
}
|
||||
const result = createSymbol(SymbolFlags.Property | SymbolFlags.Optional, name);
|
||||
result.type = undefinedType;
|
||||
const associatedKeyType = getLiteralType(unescapeLeadingUnderscores(name));
|
||||
if (associatedKeyType.flags & TypeFlags.StringLiteral) {
|
||||
result.syntheticLiteralTypeOrigin = associatedKeyType as StringLiteralType;
|
||||
}
|
||||
undefinedProperties.set(name, result);
|
||||
return result;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
//// [inferredNonidentifierTypesGetQuotes.ts]
|
||||
var x = [{ "a-b": "string" }, {}];
|
||||
|
||||
var y = [{ ["a-b"]: "string" }, {}];
|
||||
|
||||
//// [inferredNonidentifierTypesGetQuotes.js]
|
||||
var x = [{ "a-b": "string" }, {}];
|
||||
var y = [(_a = {}, _a["a-b"] = "string", _a), {}];
|
||||
var _a;
|
||||
|
||||
|
||||
//// [inferredNonidentifierTypesGetQuotes.d.ts]
|
||||
declare var x: ({
|
||||
"a-b": string;
|
||||
} | {
|
||||
"a-b"?: undefined;
|
||||
})[];
|
||||
declare var y: ({
|
||||
["a-b"]: string;
|
||||
} | {
|
||||
"a-b"?: undefined;
|
||||
})[];
|
|
@ -0,0 +1,10 @@
|
|||
=== tests/cases/compiler/inferredNonidentifierTypesGetQuotes.ts ===
|
||||
var x = [{ "a-b": "string" }, {}];
|
||||
>x : Symbol(x, Decl(inferredNonidentifierTypesGetQuotes.ts, 0, 3))
|
||||
>"a-b" : Symbol("a-b", Decl(inferredNonidentifierTypesGetQuotes.ts, 0, 10))
|
||||
|
||||
var y = [{ ["a-b"]: "string" }, {}];
|
||||
>y : Symbol(y, Decl(inferredNonidentifierTypesGetQuotes.ts, 2, 3))
|
||||
>["a-b"] : Symbol(["a-b"], Decl(inferredNonidentifierTypesGetQuotes.ts, 2, 10))
|
||||
>"a-b" : Symbol(["a-b"], Decl(inferredNonidentifierTypesGetQuotes.ts, 2, 10))
|
||||
|
|
@ -0,0 +1,18 @@
|
|||
=== tests/cases/compiler/inferredNonidentifierTypesGetQuotes.ts ===
|
||||
var x = [{ "a-b": "string" }, {}];
|
||||
>x : ({ "a-b": string; } | { "a-b"?: undefined; })[]
|
||||
>[{ "a-b": "string" }, {}] : ({ "a-b": string; } | {})[]
|
||||
>{ "a-b": "string" } : { "a-b": string; }
|
||||
>"a-b" : string
|
||||
>"string" : "string"
|
||||
>{} : {}
|
||||
|
||||
var y = [{ ["a-b"]: "string" }, {}];
|
||||
>y : ({ ["a-b"]: string; } | { "a-b"?: undefined; })[]
|
||||
>[{ ["a-b"]: "string" }, {}] : ({ ["a-b"]: string; } | {})[]
|
||||
>{ ["a-b"]: "string" } : { ["a-b"]: string; }
|
||||
>["a-b"] : string
|
||||
>"a-b" : "a-b"
|
||||
>"string" : "string"
|
||||
>{} : {}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
// @declaration: true
|
||||
var x = [{ "a-b": "string" }, {}];
|
||||
|
||||
var y = [{ ["a-b"]: "string" }, {}];
|
Loading…
Reference in a new issue