@@ -22358,9 +22358,10 @@ namespace ts {
2235822358 return isMatchingReference((source as NonNullExpression | ParenthesizedExpression).expression, target);
2235922359 case SyntaxKind.PropertyAccessExpression:
2236022360 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);
2236422365 case SyntaxKind.QualifiedName:
2236522366 return isAccessExpression(target) &&
2236622367 (source as QualifiedName).right.escapedText === getAccessedPropertyName(target) &&
@@ -22396,11 +22397,38 @@ namespace ts {
2239622397 }
2239722398
2239822399 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 tryGetElementAccessExpressionName(node: ElementAccessExpression) {
22414+ if (isStringOrNumericLiteralLike(node.argumentExpression)) {
22415+ return escapeLeadingUnderscores(node.argumentExpression.text);
22416+ }
22417+ if (isIdentifier(node.argumentExpression)) {
22418+ const symbol = getResolvedSymbol(node.argumentExpression);
22419+ if (!isConstVariable(symbol)) return undefined;
22420+
22421+ const declaration = symbol.valueDeclaration;
22422+ if (!(declaration && hasOnlyExpressionInitializer(declaration))) return undefined;
22423+
22424+ const initializer = getEffectiveInitializer(declaration);
22425+ if (initializer === undefined) return undefined;
22426+
22427+ const type = getTypeOfExpression(initializer);
22428+ return type.flags & TypeFlags.UniqueESSymbol ? (type as UniqueESSymbolType).escapedName :
22429+ type.flags & TypeFlags.StringOrNumberLiteral ? escapeLeadingUnderscores("" + (type as StringLiteralType | NumberLiteralType).value) : undefined;
22430+ }
22431+ return undefined;
2240422432 }
2240522433
2240622434 function containsMatchingReference(source: Node, target: Node) {
@@ -38598,7 +38626,7 @@ namespace ts {
3859838626 }
3859938627 if (!isStatic(member) && isPropertyWithoutInitializer(member)) {
3860038628 const propName = (member as PropertyDeclaration).name;
38601- if (isIdentifier(propName) || isPrivateIdentifier(propName)) {
38629+ if (isIdentifier(propName) || isPrivateIdentifier(propName) || isComputedPropertyName(propName) ) {
3860238630 const type = getTypeOfSymbol(getSymbolOfNode(member));
3860338631 if (!(type.flags & TypeFlags.AnyOrUnknown || getFalsyFlags(type) & TypeFlags.Undefined)) {
3860438632 if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) {
@@ -38634,8 +38662,10 @@ namespace ts {
3863438662 return false;
3863538663 }
3863638664
38637- function isPropertyInitializedInConstructor(propName: Identifier | PrivateIdentifier, propType: Type, constructor: ConstructorDeclaration) {
38638- const reference = factory.createPropertyAccessExpression(factory.createThis(), propName);
38665+ function isPropertyInitializedInConstructor(propName: Identifier | PrivateIdentifier | ComputedPropertyName, propType: Type, constructor: ConstructorDeclaration) {
38666+ const reference = isComputedPropertyName(propName)
38667+ ? factory.createElementAccessExpression(factory.createThis(), propName.expression)
38668+ : factory.createPropertyAccessExpression(factory.createThis(), propName);
3863938669 setParent(reference.expression, reference);
3864038670 setParent(reference, constructor);
3864138671 reference.flowNode = constructor.returnFlowNode;
0 commit comments