Split declaration initialization / Fix TS Annotation Duplication#244
Merged
nicoespeon merged 4 commits intonicoespeon:masterfrom Feb 9, 2021
Conversation
Does not work because Identifier node is mutated by setting the typeAnnotation property to null and the variableDeclaration needs a type annotation.
nicoespeon
approved these changes
Feb 9, 2021
Owner
nicoespeon
left a comment
There was a problem hiding this comment.
Awesome, thanks for the fix!
I'll update the Changelog & get that release this week with the other changes ❤️
I'll try to get some improvements I've been working on done too, then I'll release.
| lastName = "Doe";` | ||
| }, | ||
| { | ||
| description: "declarations with type annotations", |
Owner
There was a problem hiding this comment.
👍 Thanks for adding a test to illustrate
| t.expressionStatement(t.assignmentExpression("=", id, init)) | ||
| ) | ||
| .map(function ({ id, init }) { | ||
| if (id.type == "Identifier" && "typeAnnotation" in id) { |
Owner
There was a problem hiding this comment.
I think we can write:
if (t.isIdentifier(id)) {And that should work. It will be less dependent of the implementation details.
Contributor
Author
There was a problem hiding this comment.
It looks like you merged into master without adding your suggestion. Did you change your mind?
Owner
Owner
|
@allcontributors please add iulspop for bug |
Contributor
|
I've put up a pull request to add @iulspop! 🎉 |
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #232
Adds a test to cover split declaration with TS annotation and fixes the duplication issue.
I'm not sure if my implementation is readable. I felt the need to add a comment to clarify why I create a new Identifier.
It's necessary, because if I reassign the
typeAnnotationproperty to null, it mutates the Identifier node in thevariableDeclarationtoo. I want the annotation to remain in the declaration, so I need to create a new Identifier and modify that.Feel free to improve the implementation!