fix: generated builder parameter should respect builder keys#11002
Merged
nicolo-ribaudo merged 1 commit intobabel:masterfrom Jan 13, 2020
Merged
fix: generated builder parameter should respect builder keys#11002nicolo-ribaudo merged 1 commit intobabel:masterfrom
nicolo-ribaudo merged 1 commit intobabel:masterfrom
Conversation
| isNullable(field) ? " | undefined" : "" | ||
| }` | ||
| ); | ||
| if (builderNames.includes(fieldName)) { |
Member
There was a problem hiding this comment.
Wouldn't it be better to directly iterate over builderNames instead of fieldNames? Since fieldNames is generated from an object, I think that we risk changing the order of its keys without thinking about this problem.
Contributor
Author
There was a problem hiding this comment.
The fieldNames has been sorted according to the orders of buildKeys and anything not in the builders are at tails.
nicolo-ribaudo
approved these changes
Jan 13, 2020
This was referenced Feb 22, 2020
This was referenced Mar 7, 2020
This was referenced Mar 14, 2020
This was referenced Mar 22, 2020
This was referenced Mar 26, 2020
This was referenced Apr 3, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a regression introduced in #10917.
In https://github.com/babel/babel/pull/10917/files#diff-dd23409d66e27b24936f7ae4e316073eR265, the
optionalmeta-field is added only if thedefaultmeta-field presents. This change makes sense but unexpectedly it breaksbabel/packages/babel-types/scripts/generators/typescript.js
Line 336 in d0a8982
which relies on
optionalto detect if it is a nullable key, so the non-builder fields are marked as non-optional and included in the definition. For example, here is whatProgramdefinitionbabel/packages/babel-types/src/definitions/core.js
Line 642 in d0a8982
generates in different versions.
v7.7.4
v7.8.0
The
sourceFileis not nullable so all the parameters beforesourceFilebecomes non optional parameters. This is a breaking change for types consumers.The problem here is that we should not include
sourceFileat all because it is not defined inbuildersand we are really lucky that nobody ever complains that the fifth argumentsourceFile?does not work at all.This PR filter the args against
BUILDER_KEYSso the generated types becomewhere the
sourceFileis removed from builder arguments definition, technically it is a breaking change but practically it should not break anyone because the builder will check the arguments length at runtime.In the long term we should add the generated
index.js.flowandindex.d.tsto the codebase so we can track such changes.