@@ -93,10 +93,16 @@ module ts {
93
93
return ( < Identifier > node . name ) . text ;
94
94
}
95
95
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" ;
100
106
}
101
107
}
102
108
@@ -114,8 +120,11 @@ module ts {
114
120
}
115
121
// Report errors every position with duplicate declaration
116
122
// 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 => {
119
128
file . semanticErrors . push ( createDiagnosticForNode ( declaration . name , message , getDisplayName ( declaration ) ) ) ;
120
129
} ) ;
121
130
file . semanticErrors . push ( createDiagnosticForNode ( node . name , message , getDisplayName ( node ) ) ) ;
@@ -233,6 +242,8 @@ module ts {
233
242
declareModuleMember ( node , symbolKind , symbolExcludes ) ;
234
243
break ;
235
244
}
245
+ case SyntaxKind . FunctionType :
246
+ case SyntaxKind . ConstructorType :
236
247
case SyntaxKind . CallSignature :
237
248
case SyntaxKind . ConstructSignature :
238
249
case SyntaxKind . IndexSignature :
@@ -294,6 +305,25 @@ module ts {
294
305
}
295
306
}
296
307
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
+
297
327
function bindAnonymousDeclaration ( node : Node , symbolKind : SymbolFlags , name : string , isBlockScopeContainer : boolean ) {
298
328
var symbol = createSymbol ( symbolKind , name ) ;
299
329
addDeclarationToSymbol ( symbol , node , symbolKind ) ;
@@ -359,12 +389,12 @@ module ts {
359
389
case SyntaxKind . CallSignature :
360
390
bindDeclaration ( < Declaration > node , SymbolFlags . CallSignature , 0 , /*isBlockScopeContainer*/ false ) ;
361
391
break ;
362
- case SyntaxKind . Method :
363
- bindDeclaration ( < Declaration > node , SymbolFlags . Method , SymbolFlags . MethodExcludes , /*isBlockScopeContainer*/ true ) ;
364
- break ;
365
392
case SyntaxKind . ConstructSignature :
366
393
bindDeclaration ( < Declaration > node , SymbolFlags . ConstructSignature , 0 , /*isBlockScopeContainer*/ true ) ;
367
394
break ;
395
+ case SyntaxKind . Method :
396
+ bindDeclaration ( < Declaration > node , SymbolFlags . Method , SymbolFlags . MethodExcludes , /*isBlockScopeContainer*/ true ) ;
397
+ break ;
368
398
case SyntaxKind . IndexSignature :
369
399
bindDeclaration ( < Declaration > node , SymbolFlags . IndexSignature , 0 , /*isBlockScopeContainer*/ false ) ;
370
400
break ;
@@ -380,6 +410,12 @@ module ts {
380
410
case SyntaxKind . SetAccessor :
381
411
bindDeclaration ( < Declaration > node , SymbolFlags . SetAccessor , SymbolFlags . SetAccessorExcludes , /*isBlockScopeContainer*/ true ) ;
382
412
break ;
413
+
414
+ case SyntaxKind . FunctionType :
415
+ case SyntaxKind . ConstructorType :
416
+ bindFunctionOrConstructorType ( < SignatureDeclaration > node ) ;
417
+ break ;
418
+
383
419
case SyntaxKind . TypeLiteral :
384
420
bindAnonymousDeclaration ( node , SymbolFlags . TypeLiteral , "__type" , /*isBlockScopeContainer*/ false ) ;
385
421
break ;
0 commit comments