diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index e325b2033e7..d0d6005d979 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -1,7 +1,7 @@ /// module ts { - /* @internal */ export var bindTime = 0; + /* @internal */ export let bindTime = 0; export const enum ModuleInstanceState { NonInstantiated = 0, @@ -25,7 +25,7 @@ module ts { } // 4. other uninstantiated module declarations. else if (node.kind === SyntaxKind.ModuleBlock) { - var state = ModuleInstanceState.NonInstantiated; + let state = ModuleInstanceState.NonInstantiated; forEachChild(node, n => { switch (getModuleInstanceState(n)) { case ModuleInstanceState.NonInstantiated: @@ -52,18 +52,18 @@ module ts { } export function bindSourceFile(file: SourceFile): void { - var start = new Date().getTime(); + let start = new Date().getTime(); bindSourceFileWorker(file); bindTime += new Date().getTime() - start; } function bindSourceFileWorker(file: SourceFile): void { var parent: Node; - var container: Node; - var blockScopeContainer: Node; - var lastContainer: Node; - var symbolCount = 0; - var Symbol = objectAllocator.getSymbolConstructor(); + let container: Node; + let blockScopeContainer: Node; + let lastContainer: Node; + let symbolCount = 0; + let Symbol = objectAllocator.getSymbolConstructor(); if (!file.locals) { file.locals = {}; @@ -103,7 +103,7 @@ module ts { return '"' + (node.name).text + '"'; } if (node.name.kind === SyntaxKind.ComputedPropertyName) { - var nameExpression = (node.name).expression; + let nameExpression = (node.name).expression; Debug.assert(isWellKnownSymbolSyntactically(nameExpression)); return getPropertyNameForKnownSymbolName((nameExpression).name.text); } @@ -138,10 +138,11 @@ module ts { Debug.assert(!hasDynamicName(node)); // The exported symbol for an export default function/class node is always named "default" - var name = node.flags & NodeFlags.Default && parent ? "default" : getDeclarationName(node); + let name = node.flags & NodeFlags.Default && parent ? "default" : getDeclarationName(node); + let symbol: Symbol; if (name !== undefined) { - var symbol = hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); + symbol = hasProperty(symbols, name) ? symbols[name] : (symbols[name] = createSymbol(0, name)); if (symbol.flags & excludes) { if (node.name) { node.name.parent = node; @@ -149,7 +150,7 @@ module ts { // Report errors every position with duplicate declaration // Report errors on previous encountered declarations - var message = symbol.flags & SymbolFlags.BlockScopedVariable + let message = symbol.flags & SymbolFlags.BlockScopedVariable ? Diagnostics.Cannot_redeclare_block_scoped_variable_0 : Diagnostics.Duplicate_identifier_0; @@ -172,7 +173,7 @@ module ts { // Every class automatically contains a static property member named 'prototype', // the type of which is an instantiation of the class type with type Any supplied as a type argument for each type parameter. // It is an error to explicitly declare a static property member with the name 'prototype'. - var prototypeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Prototype, "prototype"); + let prototypeSymbol = createSymbol(SymbolFlags.Property | SymbolFlags.Prototype, "prototype"); if (hasProperty(symbol.exports, prototypeSymbol.name)) { if (node.name) { node.name.parent = node; @@ -196,7 +197,7 @@ module ts { } function declareModuleMember(node: Declaration, symbolKind: SymbolFlags, symbolExcludes: SymbolFlags) { - var hasExportModifier = getCombinedNodeFlags(node) & NodeFlags.Export; + let hasExportModifier = getCombinedNodeFlags(node) & NodeFlags.Export; if (symbolKind & SymbolFlags.Alias) { if (node.kind === SyntaxKind.ExportSpecifier || (node.kind === SyntaxKind.ImportEqualsDeclaration && hasExportModifier)) { declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); @@ -218,10 +219,10 @@ module ts { // but return the export symbol (by calling getExportSymbolOfValueSymbolIfExported). That way // when the emitter comes back to it, it knows not to qualify the name if it was found in a containing scope. if (hasExportModifier || isAmbientContext(container)) { - var exportKind = (symbolKind & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) | + let exportKind = (symbolKind & SymbolFlags.Value ? SymbolFlags.ExportValue : 0) | (symbolKind & SymbolFlags.Type ? SymbolFlags.ExportType : 0) | (symbolKind & SymbolFlags.Namespace ? SymbolFlags.ExportNamespace : 0); - var local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); + let local = declareSymbol(container.locals, undefined, node, exportKind, symbolExcludes); local.exportSymbol = declareSymbol(container.symbol.exports, container.symbol, node, symbolKind, symbolExcludes); node.localSymbol = local; } @@ -238,9 +239,9 @@ module ts { node.locals = {}; } - var saveParent = parent; - var saveContainer = container; - var savedBlockScopeContainer = blockScopeContainer; + let saveParent = parent; + let saveContainer = container; + let savedBlockScopeContainer = blockScopeContainer; parent = node; if (symbolKind & SymbolFlags.IsContainer) { container = node; @@ -315,7 +316,7 @@ module ts { bindDeclaration(node, SymbolFlags.ValueModule, SymbolFlags.ValueModuleExcludes, /*isBlockScopeContainer*/ true); } else { - var state = getModuleInstanceState(node); + let state = getModuleInstanceState(node); if (state === ModuleInstanceState.NonInstantiated) { bindDeclaration(node, SymbolFlags.NamespaceModule, SymbolFlags.NamespaceModuleExcludes, /*isBlockScopeContainer*/ true); } @@ -341,18 +342,18 @@ module ts { // symbol as its sole member. To the rest of the system, this symbol will be indistinguishable // from an actual type literal symbol you would have gotten had you used the long form. - var symbol = createSymbol(SymbolFlags.Signature, getDeclarationName(node)); + let symbol = createSymbol(SymbolFlags.Signature, getDeclarationName(node)); addDeclarationToSymbol(symbol, node, SymbolFlags.Signature); bindChildren(node, SymbolFlags.Signature, /*isBlockScopeContainer:*/ false); - var typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type"); + let typeLiteralSymbol = createSymbol(SymbolFlags.TypeLiteral, "__type"); addDeclarationToSymbol(typeLiteralSymbol, node, SymbolFlags.TypeLiteral); typeLiteralSymbol.members = {}; typeLiteralSymbol.members[node.kind === SyntaxKind.FunctionType ? "__call" : "__new"] = symbol } function bindAnonymousDeclaration(node: Declaration, symbolKind: SymbolFlags, name: string, isBlockScopeContainer: boolean) { - var symbol = createSymbol(symbolKind, name); + let symbol = createSymbol(symbolKind, name); addDeclarationToSymbol(symbol, node, symbolKind); bindChildren(node, symbolKind, isBlockScopeContainer); } @@ -525,9 +526,9 @@ module ts { // Otherwise this won't be considered as redeclaration of a block scoped local: // function foo() { // let x; - // var x; + // let x; // } - // 'var x' will be placed into the function locals and 'let x' - into the locals of the block + // 'let x' will be placed into the function locals and 'let x' - into the locals of the block bindChildren(node, 0, /*isBlockScopeContainer*/ !isFunctionLike(node.parent)); break; case SyntaxKind.CatchClause: @@ -538,7 +539,7 @@ module ts { bindChildren(node, 0, /*isBlockScopeContainer*/ true); break; default: - var saveParent = parent; + let saveParent = parent; parent = node; forEachChild(node, bind); parent = saveParent; @@ -559,7 +560,7 @@ module ts { node.parent.kind === SyntaxKind.Constructor && node.parent.parent.kind === SyntaxKind.ClassDeclaration) { - var classDeclaration = node.parent.parent; + let classDeclaration = node.parent.parent; declareSymbol(classDeclaration.symbol.members, classDeclaration.symbol, node, SymbolFlags.Property, SymbolFlags.PropertyExcludes); } }