Skip to content

Commit 07d3a2e

Browse files
authored
Do not consider element accesses which are neither statically bindable nor late bound as special assignments (microsoft#34679)
1 parent 8223c07 commit 07d3a2e

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

src/compiler/utilities.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -2115,7 +2115,7 @@ namespace ts {
21152115
if (expr.operatorToken.kind !== SyntaxKind.EqualsToken || !isAccessExpression(expr.left)) {
21162116
return AssignmentDeclarationKind.None;
21172117
}
2118-
if (isBindableStaticNameExpression(expr.left.expression) && getElementOrPropertyAccessName(expr.left) === "prototype" && isObjectLiteralExpression(getInitializerOfBinaryExpression(expr))) {
2118+
if (isBindableStaticNameExpression(expr.left.expression, /*excludeThisKeyword*/ true) && getElementOrPropertyAccessName(expr.left) === "prototype" && isObjectLiteralExpression(getInitializerOfBinaryExpression(expr))) {
21192119
// F.prototype = { ... }
21202120
return AssignmentDeclarationKind.Prototype;
21212121
}
@@ -2183,8 +2183,10 @@ namespace ts {
21832183
// exports.name = expr OR module.exports.name = expr OR exports["name"] = expr ...
21842184
return AssignmentDeclarationKind.ExportsProperty;
21852185
}
2186-
// F.G...x = expr
2187-
return AssignmentDeclarationKind.Property;
2186+
if (isBindableStaticNameExpression(lhs, /*excludeThisKeyword*/ true) || (isElementAccessExpression(lhs) && isDynamicName(lhs) && lhs.expression.kind !== SyntaxKind.ThisKeyword)) {
2187+
// F.G...x = expr
2188+
return AssignmentDeclarationKind.Property;
2189+
}
21882190
}
21892191

21902192
return AssignmentDeclarationKind.None;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
=== tests/cases/compiler/jsNegativeELementAccessNotBound.js ===
2+
var indexMap = {};
3+
>indexMap : Symbol(indexMap, Decl(jsNegativeELementAccessNotBound.js, 0, 3))
4+
5+
indexMap[-1] = 0;
6+
>indexMap : Symbol(indexMap, Decl(jsNegativeELementAccessNotBound.js, 0, 3))
7+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
=== tests/cases/compiler/jsNegativeELementAccessNotBound.js ===
2+
var indexMap = {};
3+
>indexMap : {}
4+
>{} : {}
5+
6+
indexMap[-1] = 0;
7+
>indexMap[-1] = 0 : 0
8+
>indexMap[-1] : any
9+
>indexMap : {}
10+
>-1 : -1
11+
>1 : 1
12+
>0 : 0
13+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// @allowJs: true
2+
// @checkJs: true
3+
// @noEmit: true
4+
// @filename: jsNegativeELementAccessNotBound.js
5+
var indexMap = {};
6+
indexMap[-1] = 0;

0 commit comments

Comments
 (0)