Skip to content

Commit e441dd0

Browse files
committed
Binder:clean up bindPropertyAssignment and friends
1 parent 74faa3d commit e441dd0

1 file changed

Lines changed: 22 additions & 39 deletions

File tree

src/compiler/binder.ts

Lines changed: 22 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -425,12 +425,8 @@ namespace ts {
425425
return symbol;
426426
}
427427

428-
function declareModuleMember(
429-
node: Declaration,
430-
symbolFlags: SymbolFlags,
431-
symbolExcludes: SymbolFlags,
432-
hasExportModifier = getCombinedModifierFlags(node) & ModifierFlags.Export
433-
): Symbol {
428+
function declareModuleMember(node: Declaration, symbolFlags: SymbolFlags, symbolExcludes: SymbolFlags): Symbol {
429+
const hasExportModifier = getCombinedModifierFlags(node) & ModifierFlags.Export;
434430
if (symbolFlags & SymbolFlags.Alias) {
435431
if (node.kind === SyntaxKind.ExportSpecifier || (node.kind === SyntaxKind.ImportEqualsDeclaration && hasExportModifier)) {
436432
return declareSymbol(container.symbol.exports, container.symbol, node, symbolFlags, symbolExcludes);
@@ -2404,52 +2400,39 @@ namespace ts {
24042400
}
24052401

24062402
function lookupSymbolForName(name: __String) {
2407-
return (container.symbol && container.symbol.exports && container.symbol.exports.get(name)) || (container.locals && container.locals.get(name));
2408-
}
2409-
2410-
function reallyLookup(name: __String) {
2411-
const local = container.locals.get(name)
2403+
const local = container.locals && container.locals.get(name);
24122404
if (local) {
24132405
return local.exportSymbol || local;
24142406
}
2415-
return container.symbol && container.symbol.exports.get(name);
2407+
return container.symbol && container.symbol.exports && container.symbol.exports.get(name);
24162408
}
24172409

2418-
function bindPropertyAssignment(functionName: __String, propertyAccessExpression: PropertyAccessExpression, isPrototypeProperty: boolean) {
2419-
let targetSymbol = lookupSymbolForName(functionName);
2420-
targetSymbol = targetSymbol && targetSymbol.exportSymbol || targetSymbol;
2421-
if (targetSymbol && isDeclarationOfFunctionOrClassExpression(targetSymbol)) {
2422-
targetSymbol = (targetSymbol.valueDeclaration as VariableDeclaration).initializer.symbol;
2423-
}
2424-
Debug.assert(propertyAccessExpression.parent.kind === SyntaxKind.BinaryExpression || propertyAccessExpression.parent.kind === SyntaxKind.ExpressionStatement);
2410+
function bindPropertyAssignment(functionName: __String, propertyAccess: PropertyAccessExpression, isPrototypeProperty: boolean) {
2411+
const symbol = lookupSymbolForName(functionName);
2412+
let targetSymbol = symbol && isDeclarationOfFunctionOrClassExpression(symbol) ?
2413+
(symbol.valueDeclaration as VariableDeclaration).initializer.symbol :
2414+
symbol;
2415+
Debug.assert(propertyAccess.parent.kind === SyntaxKind.BinaryExpression || propertyAccess.parent.kind === SyntaxKind.ExpressionStatement);
24252416
let isLegalPosition: boolean;
2426-
if (propertyAccessExpression.parent.kind === SyntaxKind.BinaryExpression) {
2427-
const initializerKind = (propertyAccessExpression.parent as BinaryExpression).right.kind;
2417+
if (propertyAccess.parent.kind === SyntaxKind.BinaryExpression) {
2418+
const initializerKind = (propertyAccess.parent as BinaryExpression).right.kind;
24282419
isLegalPosition = (initializerKind === SyntaxKind.ClassExpression || initializerKind === SyntaxKind.FunctionExpression) &&
2429-
propertyAccessExpression.parent.parent.parent.kind === SyntaxKind.SourceFile;
2420+
propertyAccess.parent.parent.parent.kind === SyntaxKind.SourceFile;
24302421
}
24312422
else {
2432-
isLegalPosition = propertyAccessExpression.parent.parent.kind === SyntaxKind.SourceFile;
2423+
isLegalPosition = propertyAccess.parent.parent.kind === SyntaxKind.SourceFile;
24332424
}
24342425
if (!isPrototypeProperty && (!targetSymbol || !(targetSymbol.flags & SymbolFlags.Namespace)) && isLegalPosition) {
2435-
// TODO: Update refactoring to understand that ES5 classes now have statics in a namespace instead
2436-
// const hasExportModifier = targetSymbol && getCombinedModifierFlags(targetSymbol.valueDeclaration) & ModifierFlags.Export;
2437-
Debug.assert(isIdentifier(propertyAccessExpression.expression));
2438-
Debug.assertEqual(propertyAccessExpression.expression.kind, SyntaxKind.Identifier);
2439-
// targetSymbol = declareSymbol(symbolTable, targetSymbol.parent, propertyAccessExpression.expression as Identifier, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes);
2440-
2441-
const symbol = reallyLookup(functionName);
2442-
if (symbol) {
2443-
addDeclarationToSymbol(symbol, propertyAccessExpression.expression as Identifier, SymbolFlags.ValueModule | SymbolFlags.NamespaceModule);
2426+
Debug.assert(isIdentifier(propertyAccess.expression));
2427+
const identifier = propertyAccess.expression as Identifier;
2428+
if (targetSymbol) {
2429+
addDeclarationToSymbol(symbol, identifier, SymbolFlags.Module);
24442430
}
2445-
else if (!targetSymbol) {
2446-
targetSymbol = declareSymbol(container.locals, undefined, propertyAccessExpression.expression as Identifier, SymbolFlags.ValueModule | SymbolFlags.NamespaceModule, SymbolFlags.ValueModuleExcludes | SymbolFlags.NamespaceModuleExcludes);
2431+
else {
2432+
targetSymbol = declareSymbol(container.locals, /*parent*/ undefined, identifier, SymbolFlags.Module, SymbolFlags.ValueModuleExcludes);
24472433
}
24482434
}
2449-
if (targetSymbol && isDeclarationOfFunctionOrClassExpression(targetSymbol)) { // TODO: Probably can move inside the preceding if
2450-
targetSymbol = (targetSymbol.valueDeclaration as VariableDeclaration).initializer.symbol;
2451-
}
2452-
if (!targetSymbol || !(targetSymbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.NamespaceModule | SymbolFlags.ExportValue))) {
2435+
if (!targetSymbol || !(targetSymbol.flags & (SymbolFlags.Function | SymbolFlags.Class | SymbolFlags.NamespaceModule))) {
24532436
return;
24542437
}
24552438

@@ -2459,7 +2442,7 @@ namespace ts {
24592442
(targetSymbol.exports || (targetSymbol.exports = createSymbolTable()));
24602443

24612444
// Declare the method/property
2462-
declareSymbol(symbolTable, targetSymbol, propertyAccessExpression, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
2445+
declareSymbol(symbolTable, targetSymbol, propertyAccess, SymbolFlags.Property, SymbolFlags.PropertyExcludes);
24632446
}
24642447

24652448
function bindCallExpression(node: CallExpression) {

0 commit comments

Comments
 (0)