-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
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
Conversation
} | ||
}); | ||
|
||
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); |
There was a problem hiding this comment.
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…
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/25400/ |
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:
|
37251aa
to
2f1cefc
Compare
2f1cefc
to
72c9d17
Compare
There was a problem hiding this 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 }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
// This is needed for backwards compatibility. | ||
// It should be removed in the next major version. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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).