From d3bfed13f8cc1ca1de972ed200bd5bb3012111ba Mon Sep 17 00:00:00 2001 From: Cyrus Najmabadi Date: Sun, 14 Dec 2014 10:03:54 -0800 Subject: [PATCH] Simplify the binder so it does not need to double recurse down constructor parameter nodes. --- src/compiler/binder.ts | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index dfb5482b09c..19ee45a419a 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -292,15 +292,6 @@ module ts { bindChildren(node, symbolKind, isBlockScopeContainer); } - function bindConstructorDeclaration(node: ConstructorDeclaration) { - bindDeclaration(node, SymbolFlags.Constructor, 0, /*isBlockScopeContainer*/ true); - forEach(node.parameters, p => { - if (p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) { - bindDeclaration(p, SymbolFlags.Property, SymbolFlags.PropertyExcludes, /*isBlockScopeContainer*/ false); - } - }); - } - function bindModuleDeclaration(node: ModuleDeclaration) { if (node.name.kind === SyntaxKind.StringLiteral) { bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true); @@ -389,12 +380,7 @@ module ts { bindDeclaration(node, SymbolFlags.TypeParameter, SymbolFlags.TypeParameterExcludes, /*isBlockScopeContainer*/ false); break; case SyntaxKind.Parameter: - if (isBindingPattern((node).name)) { - bindAnonymousDeclaration(node, SymbolFlags.FunctionScopedVariable, getDestructuringParameterName(node), /*isBlockScopeContainer*/ false); - } - else { - bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false); - } + bindParameter(node); break; case SyntaxKind.VariableDeclaration: case SyntaxKind.BindingElement: @@ -437,7 +423,7 @@ module ts { bindDeclaration(node, SymbolFlags.Function, SymbolFlags.FunctionExcludes, /*isBlockScopeContainer*/ true); break; case SyntaxKind.Constructor: - bindConstructorDeclaration(node); + bindDeclaration(node, SymbolFlags.Constructor, /*symbolExcludes:*/ 0, /*isBlockScopeContainer:*/ true); break; case SyntaxKind.GetAccessor: bindDeclaration(node, SymbolFlags.GetAccessor, SymbolFlags.GetAccessorExcludes, /*isBlockScopeContainer*/ true); @@ -508,5 +494,24 @@ module ts { parent = saveParent; } } + + function bindParameter(node: ParameterDeclaration) { + if (isBindingPattern(node.name)) { + bindAnonymousDeclaration(node, SymbolFlags.FunctionScopedVariable, getDestructuringParameterName(node), /*isBlockScopeContainer*/ false); + } + else { + bindDeclaration(node, SymbolFlags.FunctionScopedVariable, SymbolFlags.ParameterExcludes, /*isBlockScopeContainer*/ false); + } + + // If this is a property-parameter, then also declare the property symbol into the + // containing class. + if (node.flags & NodeFlags.AccessibilityModifier && + node.parent.kind === SyntaxKind.Constructor && + node.parent.parent.kind === SyntaxKind.ClassDeclaration) { + + var classDeclaration = node.parent.parent; + declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); + } + } } }