@@ -123,7 +123,7 @@ module ts {
123
123
case SyntaxKind . ExportDeclaration :
124
124
return "__export" ;
125
125
case SyntaxKind . ExportAssignment :
126
- return "default" ;
126
+ return ( < ExportAssignment > node ) . isExportEquals ? "export=" : "default" ;
127
127
case SyntaxKind . FunctionDeclaration :
128
128
case SyntaxKind . ClassDeclaration :
129
129
return node . flags & NodeFlags . Default ? "default" : undefined ;
@@ -188,14 +188,6 @@ module ts {
188
188
return symbol ;
189
189
}
190
190
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
-
199
191
function declareModuleMember ( node : Declaration , symbolKind : SymbolFlags , symbolExcludes : SymbolFlags ) {
200
192
let hasExportModifier = getCombinedNodeFlags ( node ) & NodeFlags . Export ;
201
193
if ( symbolKind & SymbolFlags . Alias ) {
@@ -218,7 +210,7 @@ module ts {
218
210
// 2. When we checkIdentifier in the checker, we set its resolved symbol to the local symbol,
219
211
// but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way
220
212
// 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 ) {
222
214
let exportKind = ( symbolKind & SymbolFlags . Value ? SymbolFlags . ExportValue : 0 ) |
223
215
( symbolKind & SymbolFlags . Type ? SymbolFlags . ExportType : 0 ) |
224
216
( symbolKind & SymbolFlags . Namespace ? SymbolFlags . ExportNamespace : 0 ) ;
@@ -311,7 +303,39 @@ module ts {
311
303
bindChildren ( node , symbolKind , isBlockScopeContainer ) ;
312
304
}
313
305
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
+
314
337
function bindModuleDeclaration ( node : ModuleDeclaration ) {
338
+ setExportContextFlag ( node ) ;
315
339
if ( node . name . kind === SyntaxKind . StringLiteral ) {
316
340
bindDeclaration ( node , SymbolFlags . ValueModule , SymbolFlags . ValueModuleExcludes , /*isBlockScopeContainer*/ true ) ;
317
341
}
@@ -508,15 +532,16 @@ module ts {
508
532
case SyntaxKind . ExportAssignment :
509
533
if ( ( < ExportAssignment > node ) . expression && ( < ExportAssignment > node ) . expression . kind === SyntaxKind . Identifier ) {
510
534
// 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 ) ;
512
536
}
513
537
else {
514
538
// 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 ) ;
516
540
}
517
541
bindChildren ( node , 0 , /*isBlockScopeContainer*/ false ) ;
518
542
break ;
519
543
case SyntaxKind . SourceFile :
544
+ setExportContextFlag ( < SourceFile > node ) ;
520
545
if ( isExternalModule ( < SourceFile > node ) ) {
521
546
bindAnonymousDeclaration ( < SourceFile > node , SymbolFlags . ValueModule , '"' + removeFileExtension ( ( < SourceFile > node ) . fileName ) + '"' , /*isBlockScopeContainer*/ true ) ;
522
547
break ;
0 commit comments