@@ -9,8 +9,8 @@ module ts {
9
9
10
10
export function getModuleInstanceState ( node : Node ) : ModuleInstanceState {
11
11
// A module is uninstantiated if it contains only
12
- // 1. interface declarations
13
- if ( node . kind === SyntaxKind . InterfaceDeclaration ) {
12
+ // 1. interface declarations, type alias declarations
13
+ if ( node . kind === SyntaxKind . InterfaceDeclaration || node . kind === SyntaxKind . TypeAliasDeclaration ) {
14
14
return ModuleInstanceState . NonInstantiated ;
15
15
}
16
16
// 2. const enum declarations don't make module instantiated
@@ -50,12 +50,13 @@ module ts {
50
50
}
51
51
52
52
/**
53
- * Returns false if any of the following are true:
54
- * 1. declaration has no name
55
- * 2. declaration has a literal name (not computed)
56
- * 3. declaration has a computed property name that is a known symbol
53
+ * A declaration has a dynamic name if both of the following are true:
54
+ * 1. The declaration has a computed property name
55
+ * 2. The computed name is *not* expressed as Symbol.<name>, where name
56
+ * is a property of the Symbol constructor that denotes a built in
57
+ * Symbol.
57
58
*/
58
- export function hasComputedNameButNotSymbol ( declaration : Declaration ) : boolean {
59
+ export function hasDynamicName ( declaration : Declaration ) : boolean {
59
60
return declaration . name && declaration . name . kind === SyntaxKind . ComputedPropertyName ;
60
61
}
61
62
@@ -96,7 +97,7 @@ module ts {
96
97
if ( node . kind === SyntaxKind . ModuleDeclaration && node . name . kind === SyntaxKind . StringLiteral ) {
97
98
return '"' + ( < LiteralExpression > node . name ) . text + '"' ;
98
99
}
99
- Debug . assert ( ! hasComputedNameButNotSymbol ( node ) ) ;
100
+ Debug . assert ( ! hasDynamicName ( node ) ) ;
100
101
return ( < Identifier | LiteralExpression > node . name ) . text ;
101
102
}
102
103
switch ( node . kind ) {
@@ -118,11 +119,7 @@ module ts {
118
119
}
119
120
120
121
function declareSymbol ( symbols : SymbolTable , parent : Symbol , node : Declaration , includes : SymbolFlags , excludes : SymbolFlags ) : Symbol {
121
- // Nodes with computed property names will not get symbols, because the type checker
122
- // does not make properties for them.
123
- if ( hasComputedNameButNotSymbol ( node ) ) {
124
- return undefined ;
125
- }
122
+ Debug . assert ( ! hasDynamicName ( node ) ) ;
126
123
127
124
var name = getDeclarationName ( node ) ;
128
125
if ( name !== undefined ) {
@@ -395,14 +392,14 @@ module ts {
395
392
break ;
396
393
case SyntaxKind . PropertyDeclaration :
397
394
case SyntaxKind . PropertySignature :
398
- bindDeclaration ( < Declaration > node , SymbolFlags . Property | ( ( < PropertyDeclaration > node ) . questionToken ? SymbolFlags . Optional : 0 ) , SymbolFlags . PropertyExcludes , /*isBlockScopeContainer*/ false ) ;
395
+ bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . Property | ( ( < PropertyDeclaration > node ) . questionToken ? SymbolFlags . Optional : 0 ) , SymbolFlags . PropertyExcludes , /*isBlockScopeContainer*/ false ) ;
399
396
break ;
400
397
case SyntaxKind . PropertyAssignment :
401
398
case SyntaxKind . ShorthandPropertyAssignment :
402
- bindDeclaration ( < Declaration > node , SymbolFlags . Property , SymbolFlags . PropertyExcludes , /*isBlockScopeContainer*/ false ) ;
399
+ bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . Property , SymbolFlags . PropertyExcludes , /*isBlockScopeContainer*/ false ) ;
403
400
break ;
404
401
case SyntaxKind . EnumMember :
405
- bindDeclaration ( < Declaration > node , SymbolFlags . EnumMember , SymbolFlags . EnumMemberExcludes , /*isBlockScopeContainer*/ false ) ;
402
+ bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . EnumMember , SymbolFlags . EnumMemberExcludes , /*isBlockScopeContainer*/ false ) ;
406
403
break ;
407
404
case SyntaxKind . CallSignature :
408
405
case SyntaxKind . ConstructSignature :
@@ -415,7 +412,7 @@ module ts {
415
412
// as other properties in the object literal. So we use SymbolFlags.PropertyExcludes
416
413
// so that it will conflict with any other object literal members with the same
417
414
// name.
418
- bindDeclaration ( < Declaration > node , SymbolFlags . Method | ( ( < MethodDeclaration > node ) . questionToken ? SymbolFlags . Optional : 0 ) ,
415
+ bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . Method | ( ( < MethodDeclaration > node ) . questionToken ? SymbolFlags . Optional : 0 ) ,
419
416
isObjectLiteralMethod ( node ) ? SymbolFlags . PropertyExcludes : SymbolFlags . MethodExcludes , /*isBlockScopeContainer*/ true ) ;
420
417
break ;
421
418
case SyntaxKind . FunctionDeclaration :
@@ -425,10 +422,10 @@ module ts {
425
422
bindDeclaration ( < Declaration > node , SymbolFlags . Constructor , /*symbolExcludes:*/ 0 , /*isBlockScopeContainer:*/ true ) ;
426
423
break ;
427
424
case SyntaxKind . GetAccessor :
428
- bindDeclaration ( < Declaration > node , SymbolFlags . GetAccessor , SymbolFlags . GetAccessorExcludes , /*isBlockScopeContainer*/ true ) ;
425
+ bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . GetAccessor , SymbolFlags . GetAccessorExcludes , /*isBlockScopeContainer*/ true ) ;
429
426
break ;
430
427
case SyntaxKind . SetAccessor :
431
- bindDeclaration ( < Declaration > node , SymbolFlags . SetAccessor , SymbolFlags . SetAccessorExcludes , /*isBlockScopeContainer*/ true ) ;
428
+ bindPropertyOrMethodOrAccessor ( < Declaration > node , SymbolFlags . SetAccessor , SymbolFlags . SetAccessorExcludes , /*isBlockScopeContainer*/ true ) ;
432
429
break ;
433
430
434
431
case SyntaxKind . FunctionType :
@@ -510,5 +507,14 @@ module ts {
510
507
declareSymbol ( classDeclaration . symbol . members , classDeclaration . symbol , node , SymbolFlags . Property , SymbolFlags . PropertyExcludes ) ;
511
508
}
512
509
}
510
+
511
+ function bindPropertyOrMethodOrAccessor ( node : Declaration , symbolKind : SymbolFlags , symbolExcludes : SymbolFlags , isBlockScopeContainer : boolean ) {
512
+ if ( hasDynamicName ( node ) ) {
513
+ bindAnonymousDeclaration ( node , symbolKind , "__computed" , isBlockScopeContainer ) ;
514
+ }
515
+ else {
516
+ bindDeclaration ( node , symbolKind , symbolExcludes , isBlockScopeContainer ) ;
517
+ }
518
+ }
513
519
}
514
520
}
0 commit comments