@@ -151,7 +151,17 @@ namespace ts {
151151 break ;
152152 }
153153
154- recordEmittedDeclarationInScope ( node ) ;
154+ // Record these declarations provided that they have a name.
155+ if ( ( node as ClassDeclaration | FunctionDeclaration ) . name ) {
156+ recordEmittedDeclarationInScope ( node as ClassDeclaration | FunctionDeclaration ) ;
157+ }
158+ else {
159+ // These nodes should always have names unless they are default-exports;
160+ // however, class declaration parsing allows for undefined names, so syntactically invalid
161+ // programs may also have an undefined name.
162+ Debug . assert ( node . kind === SyntaxKind . ClassDeclaration || hasModifier ( node , ModifierFlags . Default ) ) ;
163+ }
164+
155165 break ;
156166 }
157167 }
@@ -2639,36 +2649,33 @@ namespace ts {
26392649 /**
26402650 * Records that a declaration was emitted in the current scope, if it was the first
26412651 * declaration for the provided symbol.
2642- *
2643- * NOTE: if there is ever a transformation above this one, we may not be able to rely
2644- * on symbol names.
26452652 */
2646- function recordEmittedDeclarationInScope ( node : Node ) {
2647- const name = node . symbol && node . symbol . escapedName ;
2648- if ( name ) {
2649- if ( ! currentScopeFirstDeclarationsOfName ) {
2650- currentScopeFirstDeclarationsOfName = createUnderscoreEscapedMap < Node > ( ) ;
2651- }
2653+ function recordEmittedDeclarationInScope ( node : FunctionDeclaration | ClassDeclaration | ModuleDeclaration | EnumDeclaration ) {
2654+ if ( ! currentScopeFirstDeclarationsOfName ) {
2655+ currentScopeFirstDeclarationsOfName = createUnderscoreEscapedMap < Node > ( ) ;
2656+ }
26522657
2653- if ( ! currentScopeFirstDeclarationsOfName . has ( name ) ) {
2654- currentScopeFirstDeclarationsOfName . set ( name , node ) ;
2655- }
2658+ const name = declaredNameInScope ( node ) ;
2659+ if ( ! currentScopeFirstDeclarationsOfName . has ( name ) ) {
2660+ currentScopeFirstDeclarationsOfName . set ( name , node ) ;
26562661 }
26572662 }
26582663
26592664 /**
2660- * Determines whether a declaration is the first declaration with the same name emitted
2661- * in the current scope.
2665+ * Determines whether a declaration is the first declaration with
2666+ * the same name emitted in the current scope.
26622667 */
2663- function isFirstEmittedDeclarationInScope ( node : Node ) {
2668+ function isFirstEmittedDeclarationInScope ( node : ModuleDeclaration | EnumDeclaration ) {
26642669 if ( currentScopeFirstDeclarationsOfName ) {
2665- const name = node . symbol && node . symbol . escapedName ;
2666- if ( name ) {
2667- return currentScopeFirstDeclarationsOfName . get ( name ) === node ;
2668- }
2670+ const name = declaredNameInScope ( node ) ;
2671+ return currentScopeFirstDeclarationsOfName . get ( name ) === node ;
26692672 }
2673+ return true ;
2674+ }
26702675
2671- return false ;
2676+ function declaredNameInScope ( node : FunctionDeclaration | ClassDeclaration | ModuleDeclaration | EnumDeclaration ) : __String {
2677+ Debug . assertNode ( node . name , isIdentifier ) ;
2678+ return ( node . name as Identifier ) . escapedText ;
26722679 }
26732680
26742681 /**
@@ -2746,7 +2753,7 @@ namespace ts {
27462753 return createNotEmittedStatement ( node ) ;
27472754 }
27482755
2749- Debug . assert ( isIdentifier ( node . name ) , " TypeScript module should have an Identifier name.") ;
2756+ Debug . assertNode ( node . name , isIdentifier , "A TypeScript namespace should have an Identifier name.") ;
27502757 enableSubstitutionForNamespaceExports ( ) ;
27512758
27522759 const statements : Statement [ ] = [ ] ;
0 commit comments