@@ -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,49 @@ 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 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;
2240422443 }
2240522444
2240622445 function containsMatchingReference(source: Node, target: Node) {
@@ -38598,7 +38637,7 @@ namespace ts {
3859838637 }
3859938638 if (!isStatic(member) && isPropertyWithoutInitializer(member)) {
3860038639 const propName = (member as PropertyDeclaration).name;
38601- if (isIdentifier(propName) || isPrivateIdentifier(propName)) {
38640+ if (isIdentifier(propName) || isPrivateIdentifier(propName) || isComputedPropertyName(propName) ) {
3860238641 const type = getTypeOfSymbol(getSymbolOfNode(member));
3860338642 if (!(type.flags & TypeFlags.AnyOrUnknown || getFalsyFlags(type) & TypeFlags.Undefined)) {
3860438643 if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) {
@@ -38634,8 +38673,10 @@ namespace ts {
3863438673 return false;
3863538674 }
3863638675
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);
3863938680 setParent(reference.expression, reference);
3864038681 setParent(reference, constructor);
3864138682 reference.flowNode = constructor.returnFlowNode;
0 commit comments