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++) {
|
for (let i = 0; i < node.properties.length; i++) {
|
||||||
const memberDecl = node.properties[i];
|
const memberDecl = node.properties[i];
|
||||||
let member = memberDecl.symbol;
|
let member = memberDecl.symbol;
|
||||||
|
let literalName: __String | undefined;
|
||||||
if (memberDecl.kind === SyntaxKind.PropertyAssignment ||
|
if (memberDecl.kind === SyntaxKind.PropertyAssignment ||
|
||||||
memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment ||
|
memberDecl.kind === SyntaxKind.ShorthandPropertyAssignment ||
|
||||||
isObjectLiteralMethod(memberDecl)) {
|
isObjectLiteralMethod(memberDecl)) {
|
||||||
|
@ -13536,6 +13537,12 @@ namespace ts {
|
||||||
|
|
||||||
let type: Type;
|
let type: Type;
|
||||||
if (memberDecl.kind === SyntaxKind.PropertyAssignment) {
|
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);
|
type = checkPropertyAssignment(<PropertyAssignment>memberDecl, checkMode);
|
||||||
}
|
}
|
||||||
else if (memberDecl.kind === SyntaxKind.MethodDeclaration) {
|
else if (memberDecl.kind === SyntaxKind.MethodDeclaration) {
|
||||||
|
@ -13552,7 +13559,7 @@ namespace ts {
|
||||||
}
|
}
|
||||||
|
|
||||||
typeFlags |= type.flags;
|
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 (inDestructuringPattern) {
|
||||||
// If object literal is an assignment pattern and if the assignment pattern specifies a default value
|
// If object literal is an assignment pattern and if the assignment pattern specifies a default value
|
||||||
// for the property, make the property optional.
|
// for the property, make the property optional.
|
||||||
|
@ -13562,7 +13569,7 @@ namespace ts {
|
||||||
if (isOptional) {
|
if (isOptional) {
|
||||||
prop.flags |= SymbolFlags.Optional;
|
prop.flags |= SymbolFlags.Optional;
|
||||||
}
|
}
|
||||||
if (hasDynamicName(memberDecl)) {
|
if (!literalName && hasDynamicName(memberDecl)) {
|
||||||
patternWithComputedProperties = true;
|
patternWithComputedProperties = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13620,7 +13627,7 @@ namespace ts {
|
||||||
checkNodeDeferred(memberDecl);
|
checkNodeDeferred(memberDecl);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hasDynamicName(memberDecl)) {
|
if (!literalName && hasDynamicName(memberDecl)) {
|
||||||
if (isNumericName(memberDecl.name)) {
|
if (isNumericName(memberDecl.name)) {
|
||||||
hasComputedNumberProperty = true;
|
hasComputedNumberProperty = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue