-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: (code actions): add/from destructure #175
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It Looks like it is working!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think its good for its purpose.
didn't really look at the code, I think its fine. However, to destructure should also avoid name collisions eg:
const a = []
const b = {}
b.a
from destruct will result in broken code, a should be named as a2 e.g. a: a2
Thanks for clarifying, we need to remove any |
Yeah, I'll replace it everywhere in the codebase in a separate PR if you approve the way I implemented this logic here. |
This is getting great! So excited to see it in repo, @Ilanaya is it ready to merge now? |
Yep, I think it is. I'll recheck it again soon and merge if u don't mind |
@Ilanaya ok, I've got time to check how it works and I must admit there are some improvements needed:
const a = {
default: 1,
}
a.default
// results in broken code:
const { class } = { // class is resorved token!
class: 1,
}
class If you use require in js file you will have a quickfix to convert the file to es modules eg: module.exports.default = 5 will be converted to const _default = 5
export { _default as default } it just uses isIdentifierANonContextualKeyword: https://github.com/a-tarasyuk/typescript/blob/8dc7ee8c2b3eadcd4d1130afb9c3a9df927ef6a7/src/services/codefixes/convertToEsModule.ts#L165
const a = {
a: 1,
}
a.a
a['b']
a['c-d'] |
fixes #167
Some tests to play with