From 4bf0bb640579000bcb5c4a531c5654ee1774bb59 Mon Sep 17 00:00:00 2001 From: Vladimir Matveev Date: Thu, 26 Feb 2015 17:19:47 -0800 Subject: [PATCH] added comments --- src/compiler/checker.ts | 4 ++-- src/compiler/emitter.ts | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index fd3d2141dc0..46d7dc5d382 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -280,7 +280,7 @@ module ts { Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0, "Should never get an instantiated symbol here."); if (symbol.flags & meaning) { return symbol; - } + } if (symbol.flags & SymbolFlags.Import) { var target = resolveImport(symbol); @@ -10716,7 +10716,7 @@ module ts { } function isUnknownIdentifier(location: Node, name: string): boolean { - return !resolveName(location, name, SymbolFlags.Value | SymbolFlags.Import, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) && + return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) && !hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name); } diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 1cfbbd20096..a887df0dcc5 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -33,11 +33,17 @@ module ts { trailingCommentRanges?: CommentRange[]; } + // represents one LexicalEnvironment frame to store unique generated names interface ScopeFrame { names: Map; previous: ScopeFrame; } + // isExisingName function has signature string -> boolean, however check if name is unique should be performed + // in the context of some location. Instead of creating function expression and closing over location + // every time isExisingName is called we use one single instance of NameLookup that is effectively a + // handrolled closure where value of location can be swapped. This allows to avoid allocations of closures on + // every call and use one shared instance instead interface NameLookup { setLocation(location: Node): void; isExistingName(name: string): boolean; @@ -1663,6 +1669,8 @@ module ts { writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM); return; + // enters the new lexical environment + // return value should be passed to matching call to exitNameScope. function enterNameScope(): boolean { var names = currentScopeNames; currentScopeNames = undefined; @@ -1683,6 +1691,8 @@ module ts { } } + // creates instance of NameLookup to be used in 'isExisingName' checks. + // see comment for NameLookup for more information function createNameLookup(): NameLookup { var location: Node; return {