mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-11 10:46:28 -05:00
drop locals in block-scope container nodes during binding
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user