@@ -22358,9 +22358,10 @@ namespace ts {
22358
22358
return isMatchingReference((source as NonNullExpression | ParenthesizedExpression).expression, target);
22359
22359
case SyntaxKind.PropertyAccessExpression:
22360
22360
case SyntaxKind.ElementAccessExpression:
22361
- return isAccessExpression(target) &&
22362
- getAccessedPropertyName(source as AccessExpression) === getAccessedPropertyName(target) &&
22363
- isMatchingReference((source as AccessExpression).expression, target.expression);
22361
+ const sourcePropertyName = getAccessedPropertyName(source as AccessExpression);
22362
+ const targetPropertyName = isAccessExpression(target) ? getAccessedPropertyName(target) : undefined;
22363
+ return sourcePropertyName !== undefined && targetPropertyName !== undefined && targetPropertyName === sourcePropertyName &&
22364
+ isMatchingReference((source as AccessExpression).expression, (target as AccessExpression).expression);
22364
22365
case SyntaxKind.QualifiedName:
22365
22366
return isAccessExpression(target) &&
22366
22367
(source as QualifiedName).right.escapedText === getAccessedPropertyName(target) &&
@@ -22396,11 +22397,49 @@ namespace ts {
22396
22397
}
22397
22398
22398
22399
function getAccessedPropertyName(access: AccessExpression | BindingElement): __String | undefined {
22399
- let propertyName;
22400
- return access.kind === SyntaxKind.PropertyAccessExpression ? access.name.escapedText :
22401
- access.kind === SyntaxKind.ElementAccessExpression && isStringOrNumericLiteralLike(access.argumentExpression) ? escapeLeadingUnderscores(access.argumentExpression.text) :
22402
- access.kind === SyntaxKind.BindingElement && (propertyName = getDestructuringPropertyName(access)) ? escapeLeadingUnderscores(propertyName) :
22403
- undefined;
22400
+ if (isPropertyAccessExpression(access)) {
22401
+ return access.name.escapedText;
22402
+ }
22403
+ if (isElementAccessExpression(access)) {
22404
+ return tryGetElementAccessExpressionName(access);
22405
+ }
22406
+ if (isBindingElement(access)) {
22407
+ const name = getDestructuringPropertyName(access);
22408
+ return name ? escapeLeadingUnderscores(name) : undefined;
22409
+ }
22410
+ return undefined;
22411
+ }
22412
+
22413
+ function tryGetNameFromType(type: Type) {
22414
+ return type.flags & TypeFlags.UniqueESSymbol ? (type as UniqueESSymbolType).escapedName :
22415
+ type.flags & TypeFlags.StringOrNumberLiteral ? escapeLeadingUnderscores("" + (type as StringLiteralType | NumberLiteralType).value) : undefined;
22416
+ }
22417
+
22418
+ function tryGetElementAccessExpressionName(node: ElementAccessExpression) {
22419
+ if (isStringOrNumericLiteralLike(node.argumentExpression)) {
22420
+ return escapeLeadingUnderscores(node.argumentExpression.text);
22421
+ }
22422
+ if (isIdentifier(node.argumentExpression)) {
22423
+ const symbol = getResolvedSymbol(node.argumentExpression);
22424
+ if (!isConstVariable(symbol)) return undefined;
22425
+
22426
+ const declaration = symbol.valueDeclaration;
22427
+ if (declaration === undefined) return undefined;
22428
+
22429
+ const type = tryGetTypeFromEffectiveTypeNode(declaration);
22430
+ if (type) {
22431
+ const name = tryGetNameFromType(type);
22432
+ if (name !== undefined) {
22433
+ return name;
22434
+ }
22435
+ }
22436
+
22437
+ if (hasOnlyExpressionInitializer(declaration)) {
22438
+ const initializer = getEffectiveInitializer(declaration);
22439
+ return initializer && tryGetNameFromType(getTypeOfExpression(initializer));
22440
+ }
22441
+ }
22442
+ return undefined;
22404
22443
}
22405
22444
22406
22445
function containsMatchingReference(source: Node, target: Node) {
@@ -38598,7 +38637,7 @@ namespace ts {
38598
38637
}
38599
38638
if (!isStatic(member) && isPropertyWithoutInitializer(member)) {
38600
38639
const propName = (member as PropertyDeclaration).name;
38601
- if (isIdentifier(propName) || isPrivateIdentifier(propName)) {
38640
+ if (isIdentifier(propName) || isPrivateIdentifier(propName) || isComputedPropertyName(propName) ) {
38602
38641
const type = getTypeOfSymbol(getSymbolOfNode(member));
38603
38642
if (!(type.flags & TypeFlags.AnyOrUnknown || getFalsyFlags(type) & TypeFlags.Undefined)) {
38604
38643
if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) {
@@ -38634,8 +38673,10 @@ namespace ts {
38634
38673
return false;
38635
38674
}
38636
38675
38637
- function isPropertyInitializedInConstructor(propName: Identifier | PrivateIdentifier, propType: Type, constructor: ConstructorDeclaration) {
38638
- const reference = factory.createPropertyAccessExpression(factory.createThis(), propName);
38676
+ function isPropertyInitializedInConstructor(propName: Identifier | PrivateIdentifier | ComputedPropertyName, propType: Type, constructor: ConstructorDeclaration) {
38677
+ const reference = isComputedPropertyName(propName)
38678
+ ? factory.createElementAccessExpression(factory.createThis(), propName.expression)
38679
+ : factory.createPropertyAccessExpression(factory.createThis(), propName);
38639
38680
setParent(reference.expression, reference);
38640
38681
setParent(reference, constructor);
38641
38682
reference.flowNode = constructor.returnFlowNode;
0 commit comments