Skip to content

Commit 82b5655

Browse files
committed
Special prop assignment symbol applies only to lhs
In a Javascript file, the binder assigns a SpecialPropertyAssignment marker to the BinaryExpression node of several kinds of special assignments. Then it binds a special symbol whose declaration is that BinaryExpression node. But the symbol only applies to the left-hand side of the assignment. The right-hand side is an independent expression that should have its own symbols. Previously, symbol lookup in the checker didn't check whether a Javascript node that was part of a special property assignment came from the lhs or the rhs. So the right-hand side would also incorrectly get the special symbol intended for the left-hand side. `getSpecialPropertyAssignmentSymbolFromEntityName` in the checker now checks that its argument is the left-hand side of an assignment before returning a special property assignment symbol.
1 parent 2d4b4c9 commit 82b5655

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20898,7 +20898,9 @@ namespace ts {
2089820898
return getSymbolOfNode(entityName.parent);
2089920899
}
2090020900

20901-
if (isInJavaScriptFile(entityName) && entityName.parent.kind === SyntaxKind.PropertyAccessExpression) {
20901+
if (isInJavaScriptFile(entityName) &&
20902+
entityName.parent.kind === SyntaxKind.PropertyAccessExpression &&
20903+
entityName.parent === (entityName.parent.parent as BinaryExpression).left) {
2090220904
// Check if this is a special property assignment
2090320905
const specialPropertyAssignmentSymbol = getSpecialPropertyAssignmentSymbolFromEntityName(entityName);
2090420906
if (specialPropertyAssignmentSymbol) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/// <reference path="fourslash.ts"/>
2+
// @allowJs: true
3+
// @Filename: a.js
4+
////const foo = {
5+
//// set: function (x) {
6+
//// this._x = x;
7+
//// },
8+
//// copy: function ([|x|]) {
9+
//// this._x = /**/[|x|].prop;
10+
//// }
11+
////};
12+
goTo.marker();
13+
verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);

0 commit comments

Comments
 (0)