Navigation Menu

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

Refactor generated builder names in @babel/types #11582

Merged
merged 4 commits into from Jul 7, 2020

Conversation

zxbodya
Copy link
Contributor

@zxbodya zxbodya commented May 18, 2020

This is related to migration to typescript #11578

The issue is that if exported builder name starts from upper case character - it conflicts with a type name.

This PRs refactors generation of builders, so by default, they are named starting with a lowercase character, and for backward compatibility re-exported starting with upper-case (currently it is opposite). This will make it easier to separate backward compatibility exports from the default, during migration to typescript. And would make it easier to be removed in the major version.

Also, I updated all the places where the builder's name starting with the upper-case was used(this is to be needed after migrating to TypeScript).

Q                       A
Fixed Issues?
Patch: Bug Fix?
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
License MIT

}
});

Object.keys(definitions.DEPRECATED_KEYS).forEach(type => {
const newType = definitions.DEPRECATED_KEYS[type];
output += `export function ${type}(...args: Array<any>): Object {
console.trace("The node type ${type} has been renamed to ${newType}");
return ${type}("${type}", ...args);
return builder("${type}", ...args);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

here was a bug, which would result in code like this:

export function RestProperty(...args: Array<any>): Object {	
  console.trace("The node type RestProperty has been renamed to RestElement");
  return RestProperty("RestProperty", ...args);
}

which will cause infinite recursion when using such deprecated builder…

@babel-bot
Copy link
Collaborator

babel-bot commented May 18, 2020

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/25400/

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 18, 2020

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 7e81925:

Sandbox Source
babel-repl-custom-plugin Configuration
babel-plugin-multi-config Configuration

@zxbodya zxbodya changed the title Refactor to generated builder names in @babel/types Refactor generated builder names in @babel/types May 18, 2020
@JLHwung JLHwung changed the base branch from master to main July 2, 2020 21:28
Copy link
Member

@nicolo-ribaudo nicolo-ribaudo left a comment

Choose a reason for hiding this comment

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

Sorry, I just noticed I had a pending review on this PR and never posted it.

I like this refactoring since it makes lowercase builders the "default" (and those are the builders we internally use). Also, thanks for catching the infinite recursion!

export { Super as super };
export function TaggedTemplateExpression(...args: Array<any>): Object {
export { _super as Super };
export { _super as super };
Copy link
Member

Choose a reason for hiding this comment

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

👍

Comment on lines 23 to 24
// This is needed for backwards compatibility.
// It should be removed in the next major version.
Copy link
Member

Choose a reason for hiding this comment

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

Nit: could you remove this comment for now? We haven't discussed about it as a team yet.

Since uppercase builders have been around for so long, maybe in Babel 8 we will "soft-remove" them (i.e. not document them, and not represent them in .d.ts files) and add a deprecation warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, updated the PR

@nicolo-ribaudo nicolo-ribaudo added pkg: types PR: Bug Fix 🐛 A type of pull request used for our changelog categories PR: Internal 🏠 A type of pull request used for our changelog categories labels Jul 5, 2020
@nicolo-ribaudo nicolo-ribaudo merged commit b1a8e72 into babel:main Jul 7, 2020
@zxbodya zxbodya deleted the lowercase-builder-names branch July 16, 2020 21:13
@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Oct 16, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: types PR: Bug Fix 🐛 A type of pull request used for our changelog categories PR: Internal 🏠 A type of pull request used for our changelog categories
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants