From 82b5655e66e3cc84dc95f96c80176ce7fc71548d Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 24 Feb 2017 14:22:55 -0800 Subject: [PATCH 1/2] 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. --- src/compiler/checker.ts | 4 +++- .../cases/fourslash/renameJsObjectLiteralMethod.ts | 13 +++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/renameJsObjectLiteralMethod.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 83fea11c993..b3c2726ba85 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -20898,7 +20898,9 @@ namespace ts { return getSymbolOfNode(entityName.parent); } - if (isInJavaScriptFile(entityName) && entityName.parent.kind === SyntaxKind.PropertyAccessExpression) { + if (isInJavaScriptFile(entityName) && + entityName.parent.kind === SyntaxKind.PropertyAccessExpression && + entityName.parent === (entityName.parent.parent as BinaryExpression).left) { // Check if this is a special property assignment const specialPropertyAssignmentSymbol = getSpecialPropertyAssignmentSymbolFromEntityName(entityName); if (specialPropertyAssignmentSymbol) { diff --git a/tests/cases/fourslash/renameJsObjectLiteralMethod.ts b/tests/cases/fourslash/renameJsObjectLiteralMethod.ts new file mode 100644 index 00000000000..b4b9fb80528 --- /dev/null +++ b/tests/cases/fourslash/renameJsObjectLiteralMethod.ts @@ -0,0 +1,13 @@ +/// +// @allowJs: true +// @Filename: a.js +////const foo = { +//// set: function (x) { +//// this._x = x; +//// }, +//// copy: function ([|x|]) { +//// this._x = /**/[|x|].prop; +//// } +////}; +goTo.marker(); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false); From 44e1140cf69605bc2c3a60c186b98b0e73a94423 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 24 Feb 2017 14:53:35 -0800 Subject: [PATCH 2/2] Rename tests --- ...alMethod.ts => renameJsSpecialAssignmentRhs1.ts} | 0 .../fourslash/renameJsSpecialAssignmentRhs2.ts | 13 +++++++++++++ 2 files changed, 13 insertions(+) rename tests/cases/fourslash/{renameJsObjectLiteralMethod.ts => renameJsSpecialAssignmentRhs1.ts} (100%) create mode 100644 tests/cases/fourslash/renameJsSpecialAssignmentRhs2.ts diff --git a/tests/cases/fourslash/renameJsObjectLiteralMethod.ts b/tests/cases/fourslash/renameJsSpecialAssignmentRhs1.ts similarity index 100% rename from tests/cases/fourslash/renameJsObjectLiteralMethod.ts rename to tests/cases/fourslash/renameJsSpecialAssignmentRhs1.ts diff --git a/tests/cases/fourslash/renameJsSpecialAssignmentRhs2.ts b/tests/cases/fourslash/renameJsSpecialAssignmentRhs2.ts new file mode 100644 index 00000000000..5b4b6e851cf --- /dev/null +++ b/tests/cases/fourslash/renameJsSpecialAssignmentRhs2.ts @@ -0,0 +1,13 @@ +/// +// @allowJs: true +// @Filename: a.js +////const foo = { +//// set: function (x) { +//// this._x = x; +//// }, +//// copy: function (/**/[|x|]) { +//// this._x = [|x|].prop; +//// } +////}; +goTo.marker(); +verify.renameLocations(/*findInStrings*/ false, /*findInComments*/ false);