@@ -415,8 +415,13 @@ module ts {
415
415
}
416
416
417
417
function getExportAssignmentSymbol ( symbol : Symbol ) : Symbol {
418
- if ( ! symbol . exportAssignSymbol ) {
419
- var exportInformation = collectExportInformationForSourceFileOrModule ( symbol ) ;
418
+ checkAndStoreTypeOfExportAssignmentSymbol ( symbol ) ;
419
+ return symbol . exportAssignSymbol === unknownSymbol ? undefined : symbol . exportAssignSymbol ;
420
+ }
421
+
422
+ function checkAndStoreTypeOfExportAssignmentSymbol ( containerSymbol : Symbol ) : void {
423
+ if ( ! containerSymbol . exportAssignSymbol ) {
424
+ var exportInformation = collectExportInformationForSourceFileOrModule ( containerSymbol ) ;
420
425
if ( exportInformation . exportAssignments . length ) {
421
426
if ( exportInformation . exportAssignments . length > 1 ) {
422
427
// TypeScript 1.0 spec (April 2014): 11.2.4
@@ -436,9 +441,8 @@ module ts {
436
441
var exportSymbol = resolveName ( node , node . exportName . text , meaning , Diagnostics . Cannot_find_name_0 , identifierToString ( node . exportName ) ) ;
437
442
}
438
443
}
439
- symbol . exportAssignSymbol = exportSymbol || unknownSymbol ;
444
+ containerSymbol . exportAssignSymbol = exportSymbol || unknownSymbol ;
440
445
}
441
- return symbol . exportAssignSymbol === unknownSymbol ? undefined : symbol . exportAssignSymbol ;
442
446
}
443
447
444
448
function collectExportInformationForSourceFileOrModule ( symbol : Symbol ) {
@@ -504,8 +508,12 @@ module ts {
504
508
var declarations = symbol . declarations ;
505
509
for ( var i = 0 ; i < declarations . length ; i ++ ) {
506
510
var declaration = declarations [ i ] ;
507
- if ( declaration . kind === kind ) return declaration ;
511
+ if ( declaration . kind === kind ) {
512
+ return declaration ;
513
+ }
508
514
}
515
+
516
+ return undefined ;
509
517
}
510
518
511
519
function findConstructorDeclaration ( node : ClassDeclaration ) : ConstructorDeclaration {
@@ -922,6 +930,12 @@ module ts {
922
930
923
931
function getTypeOfAccessors ( symbol : Symbol ) : Type {
924
932
var links = getSymbolLinks ( symbol ) ;
933
+ checkAndStoreTypeOfAccessors ( symbol , links ) ;
934
+ return links . type ;
935
+ }
936
+
937
+ function checkAndStoreTypeOfAccessors ( symbol : Symbol , links ?: SymbolLinks ) {
938
+ links = links || getSymbolLinks ( symbol ) ;
925
939
if ( ! links . type ) {
926
940
links . type = resolvingType ;
927
941
var getter = < AccessorDeclaration > getDeclarationOfKind ( symbol , SyntaxKind . GetAccessor ) ;
@@ -955,7 +969,6 @@ module ts {
955
969
}
956
970
}
957
971
}
958
-
959
972
960
973
if ( links . type === resolvingType ) {
961
974
links . type = type ;
@@ -964,7 +977,6 @@ module ts {
964
977
else if ( links . type === resolvingType ) {
965
978
links . type = anyType ;
966
979
}
967
- return links . type ;
968
980
}
969
981
970
982
function getTypeOfFuncClassEnumModule ( symbol : Symbol ) : Type {
@@ -4212,11 +4224,10 @@ module ts {
4212
4224
checkSourceElement ( node . body ) ;
4213
4225
4214
4226
var symbol = getSymbolOfNode ( node ) ;
4215
- var symbolLinks = getSymbolLinks ( symbol ) ;
4216
- var type = getTypeOfSymbol ( symbol . parent ) ;
4217
- if ( ! ( symbolLinks . typeChecked ) ) {
4227
+ var firstDeclaration = getDeclarationOfKind ( symbol , node . kind ) ;
4228
+ // Only type check the symbol once
4229
+ if ( node === firstDeclaration ) {
4218
4230
checkFunctionOrConstructorSymbol ( symbol ) ;
4219
- symbolLinks . typeChecked = true ;
4220
4231
}
4221
4232
4222
4233
// exit early in the case of signature - super checks are not relevant to them
@@ -4335,6 +4346,7 @@ module ts {
4335
4346
}
4336
4347
4337
4348
checkFunctionDeclaration ( node ) ;
4349
+ checkAndStoreTypeOfAccessors ( getSymbolOfNode ( node ) ) ;
4338
4350
}
4339
4351
4340
4352
function checkTypeReference ( node : TypeReferenceNode ) {
@@ -4550,12 +4562,12 @@ module ts {
4550
4562
function checkFunctionDeclaration ( node : FunctionDeclaration ) {
4551
4563
checkDeclarationModifiers ( node ) ;
4552
4564
checkSignatureDeclaration ( node ) ;
4565
+
4553
4566
var symbol = getSymbolOfNode ( node ) ;
4554
- var symbolLinks = getSymbolLinks ( symbol ) ;
4555
- var type = getTypeOfSymbol ( symbol ) ;
4556
- if ( ! ( symbolLinks . typeChecked ) ) {
4567
+ var firstDeclaration = getDeclarationOfKind ( symbol , node . kind ) ;
4568
+ // Only type check the symbol once
4569
+ if ( node === firstDeclaration ) {
4557
4570
checkFunctionOrConstructorSymbol ( symbol ) ;
4558
- symbolLinks . typeChecked = true ;
4559
4571
}
4560
4572
checkSourceElement ( node . body ) ;
4561
4573
@@ -5156,15 +5168,15 @@ module ts {
5156
5168
checkNameIsReserved ( node . name , Diagnostics . Interface_name_cannot_be_0 ) ;
5157
5169
checkTypeParameters ( node . typeParameters ) ;
5158
5170
var symbol = getSymbolOfNode ( node ) ;
5171
+ var firstInterfaceDecl = < InterfaceDeclaration > getDeclarationOfKind ( symbol , SyntaxKind . InterfaceDeclaration ) ;
5159
5172
if ( symbol . declarations . length > 1 ) {
5160
- var firstInterfaceDecl = < InterfaceDeclaration > getDeclarationOfKind ( symbol , SyntaxKind . InterfaceDeclaration ) ;
5161
5173
if ( node !== firstInterfaceDecl && ! areTypeParametersIdentical ( firstInterfaceDecl . typeParameters , node . typeParameters ) ) {
5162
5174
error ( node . name , Diagnostics . All_declarations_of_an_interface_must_have_identical_type_parameters ) ;
5163
5175
}
5164
5176
}
5165
5177
5166
- var links = getSymbolLinks ( symbol ) ;
5167
- if ( ! links . typeChecked ) {
5178
+ // Only check this symbol once
5179
+ if ( node === firstInterfaceDecl ) {
5168
5180
var type = < InterfaceType > getDeclaredTypeOfSymbol ( symbol ) ;
5169
5181
// run subsequent checks only if first set succeeded
5170
5182
if ( checkInheritedPropertiesAreIdentical ( type , node . name ) ) {
@@ -5173,7 +5185,6 @@ module ts {
5173
5185
} ) ;
5174
5186
checkIndexConstraints ( type ) ;
5175
5187
}
5176
- links . typeChecked = true ;
5177
5188
}
5178
5189
forEach ( node . baseTypes , checkTypeReference ) ;
5179
5190
forEach ( node . members , checkSourceElement ) ;
@@ -5237,11 +5248,6 @@ module ts {
5237
5248
error ( node , Diagnostics . Ambient_external_module_declaration_cannot_specify_relative_module_name ) ;
5238
5249
}
5239
5250
var symbol = getSymbolOfNode ( node ) ;
5240
- var links = getSymbolLinks ( symbol ) ;
5241
- if ( ! links . typeChecked ) {
5242
- getExportAssignmentSymbol ( symbol ) ;
5243
- links . typeChecked = true ;
5244
- }
5245
5251
}
5246
5252
checkSourceElement ( node . body ) ;
5247
5253
}
@@ -5310,6 +5316,11 @@ module ts {
5310
5316
if ( container . kind === SyntaxKind . SourceFile ) {
5311
5317
checkModulesEnabled ( node ) ;
5312
5318
}
5319
+ else {
5320
+ // In a module, the immediate parent will be a block, so climb up one more parent
5321
+ container = container . parent ;
5322
+ }
5323
+ checkAndStoreTypeOfExportAssignmentSymbol ( getSymbolOfNode ( container ) ) ;
5313
5324
}
5314
5325
5315
5326
function checkSourceElement ( node : Node ) : void {
0 commit comments