diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index 19fdf79a24a..6f0f1ac7863 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1880,12 +1880,20 @@ namespace ts { } function bindThisPropertyAssignment(node: BinaryExpression) { - // Declare a 'member' in case it turns out the container was an ES5 class - if (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.FunctionDeclaration) { - container.symbol.members = container.symbol.members || {}; - // It's acceptable for multiple 'this' assignments of the same identifier to occur - declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property); + // Declare a 'member' in case it turns out the container was an ES5 class or ES6 constructor + let assignee: Node; + if (container.kind === SyntaxKind.FunctionDeclaration || container.kind === SyntaxKind.FunctionDeclaration) { + assignee = container; } + else if (container.kind === SyntaxKind.Constructor) { + assignee = container.parent; + } + else { + return; + } + assignee.symbol.members = assignee.symbol.members || {}; + // It's acceptable for multiple 'this' assignments of the same identifier to occur + declareSymbol(assignee.symbol.members, assignee.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property); } function bindPrototypePropertyAssignment(node: BinaryExpression) { diff --git a/tests/cases/fourslash/renameJsThisProperty03.ts b/tests/cases/fourslash/renameJsThisProperty03.ts new file mode 100644 index 00000000000..f2176538578 --- /dev/null +++ b/tests/cases/fourslash/renameJsThisProperty03.ts @@ -0,0 +1,14 @@ +/// + +// @allowJs: true +// @Filename: a.js +////class C { +//// constructor(y) { +//// this./**/[|x|] = y; +//// } +////} +////var t = new C(12); +////t.[|x|] = 11; + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false); diff --git a/tests/cases/fourslash/renameJsThisProperty04.ts b/tests/cases/fourslash/renameJsThisProperty04.ts new file mode 100644 index 00000000000..e307022c66f --- /dev/null +++ b/tests/cases/fourslash/renameJsThisProperty04.ts @@ -0,0 +1,14 @@ +/// + +// @allowJs: true +// @Filename: a.js +////class C { +//// constructor(y) { +//// this.[|x|] = y; +//// } +////} +////var t = new C(12); +////t./**/[|x|] = 11; + +goTo.marker(); +verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false);