@@ -93,10 +93,16 @@ module ts {
9393 return ( < Identifier > node . name ) . text ;
9494 }
9595 switch ( node . kind ) {
96- case SyntaxKind . Constructor : return "__constructor" ;
97- case SyntaxKind . CallSignature : return "__call" ;
98- case SyntaxKind . ConstructSignature : return "__new" ;
99- case SyntaxKind . IndexSignature : return "__index" ;
96+ case SyntaxKind . ConstructorType :
97+ case SyntaxKind . Constructor :
98+ return "__constructor" ;
99+ case SyntaxKind . FunctionType :
100+ case SyntaxKind . CallSignature :
101+ return "__call" ;
102+ case SyntaxKind . ConstructSignature :
103+ return "__new" ;
104+ case SyntaxKind . IndexSignature :
105+ return "__index" ;
100106 }
101107 }
102108
@@ -114,8 +120,11 @@ module ts {
114120 }
115121 // Report errors every position with duplicate declaration
116122 // Report errors on previous encountered declarations
117- var message = symbol . flags & SymbolFlags . BlockScopedVariable ? Diagnostics . Cannot_redeclare_block_scoped_variable_0 : Diagnostics . Duplicate_identifier_0 ;
118- forEach ( symbol . declarations , ( declaration ) => {
123+ var message = symbol . flags & SymbolFlags . BlockScopedVariable
124+ ? Diagnostics . Cannot_redeclare_block_scoped_variable_0
125+ : Diagnostics . Duplicate_identifier_0 ;
126+
127+ forEach ( symbol . declarations , declaration => {
119128 file . semanticErrors . push ( createDiagnosticForNode ( declaration . name , message , getDisplayName ( declaration ) ) ) ;
120129 } ) ;
121130 file . semanticErrors . push ( createDiagnosticForNode ( node . name , message , getDisplayName ( node ) ) ) ;
@@ -233,6 +242,8 @@ module ts {
233242 declareModuleMember ( node , symbolKind , symbolExcludes ) ;
234243 break ;
235244 }
245+ case SyntaxKind . FunctionType :
246+ case SyntaxKind . ConstructorType :
236247 case SyntaxKind . CallSignature :
237248 case SyntaxKind . ConstructSignature :
238249 case SyntaxKind . IndexSignature :
@@ -294,6 +305,25 @@ module ts {
294305 }
295306 }
296307
308+ function bindFunctionOrConstructorType ( node : SignatureDeclaration ) {
309+ // For a given function symbol "<...>(...) => T" we want to generate a symbol identical
310+ // to the one we would get for: { <...>(...): T }
311+ //
312+ // We do that by making an anonymous type literal symbol, and then setting the function
313+ // symbol as its sole member. To the rest of the system, this symbol will be indistinguishable
314+ // from an actual type literal symbol you would have gotten had you used the long form.
315+
316+ var symbolKind = node . kind === SyntaxKind . FunctionType ? SymbolFlags . CallSignature : SymbolFlags . ConstructSignature ;
317+ var symbol = createSymbol ( symbolKind , getDeclarationName ( node ) ) ;
318+ addDeclarationToSymbol ( symbol , node , symbolKind ) ;
319+ bindChildren ( node , symbolKind , /*isBlockScopeContainer:*/ false ) ;
320+
321+ var typeLiteralSymbol = createSymbol ( SymbolFlags . TypeLiteral , "__type" ) ;
322+ addDeclarationToSymbol ( typeLiteralSymbol , node , SymbolFlags . TypeLiteral ) ;
323+ typeLiteralSymbol . members = { } ;
324+ typeLiteralSymbol . members [ node . kind === SyntaxKind . FunctionType ? "__call" : "__new" ] = symbol
325+ }
326+
297327 function bindAnonymousDeclaration ( node : Node , symbolKind : SymbolFlags , name : string , isBlockScopeContainer : boolean ) {
298328 var symbol = createSymbol ( symbolKind , name ) ;
299329 addDeclarationToSymbol ( symbol , node , symbolKind ) ;
@@ -359,12 +389,12 @@ module ts {
359389 case SyntaxKind . CallSignature :
360390 bindDeclaration ( < Declaration > node , SymbolFlags . CallSignature , 0 , /*isBlockScopeContainer*/ false ) ;
361391 break ;
362- case SyntaxKind . Method :
363- bindDeclaration ( < Declaration > node , SymbolFlags . Method , SymbolFlags . MethodExcludes , /*isBlockScopeContainer*/ true ) ;
364- break ;
365392 case SyntaxKind . ConstructSignature :
366393 bindDeclaration ( < Declaration > node , SymbolFlags . ConstructSignature , 0 , /*isBlockScopeContainer*/ true ) ;
367394 break ;
395+ case SyntaxKind . Method :
396+ bindDeclaration ( < Declaration > node , SymbolFlags . Method , SymbolFlags . MethodExcludes , /*isBlockScopeContainer*/ true ) ;
397+ break ;
368398 case SyntaxKind . IndexSignature :
369399 bindDeclaration ( < Declaration > node , SymbolFlags . IndexSignature , 0 , /*isBlockScopeContainer*/ false ) ;
370400 break ;
@@ -380,6 +410,12 @@ module ts {
380410 case SyntaxKind . SetAccessor :
381411 bindDeclaration ( < Declaration > node , SymbolFlags . SetAccessor , SymbolFlags . SetAccessorExcludes , /*isBlockScopeContainer*/ true ) ;
382412 break ;
413+
414+ case SyntaxKind . FunctionType :
415+ case SyntaxKind . ConstructorType :
416+ bindFunctionOrConstructorType ( < SignatureDeclaration > node ) ;
417+ break ;
418+
383419 case SyntaxKind . TypeLiteral :
384420 bindAnonymousDeclaration ( node , SymbolFlags . TypeLiteral , "__type" , /*isBlockScopeContainer*/ false ) ;
385421 break ;
0 commit comments