Skip to content

Commit 0aa8a6e

Browse files
committed
Consolidate bindProperty logic in one function
1 parent 4b8396b commit 0aa8a6e

File tree

1 file changed

+15
-26
lines changed

1 file changed

+15
-26
lines changed

src/compiler/binder.ts

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1928,7 +1928,7 @@ namespace ts {
19281928
bindThisPropertyAssignment(<BinaryExpression>node);
19291929
break;
19301930
case SpecialPropertyAssignmentKind.Property:
1931-
bindPropertyAssignment(<BinaryExpression>node);
1931+
bindStaticPropertyAssignment(<BinaryExpression>node);
19321932
break;
19331933
case SpecialPropertyAssignmentKind.None:
19341934
// Nothing to do
@@ -2220,25 +2220,10 @@ namespace ts {
22202220
constructorFunction.parent = classPrototype;
22212221
classPrototype.parent = leftSideOfAssignment;
22222222

2223-
let funcSymbol = container.locals.get(constructorFunction.text);
2224-
if (funcSymbol && isDeclarationOfFunctionOrClassExpression(funcSymbol)) {
2225-
funcSymbol = (funcSymbol.valueDeclaration as VariableDeclaration).initializer.symbol;
2226-
}
2227-
2228-
if (!funcSymbol || !(funcSymbol.flags & (SymbolFlags.Function | SymbolFlags.Class))) {
2229-
return;
2230-
}
2231-
2232-
// Set up the members collection if it doesn't exist already
2233-
if (!funcSymbol.members) {
2234-
funcSymbol.members = createMap<Symbol>();
2235-
}
2236-
2237-
// Declare the method/property
2238-
declareSymbol(funcSymbol.members, funcSymbol, leftSideOfAssignment, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
2223+
bindPropertyAssignment(constructorFunction.text, leftSideOfAssignment, /*isPrototypeProperty*/ true);
22392224
}
22402225

2241-
function bindPropertyAssignment(node: BinaryExpression) {
2226+
function bindStaticPropertyAssignment(node: BinaryExpression) {
22422227
// We saw a node of the form 'x.y = z'. Declare a 'member' y on x if x was a function.
22432228

22442229
// Look up the function in the local scope, since prototype assignments should
@@ -2250,22 +2235,26 @@ namespace ts {
22502235
leftSideOfAssignment.parent = node;
22512236
target.parent = leftSideOfAssignment;
22522237

2253-
let funcSymbol = container.locals.get(target.text);
2254-
if (funcSymbol && isDeclarationOfFunctionOrClassExpression(funcSymbol)) {
2255-
funcSymbol = (funcSymbol.valueDeclaration as VariableDeclaration).initializer.symbol;
2238+
bindPropertyAssignment(target.text, leftSideOfAssignment, /*isPrototypeProperty*/ false);
2239+
}
2240+
2241+
function bindPropertyAssignment(functionName: string, propertyAccessExpression: PropertyAccessExpression, isPrototypeProperty: boolean) {
2242+
let targetSymbol = container.locals.get(functionName);
2243+
if (targetSymbol && isDeclarationOfFunctionOrClassExpression(targetSymbol)) {
2244+
targetSymbol = (targetSymbol.valueDeclaration as VariableDeclaration).initializer.symbol;
22562245
}
22572246

2258-
if (!funcSymbol || !(funcSymbol.flags & (SymbolFlags.Function | SymbolFlags.Class))) {
2247+
if (!targetSymbol || !(targetSymbol.flags & (SymbolFlags.Function | SymbolFlags.Class))) {
22592248
return;
22602249
}
22612250

22622251
// Set up the members collection if it doesn't exist already
2263-
if (!funcSymbol.exports) {
2264-
funcSymbol.exports = createMap<Symbol>();
2265-
}
2252+
const symbolTable = isPrototypeProperty ?
2253+
(targetSymbol.members || (targetSymbol.members = createMap<Symbol>())):
2254+
(targetSymbol.exports || (targetSymbol.exports = createMap<Symbol>()));
22662255

22672256
// Declare the method/property
2268-
declareSymbol(funcSymbol.exports, funcSymbol, leftSideOfAssignment, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
2257+
declareSymbol(symbolTable, targetSymbol, propertyAccessExpression, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
22692258
}
22702259

22712260
function bindCallExpression(node: CallExpression) {

0 commit comments

Comments
 (0)