drop locals in block-scope container nodes during binding

This commit is contained in:
Vladimir Matveev
2015-02-14 16:11:58 -08:00
parent ba52d60c7a
commit 7f5fb8bc19

View File

@@ -78,7 +78,8 @@ module ts {
if (!file.locals) {
file.locals = {};
container = blockScopeContainer = file;
container = file;
setBlockScopeContainer(file, /*cleanLocals*/ false);
bind(file);
file.symbolCount = symbolCount;
}
@@ -88,6 +89,13 @@ module ts {
return new Symbol(flags, name);
}
function setBlockScopeContainer(node: Node, cleanLocals: boolean) {
blockScopeContainer = node;
if (cleanLocals) {
blockScopeContainer.locals = undefined;
}
}
function addDeclarationToSymbol(symbol: Symbol, node: Declaration, symbolKind: SymbolFlags) {
symbol.flags |= symbolKind;
if (!symbol.declarations) symbol.declarations = [];
@@ -244,7 +252,10 @@ module ts {
}
if (isBlockScopeContainer) {
blockScopeContainer = node;
// clean locals in block scope container if
// - current node does not have local variables
// - current node is not source file (source file always have locals)
setBlockScopeContainer(node, /*cleanLocals*/ (symbolKind & SymbolFlags.HasLocals) == 0 && node.kind !== SyntaxKind.SourceFile);
}
forEachChild(node, bind);
@@ -347,7 +358,8 @@ module ts {
addDeclarationToSymbol(symbol, node, SymbolFlags.FunctionScopedVariable);
var saveParent = parent;
var savedBlockScopeContainer = blockScopeContainer;
parent = blockScopeContainer = node;
parent = node;
setBlockScopeContainer(node, /*cleanLocals*/ true);
forEachChild(node, bind);
parent = saveParent;
blockScopeContainer = savedBlockScopeContainer;