Skip to content

Commit 07a8f31

Browse files
committed
Correctly merge bindThisPropertyAssignment
Also simply it considerably after noticing that it's *only* called for Javascript files, so there was a lot of dead code for TS cases that never happened.
1 parent 96840c3 commit 07a8f31

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

src/compiler/binder.ts

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,33 +1977,25 @@ namespace ts {
19771977
}
19781978

19791979
function bindThisPropertyAssignment(node: BinaryExpression) {
1980+
Debug.assert(isInJavaScriptFile(node));
19801981
// Declare a 'member' if the container is an ES5 class or ES6 constructor
1981-
let assignee: Node;
19821982
if (container.kind === SyntaxKind.FunctionDeclaration || container.kind === SyntaxKind.FunctionExpression) {
1983-
assignee = container;
1983+
container.symbol.members = container.symbol.members || createMap<Symbol>();
1984+
// It's acceptable for multiple 'this' assignments of the same identifier to occur
1985+
declareSymbol(container.symbol.members, container.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
19841986
}
19851987
else if (container.kind === SyntaxKind.Constructor) {
1986-
if (isInJavaScriptFile(node)) {
1987-
// this.foo assignment in a JavaScript class
1988-
// Bind this property to the containing class
1989-
const saveContainer = container;
1990-
container = container.parent;
1991-
bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property, SymbolFlags.None);
1992-
container = saveContainer;
1993-
return;
1994-
}
1995-
else {
1996-
assignee = container.parent;
1988+
// this.foo assignment in a JavaScript class
1989+
// Bind this property to the containing class
1990+
const saveContainer = container;
1991+
container = container.parent;
1992+
// AND it can be overwritten by subsequent method declarations
1993+
const symbol = bindPropertyOrMethodOrAccessor(node, SymbolFlags.Property, SymbolFlags.None);
1994+
if (symbol) {
1995+
(symbol as Symbol).isReplaceableByMethod = true;
19971996
}
1997+
container = saveContainer;
19981998
}
1999-
else {
2000-
return;
2001-
}
2002-
assignee.symbol.members = assignee.symbol.members || createMap<Symbol>();
2003-
// It's acceptable for multiple 'this' assignments of the same identifier to occur
2004-
// AND it can be overwritten by subsequent method declarations
2005-
const symbol = declareSymbol(assignee.symbol.members, assignee.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes & ~SymbolFlags.Property);
2006-
symbol.isReplaceableByMethod = true;
20071999
}
20082000

20092001
function bindPrototypePropertyAssignment(node: BinaryExpression) {

0 commit comments

Comments
 (0)