Skip to content

Commit abfcdd2

Browse files
committed
Symbol for property assignments in Salsa/ES6 constructors
Previously no symbol at all was created, meaning that Salsa didn't track properties in ES6 code.
1 parent 27a1e91 commit abfcdd2

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

src/compiler/binder.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1880,12 +1880,20 @@ namespace ts {
18801880
}
18811881

18821882
function bindThisPropertyAssignment(node: BinaryExpression) {
1883-
// Declare a 'member' in case it turns out the container was an ES5 class
1884-
if (container.kind === SyntaxKind.FunctionExpression || container.kind === SyntaxKind.FunctionDeclaration) {
1885-
container.symbol.members = container.symbol.members || {};
1886-
// It's acceptable for multiple 'this' assignments of the same identifier to occur
1887-
declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
1883+
// Declare a 'member' in case it turns out the container was an ES5 class or ES6 constructor
1884+
let assignee: Node;
1885+
if (container.kind === SyntaxKind.FunctionDeclaration || container.kind === SyntaxKind.FunctionDeclaration) {
1886+
assignee = container;
18881887
}
1888+
else if (container.kind === SyntaxKind.Constructor) {
1889+
assignee = container.parent;
1890+
}
1891+
else {
1892+
return;
1893+
}
1894+
assignee.symbol.members = assignee.symbol.members || {};
1895+
// It's acceptable for multiple 'this' assignments of the same identifier to occur
1896+
declareSymbol(assignee.symbol.members, assignee.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
18891897
}
18901898

18911899
function bindPrototypePropertyAssignment(node: BinaryExpression) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @allowJs: true
4+
// @Filename: a.js
5+
////class C {
6+
//// constructor(y) {
7+
//// this./**/[|x|] = y;
8+
//// }
9+
////}
10+
////var t = new C(12);
11+
////t.[|x|] = 11;
12+
13+
goTo.marker();
14+
verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @allowJs: true
4+
// @Filename: a.js
5+
////class C {
6+
//// constructor(y) {
7+
//// this.[|x|] = y;
8+
//// }
9+
////}
10+
////var t = new C(12);
11+
////t./**/[|x|] = 11;
12+
13+
goTo.marker();
14+
verify.renameLocations( /*findInStrings*/ false, /*findInComments*/ false);

0 commit comments

Comments
 (0)