Skip to content
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

Make most current Node factory functions public #13825

Merged
merged 6 commits into from
Feb 6, 2017
Merged

Conversation

rbuckton
Copy link
Member

@rbuckton rbuckton commented Feb 2, 2017

This change makes a majority of our current Node factory functions a part of our public API. In addition, I have made a few API changes to make the API more consistent and ensure the public API is resilient to future changes.

The major change here involves the removal of the optional location parameter from most factory functions. This is due to the fact that any Node is a TextRange, and it would be very difficult to add overloads for if/when new members are added and still be able to distinguish between a valid Node for a new overload vs. an optional location. To continue to support the update pattern when visiting nodes, I have moved the operation that copies the original node's location to the updateNode function in factory.ts.

Fixes #13765

const name = <Identifier>createNode(SyntaxKind.Identifier, location);
/** Create a unique name based on the supplied text. */
export function createUniqueName(text: string): Identifier {
const name = createIdentifier("");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

createIdentifier(text) ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to call escapeIdentifier on text, which is the default behavior of createIdentifier.

@zpdDG4gta8XKpMCd
Copy link

👍

Copy link
Member

@sandersn sandersn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couple of cosmetic comments.

// Utilities

function asName(name: string): Identifier;
function asName(name: Identifier): Identifier;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think string | Identifier covers both the string and Identifier overloads. Are they just there because they are easier to understand for people who don't know about union types?

* Associates a node with the current transformation, initializing
* various transient transformation properties.
*
* @param node The node.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These @param node The nodes are low value (as are a lot of the others), so I'd delete them.

@rbuckton rbuckton merged commit 955b10e into master Feb 6, 2017
@rbuckton rbuckton deleted the publicNodeFactories branch February 6, 2017 23:43
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants