Skip to content

Commit 4bf0bb6

Browse files
committed
added comments
1 parent 904d116 commit 4bf0bb6

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/compiler/checker.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ module ts {
280280
Debug.assert((symbol.flags & SymbolFlags.Instantiated) === 0, "Should never get an instantiated symbol here.");
281281
if (symbol.flags & meaning) {
282282
return symbol;
283-
}
283+
}
284284

285285
if (symbol.flags & SymbolFlags.Import) {
286286
var target = resolveImport(symbol);
@@ -10716,7 +10716,7 @@ module ts {
1071610716
}
1071710717

1071810718
function isUnknownIdentifier(location: Node, name: string): boolean {
10719-
return !resolveName(location, name, SymbolFlags.Value | SymbolFlags.Import, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) &&
10719+
return !resolveName(location, name, SymbolFlags.Value, /*nodeNotFoundMessage*/ undefined, /*nameArg*/ undefined) &&
1072010720
!hasProperty(getGeneratedNamesForSourceFile(getSourceFile(location)), name);
1072110721
}
1072210722

src/compiler/emitter.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,17 @@ module ts {
3333
trailingCommentRanges?: CommentRange[];
3434
}
3535

36+
// represents one LexicalEnvironment frame to store unique generated names
3637
interface ScopeFrame {
3738
names: Map<string>;
3839
previous: ScopeFrame;
3940
}
4041

42+
// isExisingName function has signature string -> boolean, however check if name is unique should be performed
43+
// in the context of some location. Instead of creating function expression and closing over location
44+
// every time isExisingName is called we use one single instance of NameLookup that is effectively a
45+
// handrolled closure where value of location can be swapped. This allows to avoid allocations of closures on
46+
// every call and use one shared instance instead
4147
interface NameLookup {
4248
setLocation(location: Node): void;
4349
isExistingName(name: string): boolean;
@@ -1663,6 +1669,8 @@ module ts {
16631669
writeEmittedFiles(writer.getText(), /*writeByteOrderMark*/ compilerOptions.emitBOM);
16641670
return;
16651671

1672+
// enters the new lexical environment
1673+
// return value should be passed to matching call to exitNameScope.
16661674
function enterNameScope(): boolean {
16671675
var names = currentScopeNames;
16681676
currentScopeNames = undefined;
@@ -1683,6 +1691,8 @@ module ts {
16831691
}
16841692
}
16851693

1694+
// creates instance of NameLookup to be used in 'isExisingName' checks.
1695+
// see comment for NameLookup for more information
16861696
function createNameLookup(): NameLookup {
16871697
var location: Node;
16881698
return {

0 commit comments

Comments
 (0)