@@ -15,12 +15,12 @@ module ts {
1515 if ( node . kind === SyntaxKind . InterfaceDeclaration || node . kind === SyntaxKind . TypeAliasDeclaration ) {
1616 return ModuleInstanceState . NonInstantiated ;
1717 }
18- // 2. const enum declarations don't make module instantiated
18+ // 2. const enum declarations
1919 else if ( isConstEnumDeclaration ( node ) ) {
2020 return ModuleInstanceState . ConstEnumOnly ;
2121 }
22- // 3. non - exported import declarations
23- else if ( node . kind === SyntaxKind . ImportDeclaration && ! ( node . flags & NodeFlags . Export ) ) {
22+ // 3. non- exported import declarations
23+ else if ( ( node . kind === SyntaxKind . ImportDeclaration || node . kind === SyntaxKind . ImportEqualsDeclaration ) && ! ( node . flags & NodeFlags . Export ) ) {
2424 return ModuleInstanceState . NonInstantiated ;
2525 }
2626 // 4. other uninstantiated module declarations.
@@ -179,41 +179,39 @@ module ts {
179179 }
180180
181181 function declareModuleMember ( node : Declaration , symbolKind : SymbolFlags , symbolExcludes : SymbolFlags ) {
182- // Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue,
183- // ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set
184- // on it. There are 2 main reasons:
185- //
186- // 1. We treat locals and exports of the same name as mutually exclusive within a container.
187- // That means the binder will issue a Duplicate Identifier error if you mix locals and exports
188- // with the same name in the same container.
189- // TODO: Make this a more specific error and decouple it from the exclusion logic.
190- // 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol,
191- // but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way
192- // when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope.
193- var exportKind = 0 ;
194- if ( symbolKind & SymbolFlags . Value ) {
195- exportKind |= SymbolFlags . ExportValue ;
196- }
197- if ( symbolKind & SymbolFlags . Type ) {
198- exportKind |= SymbolFlags . ExportType ;
199- }
200- if ( symbolKind & SymbolFlags . Namespace ) {
201- exportKind |= SymbolFlags . ExportNamespace ;
182+ var hasExportModifier = getCombinedNodeFlags ( node ) & NodeFlags . Export ;
183+ if ( symbolKind & SymbolFlags . Import ) {
184+ if ( node . kind === SyntaxKind . ExportSpecifier || ( node . kind === SyntaxKind . ImportEqualsDeclaration && hasExportModifier ) ) {
185+ declareSymbol ( container . symbol . exports , container . symbol , node , symbolKind , symbolExcludes ) ;
186+ }
187+ else {
188+ declareSymbol ( container . locals , undefined , node , symbolKind , symbolExcludes ) ;
189+ }
202190 }
203-
204- if ( getCombinedNodeFlags ( node ) & NodeFlags . Export || ( node . kind !== SyntaxKind . ImportDeclaration && isAmbientContext ( container ) ) ) {
205- if ( exportKind ) {
191+ else {
192+ // Exported module members are given 2 symbols: A local symbol that is classified with an ExportValue,
193+ // ExportType, or ExportContainer flag, and an associated export symbol with all the correct flags set
194+ // on it. There are 2 main reasons:
195+ //
196+ // 1. We treat locals and exports of the same name as mutually exclusive within a container.
197+ // That means the binder will issue a Duplicate Identifier error if you mix locals and exports
198+ // with the same name in the same container.
199+ // TODO: Make this a more specific error and decouple it from the exclusion logic.
200+ // 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol,
201+ // but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way
202+ // when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope.
203+ if ( hasExportModifier || isAmbientContext ( container ) ) {
204+ var exportKind = ( symbolKind & SymbolFlags . Value ? SymbolFlags . ExportValue : 0 ) |
205+ ( symbolKind & SymbolFlags . Type ? SymbolFlags . ExportType : 0 ) |
206+ ( symbolKind & SymbolFlags . Namespace ? SymbolFlags . ExportNamespace : 0 ) ;
206207 var local = declareSymbol ( container . locals , undefined , node , exportKind , symbolExcludes ) ;
207208 local . exportSymbol = declareSymbol ( container . symbol . exports , container . symbol , node , symbolKind , symbolExcludes ) ;
208209 node . localSymbol = local ;
209210 }
210211 else {
211- declareSymbol ( container . symbol . exports , container . symbol , node , symbolKind , symbolExcludes ) ;
212+ declareSymbol ( container . locals , undefined , node , symbolKind , symbolExcludes ) ;
212213 }
213214 }
214- else {
215- declareSymbol ( container . locals , undefined , node , symbolKind , symbolExcludes ) ;
216- }
217215 }
218216
219217 // All container nodes are kept on a linked list in declaration order. This list is used by the getLocalNameOfContainer function
@@ -312,6 +310,13 @@ module ts {
312310 }
313311 }
314312
313+ function bindExportDeclaration ( node : ExportDeclaration ) {
314+ if ( ! node . exportClause ) {
315+ ( ( < ExportContainer > container ) . exportStars || ( ( < ExportContainer > container ) . exportStars = [ ] ) ) . push ( node ) ;
316+ }
317+ bindChildren ( node , 0 , /*isBlockScopeContainer*/ false ) ;
318+ }
319+
315320 function bindFunctionOrConstructorType ( node : SignatureDeclaration ) {
316321 // For a given function symbol "<...>(...) => T" we want to generate a symbol identical
317322 // to the one we would get for: { <...>(...): T }
@@ -467,9 +472,23 @@ module ts {
467472 case SyntaxKind . ModuleDeclaration :
468473 bindModuleDeclaration ( < ModuleDeclaration > node ) ;
469474 break ;
470- case SyntaxKind . ImportDeclaration :
475+ case SyntaxKind . ImportEqualsDeclaration :
476+ case SyntaxKind . NamespaceImport :
477+ case SyntaxKind . ImportSpecifier :
478+ case SyntaxKind . ExportSpecifier :
471479 bindDeclaration ( < Declaration > node , SymbolFlags . Import , SymbolFlags . ImportExcludes , /*isBlockScopeContainer*/ false ) ;
472480 break ;
481+ case SyntaxKind . ExportDeclaration :
482+ bindExportDeclaration ( < ExportDeclaration > node ) ;
483+ break ;
484+ case SyntaxKind . ImportClause :
485+ if ( ( < ImportClause > node ) . name ) {
486+ bindDeclaration ( < Declaration > node , SymbolFlags . Import , SymbolFlags . ImportExcludes , /*isBlockScopeContainer*/ false ) ;
487+ }
488+ else {
489+ bindChildren ( node , 0 , /*isBlockScopeContainer*/ false ) ;
490+ }
491+ break ;
473492 case SyntaxKind . SourceFile :
474493 if ( isExternalModule ( < SourceFile > node ) ) {
475494 bindAnonymousDeclaration ( < SourceFile > node , SymbolFlags . ValueModule , '"' + removeFileExtension ( ( < SourceFile > node ) . fileName ) + '"' , /*isBlockScopeContainer*/ true ) ;
0 commit comments