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

[babel 8] ObjectTypeAnnotation fields must always be arrays #14465

Merged
merged 1 commit into from Apr 24, 2022

Conversation

danez
Copy link
Member

@danez danez commented Apr 14, 2022

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

The fields indexers, callProperties, and internalSlots in the node ObjectTypeAnnotation are currently marked as optional. This is correct for the builder, they should be optional there.
For the TS types, this is not quite correct, because the babel parser always initializes these fields with empty arrays (https://github.com/babel/babel/blob/main/packages/babel-parser/src/plugins/flow/index.js#L1085-L1088).
The only way to set these fields to null is with the builder currently.

The change here is to not mark these fields as optional but instead provide an empty array as a default value. This way the builder still has these params as optional, but cannot be set to null anymore.
The Typescript types on the other hand now do not mark these fields as optional which is correct, as they are always an array, even if it might be empty.

Do you think this is a reasonable change?

Now, is this breaking? Only the builder might be considered as a breaking change, as it does not allow null anymore for these fields (see change generator tests). If you think this is breaking enough I could move that behind the BABEL8 flag. Please let me know.
After thinking about this a little more I now think this should be considered breaking. Which Flag should I use? BABEL_TYPES_8_BREAKING or BABEL_8_BREAKING

Copy link
Contributor

@JLHwung JLHwung left a comment

Choose a reason for hiding this comment

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

The changes look good to me. BABEL_TYPES_8_BREAKING is superseded by BABEL_8_BREAKING, so the latter should be good to go.

@danez danez force-pushed the danez-objecttypeannotation-fields branch from 82ad2f2 to 5d5202f Compare April 21, 2022 21:48
@danez
Copy link
Member Author

danez commented Apr 21, 2022

Ok, I put all the changes behind the flag.

Is there a document where all breaking changes/migrations steps are recorded?

…are always present

BREAKING CHANGE: The 2., 3., and 4. parameter to the builder for `ObjectTypeAnnotation` do not accept null anymore. Use undefined.
@danez danez force-pushed the danez-objecttypeannotation-fields branch from 5d5202f to 4882ccc Compare April 21, 2022 21:52
@danez danez added this to the Babel 8.0 milestone Apr 21, 2022
@JLHwung
Copy link
Contributor

JLHwung commented Apr 21, 2022

Is there a document where all breaking changes/migrations steps are recorded?

Yes, see #10746.

@nicolo-ribaudo nicolo-ribaudo changed the title fix(babel-types): Fix ts types because array fields in ObjectTypeAnnotation are always present [babel 8] ObjectTypeAnnotation fields must always be arrays Apr 24, 2022
@nicolo-ribaudo nicolo-ribaudo merged commit 0b9fb13 into main Apr 24, 2022
@nicolo-ribaudo nicolo-ribaudo deleted the danez-objecttypeannotation-fields branch April 24, 2022 18:44
@nicolo-ribaudo
Copy link
Member

@danez Even if something is not tracked in this issue (for example, this PR is a very small breaking change), we are marking all these changes with the same label so that we can go through them when preparing Babel 8.

@danez
Copy link
Member Author

danez commented Apr 24, 2022

Ok cool.

@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 Jul 25, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 25, 2022
@JLHwung JLHwung added PR: Breaking Change 💥 A type of pull request used for our changelog categories for next major release and removed babel 8 labels Aug 9, 2023
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: Breaking Change 💥 A type of pull request used for our changelog categories for next major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants