From 7f5fb8bc19005a0082fd627f82c8606799709178 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Sat, 14 Feb 2015 16:11:58 -0800 Subject: [PATCH] drop locals in block-scope container nodes during binding --- src/compiler/binder.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index be9e9a525c0..5657ce4e8e0 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -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;