@@ -123,7 +123,7 @@ module ts {
123123 case SyntaxKind . ExportDeclaration :
124124 return "__export" ;
125125 case SyntaxKind . ExportAssignment :
126- return "default" ;
126+ return ( < ExportAssignment > node ) . isExportEquals ? "export=" : "default" ;
127127 case SyntaxKind . FunctionDeclaration :
128128 case SyntaxKind . ClassDeclaration :
129129 return node . flags & NodeFlags . Default ? "default" : undefined ;
@@ -188,14 +188,6 @@ module ts {
188188 return symbol ;
189189 }
190190
191- function isAmbientContext ( node : Node ) : boolean {
192- while ( node ) {
193- if ( node . flags & NodeFlags . Ambient ) return true ;
194- node = node . parent ;
195- }
196- return false ;
197- }
198-
199191 function declareModuleMember ( node : Declaration , symbolKind : SymbolFlags , symbolExcludes : SymbolFlags ) {
200192 let hasExportModifier = getCombinedNodeFlags ( node ) & NodeFlags . Export ;
201193 if ( symbolKind & SymbolFlags . Alias ) {
@@ -218,7 +210,7 @@ module ts {
218210 // 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol,
219211 // but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way
220212 // when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope.
221- if ( hasExportModifier || isAmbientContext ( container ) ) {
213+ if ( hasExportModifier || container . flags & NodeFlags . ExportContext ) {
222214 let exportKind = ( symbolKind & SymbolFlags . Value ? SymbolFlags . ExportValue : 0 ) |
223215 ( symbolKind & SymbolFlags . Type ? SymbolFlags . ExportType : 0 ) |
224216 ( symbolKind & SymbolFlags . Namespace ? SymbolFlags . ExportNamespace : 0 ) ;
@@ -311,7 +303,39 @@ module ts {
311303 bindChildren ( node , symbolKind , isBlockScopeContainer ) ;
312304 }
313305
306+ function isAmbientContext ( node : Node ) : boolean {
307+ while ( node ) {
308+ if ( node . flags & NodeFlags . Ambient ) return true ;
309+ node = node . parent ;
310+ }
311+ return false ;
312+ }
313+
314+ function hasExportDeclarations ( node : ModuleDeclaration | SourceFile ) : boolean {
315+ var body = node . kind === SyntaxKind . SourceFile ? node : ( < ModuleDeclaration > node ) . body ;
316+ if ( body . kind === SyntaxKind . SourceFile || body . kind === SyntaxKind . ModuleBlock ) {
317+ for ( let stat of ( < Block > body ) . statements ) {
318+ if ( stat . kind === SyntaxKind . ExportDeclaration || stat . kind === SyntaxKind . ExportAssignment ) {
319+ return true ;
320+ }
321+ }
322+ }
323+ return false ;
324+ }
325+
326+ function setExportContextFlag ( node : ModuleDeclaration | SourceFile ) {
327+ // A declaration source file or ambient module declaration that contains no export declarations (but possibly regular
328+ // declarations with export modifiers) is an export context in which declarations are implicitly exported.
329+ if ( isAmbientContext ( node ) && ! hasExportDeclarations ( node ) ) {
330+ node . flags |= NodeFlags . ExportContext ;
331+ }
332+ else {
333+ node . flags &= ~ NodeFlags . ExportContext ;
334+ }
335+ }
336+
314337 function bindModuleDeclaration ( node : ModuleDeclaration ) {
338+ setExportContextFlag ( node ) ;
315339 if ( node . name . kind === SyntaxKind . StringLiteral ) {
316340 bindDeclaration ( node , SymbolFlags . ValueModule , SymbolFlags . ValueModuleExcludes , /*isBlockScopeContainer*/ true ) ;
317341 }
@@ -508,15 +532,16 @@ module ts {
508532 case SyntaxKind . ExportAssignment :
509533 if ( ( < ExportAssignment > node ) . expression && ( < ExportAssignment > node ) . expression . kind === SyntaxKind . Identifier ) {
510534 // An export default clause with an identifier exports all meanings of that identifier
511- declareSymbol ( container . symbol . exports , container . symbol , < Declaration > node , SymbolFlags . Alias , SymbolFlags . AliasExcludes ) ;
535+ declareSymbol ( container . symbol . exports , container . symbol , < Declaration > node , SymbolFlags . Alias , SymbolFlags . PropertyExcludes | SymbolFlags . AliasExcludes ) ;
512536 }
513537 else {
514538 // An export default clause with an expression exports a value
515- declareSymbol ( container . symbol . exports , container . symbol , < Declaration > node , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
539+ declareSymbol ( container . symbol . exports , container . symbol , < Declaration > node , SymbolFlags . Property , SymbolFlags . PropertyExcludes | SymbolFlags . AliasExcludes ) ;
516540 }
517541 bindChildren ( node , 0 , /*isBlockScopeContainer*/ false ) ;
518542 break ;
519543 case SyntaxKind . SourceFile :
544+ setExportContextFlag ( < SourceFile > node ) ;
520545 if ( isExternalModule ( < SourceFile > node ) ) {
521546 bindAnonymousDeclaration ( < SourceFile > node , SymbolFlags . ValueModule , '"' + removeFileExtension ( ( < SourceFile > node ) . fileName ) + '"' , /*isBlockScopeContainer*/ true ) ;
522547 break ;
0 commit comments