@@ -22773,9 +22773,10 @@ namespace ts {
2277322773 return isMatchingReference((source as NonNullExpression | ParenthesizedExpression).expression, target);
2277422774 case SyntaxKind.PropertyAccessExpression:
2277522775 case SyntaxKind.ElementAccessExpression:
22776- return isAccessExpression(target) &&
22777- getAccessedPropertyName(source as AccessExpression) === getAccessedPropertyName(target) &&
22778- isMatchingReference((source as AccessExpression).expression, target.expression);
22776+ const sourcePropertyName = getAccessedPropertyName(source as AccessExpression);
22777+ const targetPropertyName = isAccessExpression(target) ? getAccessedPropertyName(target) : undefined;
22778+ return sourcePropertyName !== undefined && targetPropertyName !== undefined && targetPropertyName === sourcePropertyName &&
22779+ isMatchingReference((source as AccessExpression).expression, (target as AccessExpression).expression);
2277922780 case SyntaxKind.QualifiedName:
2278022781 return isAccessExpression(target) &&
2278122782 (source as QualifiedName).right.escapedText === getAccessedPropertyName(target) &&
@@ -22787,12 +22788,52 @@ namespace ts {
2278722788 }
2278822789
2278922790 function getAccessedPropertyName(access: AccessExpression | BindingElement | ParameterDeclaration): __String | undefined {
22790- let propertyName;
22791- return access.kind === SyntaxKind.PropertyAccessExpression ? access.name.escapedText :
22792- access.kind === SyntaxKind.ElementAccessExpression && isStringOrNumericLiteralLike(access.argumentExpression) ? escapeLeadingUnderscores(access.argumentExpression.text) :
22793- access.kind === SyntaxKind.BindingElement && (propertyName = getDestructuringPropertyName(access)) ? escapeLeadingUnderscores(propertyName) :
22794- access.kind === SyntaxKind.Parameter ? ("" + access.parent.parameters.indexOf(access)) as __String :
22795- undefined;
22791+ if (isPropertyAccessExpression(access)) {
22792+ return access.name.escapedText;
22793+ }
22794+ if (isElementAccessExpression(access)) {
22795+ return tryGetElementAccessExpressionName(access);
22796+ }
22797+ if (isBindingElement(access)) {
22798+ const name = getDestructuringPropertyName(access);
22799+ return name ? escapeLeadingUnderscores(name) : undefined;
22800+ }
22801+ if (isParameter(access)) {
22802+ return ("" + access.parent.parameters.indexOf(access)) as __String;
22803+ }
22804+ return undefined;
22805+ }
22806+
22807+ function tryGetNameFromType(type: Type) {
22808+ return type.flags & TypeFlags.UniqueESSymbol ? (type as UniqueESSymbolType).escapedName :
22809+ type.flags & TypeFlags.StringOrNumberLiteral ? escapeLeadingUnderscores("" + (type as StringLiteralType | NumberLiteralType).value) : undefined;
22810+ }
22811+
22812+ function tryGetElementAccessExpressionName(node: ElementAccessExpression) {
22813+ if (isStringOrNumericLiteralLike(node.argumentExpression)) {
22814+ return escapeLeadingUnderscores(node.argumentExpression.text);
22815+ }
22816+ if (isEntityNameExpression(node.argumentExpression)) {
22817+ const symbol = resolveEntityName(node.argumentExpression, SymbolFlags.Value, /*ignoreErrors*/ true);
22818+ if (!symbol || !isConstVariable(symbol)) return undefined;
22819+
22820+ const declaration = symbol.valueDeclaration;
22821+ if (declaration === undefined) return undefined;
22822+
22823+ const type = tryGetTypeFromEffectiveTypeNode(declaration);
22824+ if (type) {
22825+ const name = tryGetNameFromType(type);
22826+ if (name !== undefined) {
22827+ return name;
22828+ }
22829+ }
22830+
22831+ if (hasOnlyExpressionInitializer(declaration)) {
22832+ const initializer = getEffectiveInitializer(declaration);
22833+ return initializer && tryGetNameFromType(getTypeOfExpression(initializer));
22834+ }
22835+ }
22836+ return undefined;
2279622837 }
2279722838
2279822839 function containsMatchingReference(source: Node, target: Node) {
@@ -39310,7 +39351,7 @@ namespace ts {
3931039351 }
3931139352 if (!isStatic(member) && isPropertyWithoutInitializer(member)) {
3931239353 const propName = (member as PropertyDeclaration).name;
39313- if (isIdentifier(propName) || isPrivateIdentifier(propName)) {
39354+ if (isIdentifier(propName) || isPrivateIdentifier(propName) || isComputedPropertyName(propName) ) {
3931439355 const type = getTypeOfSymbol(getSymbolOfNode(member));
3931539356 if (!(type.flags & TypeFlags.AnyOrUnknown || getFalsyFlags(type) & TypeFlags.Undefined)) {
3931639357 if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) {
@@ -39346,8 +39387,10 @@ namespace ts {
3934639387 return false;
3934739388 }
3934839389
39349- function isPropertyInitializedInConstructor(propName: Identifier | PrivateIdentifier, propType: Type, constructor: ConstructorDeclaration) {
39350- const reference = factory.createPropertyAccessExpression(factory.createThis(), propName);
39390+ function isPropertyInitializedInConstructor(propName: Identifier | PrivateIdentifier | ComputedPropertyName, propType: Type, constructor: ConstructorDeclaration) {
39391+ const reference = isComputedPropertyName(propName)
39392+ ? factory.createElementAccessExpression(factory.createThis(), propName.expression)
39393+ : factory.createPropertyAccessExpression(factory.createThis(), propName);
3935139394 setParent(reference.expression, reference);
3935239395 setParent(reference, constructor);
3935339396 reference.flowNode = constructor.returnFlowNode;
0 commit comments