Improving code and addressing code review feedback.

Binder now builds more generally useful linked list of all container declarations.
Emitter uses original spelling when creating unique local container names.
This commit is contained in:
Anders Hejlsberg 2014-07-19 08:53:25 -07:00 коммит произвёл unknown
Родитель 175dba4977
Коммит 24dbe2dd79
3 изменённых файлов: 1 добавлений и 45 удалений

Просмотреть файл

@ -33,7 +33,6 @@ module ts {
var container: Declaration;
var lastContainer: Declaration;
var symbolCount = 0;
var lastLocals: Declaration;
var Symbol = objectAllocator.getSymbolConstructor();
if (!file.locals) {

Просмотреть файл

@ -6049,49 +6049,6 @@ module ts {
Debug.fail("getLocalNameForSymbol failed");
}
function isNodeParentedBy(node: Node, parent: Node): boolean {
while (node) {
if (node === parent) return true;
node = node.parent;
}
return false;
}
function isUniqueLocalName(name: string, container: Node): boolean {
name = escapeIdentifier(name);
if (container.locals) {
for (var node = container; isNodeParentedBy(node, container); node = node.nextLocals) {
if (hasProperty(node.locals, name) && node.locals[name].flags & (SymbolFlags.Value | SymbolFlags.ExportValue)) {
return false;
}
}
}
return true;
}
function getLocalNameOfContainer(container: Declaration): string {
var links = getNodeLinks(container);
if (!links.localModuleName) {
var name = container.name.text ? unescapeIdentifier(container.name.text) : "M";
while (!isUniqueLocalName(name, container)) {
name = "_" + name;
}
links.localModuleName = name;
}
return links.localModuleName;
}
function getLocalNameForSymbol(symbol: Symbol, location: Node): string {
var node = location;
while (node) {
if ((node.kind === SyntaxKind.ModuleDeclaration || node.kind === SyntaxKind.EnumDeclaration) && getSymbolOfNode(node) === symbol) {
return getLocalNameOfContainer(node);
}
node = node.parent;
}
Debug.fail("getLocalNameForSymbol failed");
}
function getExpressionNamePrefix(node: Identifier): string {
var symbol = getNodeLinks(node).resolvedSymbol;
if (symbol) {

Просмотреть файл

@ -691,7 +691,7 @@ module ts {
ExportHasLocal = Function | Class | Enum | ValueModule,
HasLocals = Function | Enum | Module | Method | Constructor | Accessor | Signature,
HasLocals = Function | Module | Method | Constructor | Accessor | Signature,
HasExports = Class | Enum | Module,
HasMembers = Class | Interface | TypeLiteral | ObjectLiteral,