@@ -12907,7 +12907,7 @@ func (c *Checker) getSpreadType(left *Type, right *Type, symbol *ast.Symbol, obj
12907
12907
12908
12908
func (c *Checker) getIndexInfoWithReadonly(info *IndexInfo, readonly bool) *IndexInfo {
12909
12909
if info.isReadonly != readonly {
12910
- return c.newIndexInfo(info.keyType, info.valueType, readonly, info.declaration)
12910
+ return c.newIndexInfo(info.keyType, info.valueType, readonly, info.declaration, info.components )
12911
12911
}
12912
12912
return info
12913
12913
}
@@ -12928,7 +12928,7 @@ func (c *Checker) getUnionIndexInfos(types []*Type) []*IndexInfo {
12928
12928
return c.getIndexTypeOfType(t, indexType)
12929
12929
}))
12930
12930
isReadonly := core.Some(types, func(t *Type) bool { return c.getIndexInfoOfType(t, indexType).isReadonly })
12931
- result = append(result, c.newIndexInfo(indexType, valueType, isReadonly, nil))
12931
+ result = append(result, c.newIndexInfo(indexType, valueType, isReadonly, nil, nil ))
12932
12932
}
12933
12933
}
12934
12934
return result
@@ -17179,7 +17179,7 @@ func (c *Checker) getTypeFromObjectBindingPattern(pattern *ast.Node, includePatt
17179
17179
for _, e := range pattern.AsBindingPattern().Elements.Nodes {
17180
17180
name := e.PropertyNameOrName()
17181
17181
if hasDotDotDotToken(e) {
17182
- stringIndexInfo = c.newIndexInfo(c.stringType, c.anyType, false /*isReadonly*/, nil)
17182
+ stringIndexInfo = c.newIndexInfo(c.stringType, c.anyType, false /*isReadonly*/, nil, nil )
17183
17183
continue
17184
17184
}
17185
17185
exprType := c.getLiteralTypeFromPropertyName(name)
@@ -17580,7 +17580,7 @@ func (c *Checker) getWidenedTypeOfObjectLiteral(t *Type, context *WideningContex
17580
17580
}
17581
17581
}
17582
17582
result := c.newAnonymousType(t.symbol, members, nil, nil, core.SameMap(c.getIndexInfosOfType(t), func(info *IndexInfo) *IndexInfo {
17583
- return c.newIndexInfo(info.keyType, c.getWidenedType(info.valueType), info.isReadonly, info.declaration)
17583
+ return c.newIndexInfo(info.keyType, c.getWidenedType(info.valueType), info.isReadonly, info.declaration, info.components )
17584
17584
}))
17585
17585
// Retain js literal flag through widening
17586
17586
result.objectFlags |= t.objectFlags & (ObjectFlagsJSLiteral | ObjectFlagsNonInferrableType)
@@ -18187,7 +18187,7 @@ func (c *Checker) findApplicableIndexInfo(indexInfos []*IndexInfo, keyType *Type
18187
18187
isReadonly = false
18188
18188
}
18189
18189
}
18190
- return c.newIndexInfo(c.unknownType, c.getIntersectionType(types), isReadonly, nil)
18190
+ return c.newIndexInfo(c.unknownType, c.getIntersectionType(types), isReadonly, nil, nil )
18191
18191
}
18192
18192
}
18193
18193
@@ -18794,7 +18794,7 @@ func (c *Checker) getIndexInfosOfIndexSymbol(indexSymbol *ast.Symbol, siblingSym
18794
18794
}
18795
18795
forEachType(c.getTypeFromTypeNode(typeNode), func(keyType *Type) {
18796
18796
if c.isValidIndexKeyType(keyType) && findIndexInfo(indexInfos, keyType) == nil {
18797
- indexInfo := c.newIndexInfo(keyType, valueType, HasModifier(declaration, ast.ModifierFlagsReadonly), declaration)
18797
+ indexInfo := c.newIndexInfo(keyType, valueType, HasModifier(declaration, ast.ModifierFlagsReadonly), declaration, nil )
18798
18798
indexInfos = append(indexInfos, indexInfo)
18799
18799
}
18800
18800
})
@@ -18861,18 +18861,22 @@ func (c *Checker) getIndexInfosOfIndexSymbol(indexSymbol *ast.Symbol, siblingSym
18861
18861
// NOTE: currently does not make pattern literal indexers, eg `${number}px`
18862
18862
func (c *Checker) getObjectLiteralIndexInfo(isReadonly bool, properties []*ast.Symbol, keyType *Type) *IndexInfo {
18863
18863
var propTypes []*Type
18864
+ var components []*ast.Node
18864
18865
for _, prop := range properties {
18865
18866
if keyType == c.stringType && !c.isSymbolWithSymbolName(prop) ||
18866
18867
keyType == c.numberType && c.isSymbolWithNumericName(prop) ||
18867
18868
keyType == c.esSymbolType && c.isSymbolWithSymbolName(prop) {
18868
18869
propTypes = append(propTypes, c.getTypeOfSymbol(prop))
18870
+ if c.isSymbolWithComputedName(prop) {
18871
+ components = append(components, prop.Declarations[0])
18872
+ }
18869
18873
}
18870
18874
}
18871
18875
unionType := c.undefinedType
18872
18876
if len(propTypes) != 0 {
18873
18877
unionType = c.getUnionTypeEx(propTypes, UnionReductionSubtype, nil, nil)
18874
18878
}
18875
- return c.newIndexInfo(keyType, unionType, isReadonly, nil /*declaration*/)
18879
+ return c.newIndexInfo(keyType, unionType, isReadonly, nil /*declaration*/, components )
18876
18880
}
18877
18881
18878
18882
func (c *Checker) isSymbolWithSymbolName(symbol *ast.Symbol) bool {
@@ -18897,6 +18901,14 @@ func (c *Checker) isSymbolWithNumericName(symbol *ast.Symbol) bool {
18897
18901
return false
18898
18902
}
18899
18903
18904
+ func (c *Checker) isSymbolWithComputedName(symbol *ast.Symbol) bool {
18905
+ if len(symbol.Declarations) != 0 {
18906
+ name := symbol.Declarations[0].Name()
18907
+ return name != nil && ast.IsComputedPropertyName(name)
18908
+ }
18909
+ return false
18910
+ }
18911
+
18900
18912
func (c *Checker) isNumericName(name *ast.Node) bool {
18901
18913
switch name.Kind {
18902
18914
case ast.KindComputedPropertyName:
@@ -19768,7 +19780,7 @@ func (c *Checker) instantiateIndexInfo(info *IndexInfo, m *TypeMapper) *IndexInf
19768
19780
if newValueType == info.valueType {
19769
19781
return info
19770
19782
}
19771
- return c.newIndexInfo(info.keyType, newValueType, info.isReadonly, info.declaration)
19783
+ return c.newIndexInfo(info.keyType, newValueType, info.isReadonly, info.declaration, info.components )
19772
19784
}
19773
19785
19774
19786
func (c *Checker) resolveAnonymousTypeMembers(t *Type) {
@@ -20086,7 +20098,7 @@ func (c *Checker) resolveMappedTypeMembers(t *Type) {
20086
20098
propType := c.instantiateType(templateType, appendTypeMapping(t.AsMappedType().mapper, typeParameter, keyType))
20087
20099
modifiersIndexInfo := c.getApplicableIndexInfo(modifiersType, propNameType)
20088
20100
isReadonly := templateModifiers&MappedTypeModifiersIncludeReadonly != 0 || templateModifiers&MappedTypeModifiersExcludeReadonly == 0 && modifiersIndexInfo != nil && modifiersIndexInfo.isReadonly
20089
- indexInfo := c.newIndexInfo(indexKeyType, propType, isReadonly, nil)
20101
+ indexInfo := c.newIndexInfo(indexKeyType, propType, isReadonly, nil, nil )
20090
20102
indexInfos = c.appendIndexInfo(indexInfos, indexInfo, true /*union*/)
20091
20103
}
20092
20104
}
@@ -20479,7 +20491,7 @@ func (c *Checker) appendIndexInfo(indexInfos []*IndexInfo, newInfo *IndexInfo, u
20479
20491
valueType = c.getIntersectionType([]*Type{info.valueType, newInfo.valueType})
20480
20492
isReadonly = info.isReadonly && newInfo.isReadonly
20481
20493
}
20482
- indexInfos[i] = c.newIndexInfo(info.keyType, valueType, isReadonly, nil)
20494
+ indexInfos[i] = c.newIndexInfo(info.keyType, valueType, isReadonly, nil, nil )
20483
20495
return indexInfos
20484
20496
}
20485
20497
}
@@ -24316,12 +24328,13 @@ func (c *Checker) newSignature(flags SignatureFlags, declaration *ast.Node, type
24316
24328
return sig
24317
24329
}
24318
24330
24319
- func (c *Checker) newIndexInfo(keyType *Type, valueType *Type, isReadonly bool, declaration *ast.Node) *IndexInfo {
24331
+ func (c *Checker) newIndexInfo(keyType *Type, valueType *Type, isReadonly bool, declaration *ast.Node, components []*ast.Node ) *IndexInfo {
24320
24332
info := c.indexInfoPool.New()
24321
24333
info.keyType = keyType
24322
24334
info.valueType = valueType
24323
24335
info.isReadonly = isReadonly
24324
24336
info.declaration = declaration
24337
+ info.components = components
24325
24338
return info
24326
24339
}
24327
24340
0 commit comments