@@ -15,12 +15,12 @@ module ts {
15
15
if ( node . kind === SyntaxKind . InterfaceDeclaration || node . kind === SyntaxKind . TypeAliasDeclaration ) {
16
16
return ModuleInstanceState . NonInstantiated ;
17
17
}
18
- // 2. const enum declarations don't make module instantiated
18
+ // 2. const enum declarations
19
19
else if ( isConstEnumDeclaration ( node ) ) {
20
20
return ModuleInstanceState . ConstEnumOnly ;
21
21
}
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 ) ) {
24
24
return ModuleInstanceState . NonInstantiated ;
25
25
}
26
26
// 4. other uninstantiated module declarations.
@@ -179,41 +179,39 @@ module ts {
179
179
}
180
180
181
181
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
+ }
202
190
}
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 ) ;
206
207
var local = declareSymbol ( container . locals , undefined , node , exportKind , symbolExcludes ) ;
207
208
local . exportSymbol = declareSymbol ( container . symbol . exports , container . symbol , node , symbolKind , symbolExcludes ) ;
208
209
node . localSymbol = local ;
209
210
}
210
211
else {
211
- declareSymbol ( container . symbol . exports , container . symbol , node , symbolKind , symbolExcludes ) ;
212
+ declareSymbol ( container . locals , undefined , node , symbolKind , symbolExcludes ) ;
212
213
}
213
214
}
214
- else {
215
- declareSymbol ( container . locals , undefined , node , symbolKind , symbolExcludes ) ;
216
- }
217
215
}
218
216
219
217
// 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 {
312
310
}
313
311
}
314
312
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
+
315
320
function bindFunctionOrConstructorType ( node : SignatureDeclaration ) {
316
321
// For a given function symbol "<...>(...) => T" we want to generate a symbol identical
317
322
// to the one we would get for: { <...>(...): T }
@@ -467,9 +472,23 @@ module ts {
467
472
case SyntaxKind . ModuleDeclaration :
468
473
bindModuleDeclaration ( < ModuleDeclaration > node ) ;
469
474
break ;
470
- case SyntaxKind . ImportDeclaration :
475
+ case SyntaxKind . ImportEqualsDeclaration :
476
+ case SyntaxKind . NamespaceImport :
477
+ case SyntaxKind . ImportSpecifier :
478
+ case SyntaxKind . ExportSpecifier :
471
479
bindDeclaration ( < Declaration > node , SymbolFlags . Import , SymbolFlags . ImportExcludes , /*isBlockScopeContainer*/ false ) ;
472
480
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 ;
473
492
case SyntaxKind . SourceFile :
474
493
if ( isExternalModule ( < SourceFile > node ) ) {
475
494
bindAnonymousDeclaration ( < SourceFile > node , SymbolFlags . ValueModule , '"' + removeFileExtension ( ( < SourceFile > node ) . fileName ) + '"' , /*isBlockScopeContainer*/ true ) ;
0 commit comments