@@ -22773,9 +22773,10 @@ namespace ts {
22773
22773
return isMatchingReference((source as NonNullExpression | ParenthesizedExpression).expression, target);
22774
22774
case SyntaxKind.PropertyAccessExpression:
22775
22775
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);
22779
22780
case SyntaxKind.QualifiedName:
22780
22781
return isAccessExpression(target) &&
22781
22782
(source as QualifiedName).right.escapedText === getAccessedPropertyName(target) &&
@@ -22787,12 +22788,52 @@ namespace ts {
22787
22788
}
22788
22789
22789
22790
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;
22796
22837
}
22797
22838
22798
22839
function containsMatchingReference(source: Node, target: Node) {
@@ -39310,7 +39351,7 @@ namespace ts {
39310
39351
}
39311
39352
if (!isStatic(member) && isPropertyWithoutInitializer(member)) {
39312
39353
const propName = (member as PropertyDeclaration).name;
39313
- if (isIdentifier(propName) || isPrivateIdentifier(propName)) {
39354
+ if (isIdentifier(propName) || isPrivateIdentifier(propName) || isComputedPropertyName(propName) ) {
39314
39355
const type = getTypeOfSymbol(getSymbolOfNode(member));
39315
39356
if (!(type.flags & TypeFlags.AnyOrUnknown || getFalsyFlags(type) & TypeFlags.Undefined)) {
39316
39357
if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) {
@@ -39346,8 +39387,10 @@ namespace ts {
39346
39387
return false;
39347
39388
}
39348
39389
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);
39351
39394
setParent(reference.expression, reference);
39352
39395
setParent(reference, constructor);
39353
39396
reference.flowNode = constructor.returnFlowNode;
0 commit comments