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

Could further reduce `.length > 0` checks #23

Open daveisfera opened 4 years ago

daveisfera commented 4 years ago

Thanks once again for this saaaaweeeet codemod!

This line of code item && item.props && item.props.data && item.props.data.length > 0 is reduced to two statementsitem?.props?.data && item.props.data.length > 0 but it could be reduced to a single statement item?.props?.data?.length > 0

villesau commented 4 years ago

Indeed! Good catch! I think > changes the semantics of the AST so that item.props.data.length and > are grouped together which causes it to be left out from the transformation. This might be a bit tricky to solve.

daveisfera commented 4 years ago

Ya, I figured that that might be case. It definitely would be nice to clean up, but isn't a major concern right now.