Make NodePath<T | U> distributive#16439
Merged
nicolo-ribaudo merged 1 commit intobabel:mainfrom Apr 21, 2024
Merged
Conversation
0fe41a6 to
c62c6d6
Compare
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/56735 |
JLHwung
reviewed
Apr 19, 2024
| } | ||
|
|
||
| declare parent: t.ParentMaps[T["type"]]; | ||
| declare parent: t.Node; |
Contributor
There was a problem hiding this comment.
Does parent path type narrowing still work in this PR?
Member
Author
There was a problem hiding this comment.
Yes, because it's properly defined further down in the NodePath interface.
liuxingbaoyu
approved these changes
Apr 19, 2024
Member
liuxingbaoyu
left a comment
There was a problem hiding this comment.
Amazing!
I've tried something similar before and failed. :)
This was referenced May 20, 2024
This was referenced May 20, 2024
This was referenced Jul 20, 2024
This was referenced Jul 21, 2024
This was referenced Jul 21, 2024
Open
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.
Fixes #1, Fixes #2This pull request makes it so that the types
NodePath<t.Identifier | t.StringLiteral>andNodePath<t.Identifier> | NodePath<t.StringLiteral>are equivalent. This makes ourpath.is*able to better perform type narrowing:It also makes #16430 slightly faster, because it reduces the number of possible
NodePath<...>types (becauseNodePath<t.Identifier> | NodePath<t.StringLiteral>andNodePath<t.Identifier | t.StringLiteral>are now the same type).Unfortunately it makes it more common for
.ensureBlock()to not work, sinceassertsreturn types do not work on unions (microsoft/TypeScript#44212). I consider this acceptable, sincepath.is*are much more common.