@@ -78,7 +78,8 @@ module ts {
78
78
79
79
if ( ! file . locals ) {
80
80
file . locals = { } ;
81
- container = blockScopeContainer = file ;
81
+ container = file ;
82
+ setBlockScopeContainer ( file , /*cleanLocals*/ false ) ;
82
83
bind ( file ) ;
83
84
file . symbolCount = symbolCount ;
84
85
}
@@ -88,6 +89,13 @@ module ts {
88
89
return new Symbol ( flags , name ) ;
89
90
}
90
91
92
+ function setBlockScopeContainer ( node : Node , cleanLocals : boolean ) {
93
+ blockScopeContainer = node ;
94
+ if ( cleanLocals ) {
95
+ blockScopeContainer . locals = undefined ;
96
+ }
97
+ }
98
+
91
99
function addDeclarationToSymbol ( symbol : Symbol , node : Declaration , symbolKind : SymbolFlags ) {
92
100
symbol . flags |= symbolKind ;
93
101
if ( ! symbol . declarations ) symbol . declarations = [ ] ;
@@ -244,7 +252,10 @@ module ts {
244
252
}
245
253
246
254
if ( isBlockScopeContainer ) {
247
- blockScopeContainer = node ;
255
+ // clean locals in block scope container if
256
+ // - current node does not have local variables
257
+ // - current node is not source file (source file always have locals)
258
+ setBlockScopeContainer ( node , /*cleanLocals*/ ( symbolKind & SymbolFlags . HasLocals ) == 0 && node . kind !== SyntaxKind . SourceFile ) ;
248
259
}
249
260
250
261
forEachChild ( node , bind ) ;
@@ -347,7 +358,8 @@ module ts {
347
358
addDeclarationToSymbol ( symbol , node , SymbolFlags . FunctionScopedVariable ) ;
348
359
var saveParent = parent ;
349
360
var savedBlockScopeContainer = blockScopeContainer ;
350
- parent = blockScopeContainer = node ;
361
+ parent = node ;
362
+ setBlockScopeContainer ( node , /*cleanLocals*/ true ) ;
351
363
forEachChild ( node , bind ) ;
352
364
parent = saveParent ;
353
365
blockScopeContainer = savedBlockScopeContainer ;
0 commit comments