Skip to content

Make most current Node factory functions public #13825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 6, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2565,7 +2565,7 @@ namespace ts {
// Node names generate unique names based on their original node
// and are cached based on that node's id.
const node = getNodeForGeneratedName(name);
return generateNameCached(node, getTextOfNode);
return generateNameCached(node);
}
else {
// Auto, Loop, and Unique names are cached based on their unique
Expand All @@ -2575,9 +2575,9 @@ namespace ts {
}
}

function generateNameCached(node: Node, getTextOfNode: (node: Node, includeTrivia?: boolean) => string) {
function generateNameCached(node: Node) {
const nodeId = getNodeId(node);
return nodeIdToGeneratedName[nodeId] || (nodeIdToGeneratedName[nodeId] = unescapeIdentifier(generateNameForNode(node, getTextOfNode)));
return nodeIdToGeneratedName[nodeId] || (nodeIdToGeneratedName[nodeId] = unescapeIdentifier(generateNameForNode(node)));
}

/**
Expand Down Expand Up @@ -2659,7 +2659,7 @@ namespace ts {
/**
* Generates a unique name for a ModuleDeclaration or EnumDeclaration.
*/
function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration, getTextOfNode: (node: Node, includeTrivia?: boolean) => string) {
function generateNameForModuleOrEnum(node: ModuleDeclaration | EnumDeclaration) {
const name = getTextOfNode(node.name);
// Use module/enum name itself if it is unique, otherwise make a unique variation
return isUniqueLocalName(name, node) ? name : makeUniqueName(name);
Expand Down Expand Up @@ -2689,23 +2689,23 @@ namespace ts {
return makeUniqueName("class");
}

function generateNameForMethodOrAccessor(node: MethodDeclaration | AccessorDeclaration, getTextOfNode: (node: Node, includeTrivia?: boolean) => string) {
function generateNameForMethodOrAccessor(node: MethodDeclaration | AccessorDeclaration) {
if (isIdentifier(node.name)) {
return generateNameCached(node.name, getTextOfNode);
return generateNameCached(node.name);
}
return makeTempVariableName(TempFlags.Auto);
}

/**
* Generates a unique name from a node.
*/
function generateNameForNode(node: Node, getTextOfNode: (node: Node, includeTrivia?: boolean) => string): string {
function generateNameForNode(node: Node): string {
switch (node.kind) {
case SyntaxKind.Identifier:
return makeUniqueName(getTextOfNode(node));
case SyntaxKind.ModuleDeclaration:
case SyntaxKind.EnumDeclaration:
return generateNameForModuleOrEnum(<ModuleDeclaration | EnumDeclaration>node, getTextOfNode);
return generateNameForModuleOrEnum(<ModuleDeclaration | EnumDeclaration>node);
case SyntaxKind.ImportDeclaration:
case SyntaxKind.ExportDeclaration:
return generateNameForImportOrExportDeclaration(<ImportDeclaration | ExportDeclaration>node);
Expand All @@ -2718,7 +2718,7 @@ namespace ts {
case SyntaxKind.MethodDeclaration:
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
return generateNameForMethodOrAccessor(<MethodDeclaration | AccessorDeclaration>node, getTextOfNode);
return generateNameForMethodOrAccessor(<MethodDeclaration | AccessorDeclaration>node);
default:
return makeTempVariableName(TempFlags.Auto);
}
Expand All @@ -2734,7 +2734,7 @@ namespace ts {
case GeneratedIdentifierKind.Loop:
return makeTempVariableName(TempFlags._i);
case GeneratedIdentifierKind.Unique:
return makeUniqueName(name.text);
return makeUniqueName(unescapeIdentifier(name.text));
}

Debug.fail("Unsupported GeneratedIdentifierKind.");
Expand Down
Loading