villesau / optional-chaining-codemod

Codemod to migrate from Lodash get and logical and expressions to optional chaining
MIT License
112 stars 14 forks source link

Doesn't put "invalid" names in string #21

Closed daveisfera closed 4 years ago

daveisfera commented 4 years ago

Thanks for this awesome codemod!

While running on our code, we noticed that it doesn't handle names that need to be made strings correctly. For example, get(['value', 'something-else'], data) is changed to data?.value?.something-else when it should be data?.value?.['something-else']

villesau commented 4 years ago

Thanks for the kind words! :)

Interesting! I think this issue is only with array representation of the path. with strings it already works:

https://github.com/villesau/optional-chaining-codemod/blob/master/__testfixtures__/transform.output.js#L18

https://github.com/villesau/optional-chaining-codemod/blob/master/__testfixtures__/transform.input.js#L21

Wanna submit a pull request? :) I'm fairly sure this is an easy fix.

daveisfera commented 4 years ago

Ya, I'll take a stab at it