@@ -349,17 +349,20 @@ namespace ts {
349349 // Otherwise, we'll be merging into a compatible existing symbol (for example when
350350 // you have multiple 'vars' with the same name in the same container). In this case
351351 // just add this node into the declarations list of the symbol.
352- symbol = symbolTable [ name ] || ( symbolTable [ name ] = createSymbol ( SymbolFlags . None , name ) ) ;
352+ symbol = symbolTable . get ( name ) ;
353+ if ( ! symbol ) {
354+ symbolTable . set ( name , symbol = createSymbol ( SymbolFlags . None , name ) ) ;
355+ }
353356
354357 if ( name && ( includes & SymbolFlags . Classifiable ) ) {
355- classifiableNames [ name ] = name ;
358+ classifiableNames . set ( name , name ) ;
356359 }
357360
358361 if ( symbol . flags & excludes ) {
359362 if ( symbol . isReplaceableByMethod ) {
360363 // Javascript constructor-declared symbols can be discarded in favor of
361364 // prototype symbols like methods.
362- symbol = symbolTable [ name ] = createSymbol ( SymbolFlags . None , name ) ;
365+ symbolTable . set ( name , symbol = createSymbol ( SymbolFlags . None , name ) ) ;
363366 }
364367 else {
365368 if ( node . name ) {
@@ -1512,7 +1515,7 @@ namespace ts {
15121515 errorOnFirstToken ( node , Diagnostics . export_modifier_cannot_be_applied_to_ambient_modules_and_module_augmentations_since_they_are_always_visible ) ;
15131516 }
15141517 if ( isExternalModuleAugmentation ( node ) ) {
1515- declareSymbolAndAddToSymbolTable ( node , SymbolFlags . NamespaceModule , SymbolFlags . NamespaceModuleExcludes ) ;
1518+ declareModuleSymbol ( node ) ;
15161519 }
15171520 else {
15181521 let pattern : Pattern | undefined ;
@@ -1534,12 +1537,8 @@ namespace ts {
15341537 }
15351538 }
15361539 else {
1537- const state = getModuleInstanceState ( node ) ;
1538- if ( state === ModuleInstanceState . NonInstantiated ) {
1539- declareSymbolAndAddToSymbolTable ( node , SymbolFlags . NamespaceModule , SymbolFlags . NamespaceModuleExcludes ) ;
1540- }
1541- else {
1542- declareSymbolAndAddToSymbolTable ( node , SymbolFlags . ValueModule , SymbolFlags . ValueModuleExcludes ) ;
1540+ const state = declareModuleSymbol ( node ) ;
1541+ if ( state !== ModuleInstanceState . NonInstantiated ) {
15431542 if ( node . symbol . flags & ( SymbolFlags . Function | SymbolFlags . Class | SymbolFlags . RegularEnum ) ) {
15441543 // if module was already merged with some function, class or non-const enum
15451544 // treat is a non-const-enum-only
@@ -1560,6 +1559,15 @@ namespace ts {
15601559 }
15611560 }
15621561
1562+ function declareModuleSymbol ( node : ModuleDeclaration ) : ModuleInstanceState {
1563+ const state = getModuleInstanceState ( node ) ;
1564+ const instantiated = state !== ModuleInstanceState . NonInstantiated ;
1565+ declareSymbolAndAddToSymbolTable ( node ,
1566+ instantiated ? SymbolFlags . ValueModule : SymbolFlags . NamespaceModule ,
1567+ instantiated ? SymbolFlags . ValueModuleExcludes : SymbolFlags . NamespaceModuleExcludes ) ;
1568+ return state ;
1569+ }
1570+
15631571 function bindFunctionOrConstructorType ( node : SignatureDeclaration ) : void {
15641572 // For a given function symbol "<...>(...) => T" we want to generate a symbol identical
15651573 // to the one we would get for: { <...>(...): T }
@@ -1573,7 +1581,7 @@ namespace ts {
15731581 const typeLiteralSymbol = createSymbol ( SymbolFlags . TypeLiteral , "__type" ) ;
15741582 addDeclarationToSymbol ( typeLiteralSymbol , node , SymbolFlags . TypeLiteral ) ;
15751583 typeLiteralSymbol . members = createMap < Symbol > ( ) ;
1576- typeLiteralSymbol . members [ symbol . name ] = symbol ;
1584+ typeLiteralSymbol . members . set ( symbol . name , symbol ) ;
15771585 }
15781586
15791587 function bindObjectLiteralExpression ( node : ObjectLiteralExpression ) {
@@ -1604,9 +1612,9 @@ namespace ts {
16041612 ? ElementKind . Property
16051613 : ElementKind . Accessor ;
16061614
1607- const existingKind = seen [ identifier . text ] ;
1615+ const existingKind = seen . get ( identifier . text ) ;
16081616 if ( ! existingKind ) {
1609- seen [ identifier . text ] = currentKind ;
1617+ seen . set ( identifier . text , currentKind ) ;
16101618 continue ;
16111619 }
16121620
@@ -2211,7 +2219,7 @@ namespace ts {
22112219 constructorFunction . parent = classPrototype ;
22122220 classPrototype . parent = leftSideOfAssignment ;
22132221
2214- const funcSymbol = container . locals [ constructorFunction . text ] ;
2222+ const funcSymbol = container . locals . get ( constructorFunction . text ) ;
22152223 if ( ! funcSymbol || ! ( funcSymbol . flags & SymbolFlags . Function || isDeclarationOfFunctionExpression ( funcSymbol ) ) ) {
22162224 return ;
22172225 }
@@ -2242,7 +2250,7 @@ namespace ts {
22422250 bindAnonymousDeclaration ( node , SymbolFlags . Class , bindingName ) ;
22432251 // Add name of class expression into the map for semantic classifier
22442252 if ( node . name ) {
2245- classifiableNames [ node . name . text ] = node . name . text ;
2253+ classifiableNames . set ( node . name . text , node . name . text ) ;
22462254 }
22472255 }
22482256
@@ -2258,14 +2266,14 @@ namespace ts {
22582266 // module might have an exported variable called 'prototype'. We can't allow that as
22592267 // that would clash with the built-in 'prototype' for the class.
22602268 const prototypeSymbol = createSymbol ( SymbolFlags . Property | SymbolFlags . Prototype , "prototype" ) ;
2261- if ( symbol . exports [ prototypeSymbol . name ] ) {
2269+ const symbolExport = symbol . exports . get ( prototypeSymbol . name ) ;
2270+ if ( symbolExport ) {
22622271 if ( node . name ) {
22632272 node . name . parent = node ;
22642273 }
2265- file . bindDiagnostics . push ( createDiagnosticForNode ( symbol . exports [ prototypeSymbol . name ] . declarations [ 0 ] ,
2266- Diagnostics . Duplicate_identifier_0 , prototypeSymbol . name ) ) ;
2274+ file . bindDiagnostics . push ( createDiagnosticForNode ( symbolExport . declarations [ 0 ] , Diagnostics . Duplicate_identifier_0 , prototypeSymbol . name ) ) ;
22672275 }
2268- symbol . exports [ prototypeSymbol . name ] = prototypeSymbol ;
2276+ symbol . exports . set ( prototypeSymbol . name , prototypeSymbol ) ;
22692277 prototypeSymbol . parent = symbol ;
22702278 }
22712279
0 commit comments