Skip to content

Do not consider element accesses which are neither statically bindable nor late bound as special assignments #34679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2115,7 +2115,7 @@ namespace ts {
if (expr.operatorToken.kind !== SyntaxKind.EqualsToken || !isAccessExpression(expr.left)) {
return AssignmentDeclarationKind.None;
}
if (isBindableStaticNameExpression(expr.left.expression) && getElementOrPropertyAccessName(expr.left) === "prototype" && isObjectLiteralExpression(getInitializerOfBinaryExpression(expr))) {
if (isBindableStaticNameExpression(expr.left.expression, /*excludeThisKeyword*/ true) && getElementOrPropertyAccessName(expr.left) === "prototype" && isObjectLiteralExpression(getInitializerOfBinaryExpression(expr))) {
// F.prototype = { ... }
return AssignmentDeclarationKind.Prototype;
}
Expand Down Expand Up @@ -2183,8 +2183,10 @@ namespace ts {
// exports.name = expr OR module.exports.name = expr OR exports["name"] = expr ...
return AssignmentDeclarationKind.ExportsProperty;
}
// F.G...x = expr
return AssignmentDeclarationKind.Property;
if (isBindableStaticNameExpression(lhs, /*excludeThisKeyword*/ true) || (isElementAccessExpression(lhs) && isDynamicName(lhs) && lhs.expression.kind !== SyntaxKind.ThisKeyword)) {
// F.G...x = expr
return AssignmentDeclarationKind.Property;
}
}

return AssignmentDeclarationKind.None;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
=== tests/cases/compiler/jsNegativeELementAccessNotBound.js ===
var indexMap = {};
>indexMap : Symbol(indexMap, Decl(jsNegativeELementAccessNotBound.js, 0, 3))

indexMap[-1] = 0;
>indexMap : Symbol(indexMap, Decl(jsNegativeELementAccessNotBound.js, 0, 3))

13 changes: 13 additions & 0 deletions tests/baselines/reference/jsNegativeElementAccessNotBound.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
=== tests/cases/compiler/jsNegativeELementAccessNotBound.js ===
var indexMap = {};
>indexMap : {}
>{} : {}

indexMap[-1] = 0;
>indexMap[-1] = 0 : 0
>indexMap[-1] : any
>indexMap : {}
>-1 : -1
>1 : 1
>0 : 0

6 changes: 6 additions & 0 deletions tests/cases/compiler/jsNegativeElementAccessNotBound.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @allowJs: true
// @checkJs: true
// @noEmit: true
// @filename: jsNegativeELementAccessNotBound.js
var indexMap = {};
indexMap[-1] = 0;