Improve transform-destructuring typings#14236
Merged
JLHwung merged 8 commits intobabel:mainfrom Mar 7, 2022
Merged
Conversation
JLHwung
commented
Feb 3, 2022
|
|
||
| if ( | ||
| t.isIdentifier(node) && | ||
| t.isReferenced(node, ancestors[ancestors.length - 1]) && |
Contributor
Author
There was a problem hiding this comment.
t.isReferenced(node, ancestors[ancestors.length - 1]) is changed to t.isReferenced(node, ancestors[ancestors.length - 1].node). This is a bug caught by type checker.
JLHwung
commented
Feb 3, 2022
| const specifiers = []; | ||
|
|
||
| for (const name of Object.keys(path.getOuterBindingIdentifiers(path))) { | ||
| for (const name of Object.keys(path.getOuterBindingIdentifiers())) { |
Contributor
Author
There was a problem hiding this comment.
Another bug caught by type checker.
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/51391/ |
| path.ensureBlock(); | ||
|
|
||
| const block = node.body; | ||
| // @ts-expect-error: ensureBlock ensures that node.body is a BlockStatement |
Member
There was a problem hiding this comment.
Could you check if changing the ensureBlock signature to this helps?
function ensureBlock<T extends t.Loop | t.WithStatement | t.Function | t.LabeledStatement | t.CatchClause>(
this: NodePath<T>,
): assert this is NodePath<T & { node: t.BlockStatement }>
Contributor
Author
There was a problem hiding this comment.
Unfortunately we can't add type assertion without breaking change because:
ensureBlockreturns at.Nodewhile assertion predicates requires that the function returnsvoid.this-type guards can only be added to a class method, though we can move it back toindexor put it in a separate file and extends an interface (type with assertions) instead.
Comment on lines
+11
to
+16
| for (const elem of pattern.elements) { | ||
| if (t.isRestElement(elem)) { | ||
| return true; | ||
| } | ||
| } | ||
| return false; |
Member
There was a problem hiding this comment.
Nit: these could be "compacted" to pattern.elements.some(elem => t.isRestElement(elem))
527552b to
57535de
Compare
nicolo-ribaudo
approved these changes
Feb 13, 2022
c309266 to
446b07e
Compare
446b07e to
85697cf
Compare
existentialism
approved these changes
Mar 7, 2022
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 improves typings of
plugin-transform-destructuring. I extracted these routines into a new module.They are likely to be reused in the
destructuring-privatetransformer I am currently working on. In this PR they are not exposed so it can ship in patch release.