@@ -22877,9 +22877,10 @@ namespace ts {
22877
22877
return isMatchingReference((source as NonNullExpression | ParenthesizedExpression).expression, target);
22878
22878
case SyntaxKind.PropertyAccessExpression:
22879
22879
case SyntaxKind.ElementAccessExpression:
22880
- return isAccessExpression(target) &&
22881
- getAccessedPropertyName(source as AccessExpression) === getAccessedPropertyName(target) &&
22882
- isMatchingReference((source as AccessExpression).expression, target.expression);
22880
+ const sourcePropertyName = getAccessedPropertyName(source as AccessExpression);
22881
+ const targetPropertyName = isAccessExpression(target) ? getAccessedPropertyName(target) : undefined;
22882
+ return sourcePropertyName !== undefined && targetPropertyName !== undefined && targetPropertyName === sourcePropertyName &&
22883
+ isMatchingReference((source as AccessExpression).expression, (target as AccessExpression).expression);
22883
22884
case SyntaxKind.QualifiedName:
22884
22885
return isAccessExpression(target) &&
22885
22886
(source as QualifiedName).right.escapedText === getAccessedPropertyName(target) &&
@@ -22891,12 +22892,52 @@ namespace ts {
22891
22892
}
22892
22893
22893
22894
function getAccessedPropertyName(access: AccessExpression | BindingElement | ParameterDeclaration): __String | undefined {
22894
- let propertyName;
22895
- return access.kind === SyntaxKind.PropertyAccessExpression ? access.name.escapedText :
22896
- access.kind === SyntaxKind.ElementAccessExpression && isStringOrNumericLiteralLike(access.argumentExpression) ? escapeLeadingUnderscores(access.argumentExpression.text) :
22897
- access.kind === SyntaxKind.BindingElement && (propertyName = getDestructuringPropertyName(access)) ? escapeLeadingUnderscores(propertyName) :
22898
- access.kind === SyntaxKind.Parameter ? ("" + access.parent.parameters.indexOf(access)) as __String :
22899
- undefined;
22895
+ if (isPropertyAccessExpression(access)) {
22896
+ return access.name.escapedText;
22897
+ }
22898
+ if (isElementAccessExpression(access)) {
22899
+ return tryGetElementAccessExpressionName(access);
22900
+ }
22901
+ if (isBindingElement(access)) {
22902
+ const name = getDestructuringPropertyName(access);
22903
+ return name ? escapeLeadingUnderscores(name) : undefined;
22904
+ }
22905
+ if (isParameter(access)) {
22906
+ return ("" + access.parent.parameters.indexOf(access)) as __String;
22907
+ }
22908
+ return undefined;
22909
+ }
22910
+
22911
+ function tryGetNameFromType(type: Type) {
22912
+ return type.flags & TypeFlags.UniqueESSymbol ? (type as UniqueESSymbolType).escapedName :
22913
+ type.flags & TypeFlags.StringOrNumberLiteral ? escapeLeadingUnderscores("" + (type as StringLiteralType | NumberLiteralType).value) : undefined;
22914
+ }
22915
+
22916
+ function tryGetElementAccessExpressionName(node: ElementAccessExpression) {
22917
+ if (isStringOrNumericLiteralLike(node.argumentExpression)) {
22918
+ return escapeLeadingUnderscores(node.argumentExpression.text);
22919
+ }
22920
+ if (isEntityNameExpression(node.argumentExpression)) {
22921
+ const symbol = resolveEntityName(node.argumentExpression, SymbolFlags.Value, /*ignoreErrors*/ true);
22922
+ if (!symbol || !isConstVariable(symbol)) return undefined;
22923
+
22924
+ const declaration = symbol.valueDeclaration;
22925
+ if (declaration === undefined) return undefined;
22926
+
22927
+ const type = tryGetTypeFromEffectiveTypeNode(declaration);
22928
+ if (type) {
22929
+ const name = tryGetNameFromType(type);
22930
+ if (name !== undefined) {
22931
+ return name;
22932
+ }
22933
+ }
22934
+
22935
+ if (hasOnlyExpressionInitializer(declaration)) {
22936
+ const initializer = getEffectiveInitializer(declaration);
22937
+ return initializer && tryGetNameFromType(getTypeOfExpression(initializer));
22938
+ }
22939
+ }
22940
+ return undefined;
22900
22941
}
22901
22942
22902
22943
function containsMatchingReference(source: Node, target: Node) {
@@ -39529,7 +39570,7 @@ namespace ts {
39529
39570
}
39530
39571
if (!isStatic(member) && isPropertyWithoutInitializer(member)) {
39531
39572
const propName = (member as PropertyDeclaration).name;
39532
- if (isIdentifier(propName) || isPrivateIdentifier(propName)) {
39573
+ if (isIdentifier(propName) || isPrivateIdentifier(propName) || isComputedPropertyName(propName) ) {
39533
39574
const type = getTypeOfSymbol(getSymbolOfNode(member));
39534
39575
if (!(type.flags & TypeFlags.AnyOrUnknown || getFalsyFlags(type) & TypeFlags.Undefined)) {
39535
39576
if (!constructor || !isPropertyInitializedInConstructor(propName, type, constructor)) {
@@ -39565,8 +39606,10 @@ namespace ts {
39565
39606
return false;
39566
39607
}
39567
39608
39568
- function isPropertyInitializedInConstructor(propName: Identifier | PrivateIdentifier, propType: Type, constructor: ConstructorDeclaration) {
39569
- const reference = factory.createPropertyAccessExpression(factory.createThis(), propName);
39609
+ function isPropertyInitializedInConstructor(propName: Identifier | PrivateIdentifier | ComputedPropertyName, propType: Type, constructor: ConstructorDeclaration) {
39610
+ const reference = isComputedPropertyName(propName)
39611
+ ? factory.createElementAccessExpression(factory.createThis(), propName.expression)
39612
+ : factory.createPropertyAccessExpression(factory.createThis(), propName);
39570
39613
setParent(reference.expression, reference);
39571
39614
setParent(reference, constructor);
39572
39615
reference.flowNode = constructor.returnFlowNode;
0 commit comments