@@ -173,6 +173,14 @@ namespace ts {
173173 return node . name ? declarationNameToString ( node . name ) : getDeclarationName ( node ) ;
174174 }
175175
176+ /**
177+ * Declares a Symbol for the node and adds it to symbols. Reports errors for conflicting identifier names.
178+ * @param symbolTable - The symbol table which node will be added to.
179+ * @param parent - node's parent declaration.
180+ * @param node - The declaration to be added to the symbol table
181+ * @param includes - The SymbolFlags that node has in addition to its declaration type (eg: export, ambient, etc.)
182+ * @param excludes - The flags which node cannot be declared alongside in a symbol table. Used to report forbidden declarations.
183+ */
176184 function declareSymbol ( symbolTable : SymbolTable , parent : Symbol , node : Declaration , includes : SymbolFlags , excludes : SymbolFlags ) : Symbol {
177185 Debug . assert ( ! hasDynamicName ( node ) ) ;
178186
@@ -181,10 +189,11 @@ namespace ts {
181189
182190 let symbol : Symbol ;
183191 if ( name !== undefined ) {
192+
184193 // Check and see if the symbol table already has a symbol with this name. If not,
185194 // create a new symbol with this name and add it to the table. Note that we don't
186195 // give the new symbol any flags *yet*. This ensures that it will not conflict
187- // witht he 'excludes' flags we pass in.
196+ // with the 'excludes' flags we pass in.
188197 //
189198 // If we do get an existing symbol, see if it conflicts with the new symbol we're
190199 // creating. For example, a 'var' symbol and a 'class' symbol will conflict within
@@ -314,6 +323,7 @@ namespace ts {
314323
315324 addToContainerChain ( container ) ;
316325 }
326+
317327 else if ( containerFlags & ContainerFlags . IsBlockScopedContainer ) {
318328 blockScopeContainer = node ;
319329 blockScopeContainer . locals = undefined ;
@@ -882,7 +892,8 @@ namespace ts {
882892 case SyntaxKind . FunctionExpression :
883893 case SyntaxKind . ArrowFunction :
884894 checkStrictModeFunctionName ( < FunctionExpression > node ) ;
885- return bindAnonymousDeclaration ( < FunctionExpression > node , SymbolFlags . Function , "__function" ) ;
895+ let bindingName = ( < FunctionExpression > node ) . name ? ( < FunctionExpression > node ) . name . text : "__function" ;
896+ return bindAnonymousDeclaration ( < FunctionExpression > node , SymbolFlags . Function , bindingName ) ;
886897 case SyntaxKind . ClassExpression :
887898 case SyntaxKind . ClassDeclaration :
888899 return bindClassLikeDeclaration ( < ClassLikeDeclaration > node ) ;
@@ -954,7 +965,8 @@ namespace ts {
954965 bindBlockScopedDeclaration ( node , SymbolFlags . Class , SymbolFlags . ClassExcludes ) ;
955966 }
956967 else {
957- bindAnonymousDeclaration ( node , SymbolFlags . Class , "__class" ) ;
968+ let bindingName = node . name ? node . name . text : "__class" ;
969+ bindAnonymousDeclaration ( node , SymbolFlags . Class , bindingName ) ;
958970 }
959971
960972 let symbol = node . symbol ;
@@ -1044,4 +1056,4 @@ namespace ts {
10441056 : declareSymbolAndAddToSymbolTable ( node , symbolFlags , symbolExcludes ) ;
10451057 }
10461058 }
1047- }
1059+ }
0 commit comments