mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-07 14:34:35 -06:00
Object literals computed property names allow literal-typed expressions
This commit is contained in:
parent
c82881f36e
commit
ac58751b62
@ -13526,6 +13526,7 @@ namespace ts {
|
||||
for (let i = 0; i < node.properties.length; i++) {
|
||||
const memberDecl = node.properties[i];
|
||||
let member = memberDecl.symbol;
|
||||
let literalName: __String | undefined;
|
||||
if (memberDecl.kind === SyntaxKind.PropertyAssignment ||
|
||||
memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment ||
|
||||
isObjectLiteralMethod(memberDecl)) {
|
||||
@ -13536,6 +13537,12 @@ namespace ts {
|
||||
|
||||
let type: Type;
|
||||
if (memberDecl.kind === SyntaxKind.PropertyAssignment) {
|
||||
if (memberDecl.name.kind === SyntaxKind.ComputedPropertyName) {
|
||||
const t = checkComputedPropertyName(<ComputedPropertyName>memberDecl.name);
|
||||
if (t.flags & TypeFlags.Literal) {
|
||||
literalName = escapeLeadingUnderscores("" + (t as LiteralType).value);
|
||||
}
|
||||
}
|
||||
type = checkPropertyAssignment(<PropertyAssignment>memberDecl, checkMode);
|
||||
}
|
||||
else if (memberDecl.kind === SyntaxKind.MethodDeclaration) {
|
||||
@ -13552,7 +13559,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
typeFlags |= type.flags;
|
||||
const prop = createSymbol(SymbolFlags.Property | member.flags, member.escapedName);
|
||||
const prop = createSymbol(SymbolFlags.Property | member.flags, literalName || member.escapedName);
|
||||
if (inDestructuringPattern) {
|
||||
// If object literal is an assignment pattern and if the assignment pattern specifies a default value
|
||||
// for the property, make the property optional.
|
||||
@ -13562,7 +13569,7 @@ namespace ts {
|
||||
if (isOptional) {
|
||||
prop.flags |= SymbolFlags.Optional;
|
||||
}
|
||||
if (hasDynamicName(memberDecl)) {
|
||||
if (!literalName && hasDynamicName(memberDecl)) {
|
||||
patternWithComputedProperties = true;
|
||||
}
|
||||
}
|
||||
@ -13620,7 +13627,7 @@ namespace ts {
|
||||
checkNodeDeferred(memberDecl);
|
||||
}
|
||||
|
||||
if (hasDynamicName(memberDecl)) {
|
||||
if (!literalName && hasDynamicName(memberDecl)) {
|
||||
if (isNumericName(memberDecl.name)) {
|
||||
hasComputedNumberProperty = true;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user