@@ -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,11 +120,14 @@ 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 ) => {
119
- file . semanticErrors . push ( createDiagnosticForNode ( declaration . name , message , getDisplayName ( 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 => {
128
+ file . semanticDiagnostics . push ( createDiagnosticForNode ( declaration . name , message , getDisplayName ( declaration ) ) ) ;
120
129
} ) ;
121
- file . semanticErrors . push ( createDiagnosticForNode ( node . name , message , getDisplayName ( node ) ) ) ;
130
+ file . semanticDiagnostics . push ( createDiagnosticForNode ( node . name , message , getDisplayName ( node ) ) ) ;
122
131
123
132
symbol = createSymbol ( 0 , name ) ;
124
133
}
@@ -139,7 +148,7 @@ module ts {
139
148
if ( node . name ) {
140
149
node . name . parent = node ;
141
150
}
142
- file . semanticErrors . push ( createDiagnosticForNode ( symbol . exports [ prototypeSymbol . name ] . declarations [ 0 ] ,
151
+ file . semanticDiagnostics . push ( createDiagnosticForNode ( symbol . exports [ prototypeSymbol . name ] . declarations [ 0 ] ,
143
152
Diagnostics . Duplicate_identifier_0 , prototypeSymbol . name ) ) ;
144
153
}
145
154
symbol . exports [ prototypeSymbol . name ] = prototypeSymbol ;
@@ -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 ) ;
@@ -350,6 +380,7 @@ module ts {
350
380
break ;
351
381
case SyntaxKind . Property :
352
382
case SyntaxKind . PropertyAssignment :
383
+ case SyntaxKind . ShorthandPropertyAssignment :
353
384
bindDeclaration ( < Declaration > node , SymbolFlags . Property , SymbolFlags . PropertyExcludes , /*isBlockScopeContainer*/ false ) ;
354
385
break ;
355
386
case SyntaxKind . EnumMember :
@@ -358,12 +389,12 @@ module ts {
358
389
case SyntaxKind . CallSignature :
359
390
bindDeclaration ( < Declaration > node , SymbolFlags . CallSignature , 0 , /*isBlockScopeContainer*/ false ) ;
360
391
break ;
361
- case SyntaxKind . Method :
362
- bindDeclaration ( < Declaration > node , SymbolFlags . Method , SymbolFlags . MethodExcludes , /*isBlockScopeContainer*/ true ) ;
363
- break ;
364
392
case SyntaxKind . ConstructSignature :
365
393
bindDeclaration ( < Declaration > node , SymbolFlags . ConstructSignature , 0 , /*isBlockScopeContainer*/ true ) ;
366
394
break ;
395
+ case SyntaxKind . Method :
396
+ bindDeclaration ( < Declaration > node , SymbolFlags . Method , SymbolFlags . MethodExcludes , /*isBlockScopeContainer*/ true ) ;
397
+ break ;
367
398
case SyntaxKind . IndexSignature :
368
399
bindDeclaration ( < Declaration > node , SymbolFlags . IndexSignature , 0 , /*isBlockScopeContainer*/ false ) ;
369
400
break ;
@@ -379,6 +410,12 @@ module ts {
379
410
case SyntaxKind . SetAccessor :
380
411
bindDeclaration ( < Declaration > node , SymbolFlags . SetAccessor , SymbolFlags . SetAccessorExcludes , /*isBlockScopeContainer*/ true ) ;
381
412
break ;
413
+
414
+ case SyntaxKind . FunctionType :
415
+ case SyntaxKind . ConstructorType :
416
+ bindFunctionOrConstructorType ( < SignatureDeclaration > node ) ;
417
+ break ;
418
+
382
419
case SyntaxKind . TypeLiteral :
383
420
bindAnonymousDeclaration ( node , SymbolFlags . TypeLiteral , "__type" , /*isBlockScopeContainer*/ false ) ;
384
421
break ;
0 commit comments