Make ParseError Much Simpler now that we can use TypeScript#14796
Merged
tolmasky merged 8 commits intobabel:mainfrom Jul 25, 2022
Merged
Make ParseError Much Simpler now that we can use TypeScript#14796tolmasky merged 8 commits intobabel:mainfrom
tolmasky merged 8 commits intobabel:mainfrom
Conversation
…ow that we can use TypeScript. Reviewed by @tolmasky.
Reviewed by @tolmasky.
Reviewed by @tolmasky.
… factoring it out. Reviewed by @tolmasky.
Reviewed by @tolmasky.
…ay, and we may want to change this back to string when we allow custom sytnax plugins (or "SyntaxPlugin | string" just to convey this a bit better, even though that would be the same). Reviewed by @tolmasky.
Reviewed by @tolmasky.
liuxingbaoyu
approved these changes
Jul 25, 2022
Member
liuxingbaoyu
left a comment
There was a problem hiding this comment.
This PR is great and it looks so much better now!
JLHwung
approved these changes
Jul 25, 2022
Contributor
JLHwung
left a comment
There was a problem hiding this comment.
This PR looks great to me.
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.
As originally promised in the TypeSafe Errors PR, this PR dramatically simplifies all the
ParseErrormachinery now that we are on TypeScript (woooo!!!). From a usability perspective, it is now much easier to define error templates, no longer requiring the use of the weird_()flow-workaround-function. So, before you'd have to do something like this:And now you instead do this:
In other words, we've kept the simplicity of the old object reason-code to message mapping, but with real types. This was of course the original goal, but many flow bugs prevented us from doing this as cleanly, so we needed these weird "carrier" functions (like
toParseErrorCredentials) to shuttle the types around. TypeScript is much better at tracking the types everywhere and so we no longer need them and can so we can just use normal objects.Aside from that, there are just a few random fixes to get rid of
ts-expect-errors, etc., and updating comments to reflect the new code.