optional-chaining-codemod icon indicating copy to clipboard operation
optional-chaining-codemod copied to clipboard

Could further reduce `.length > 0` checks

Open daveisfera opened this issue 5 years ago • 2 comments
trafficstars

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

daveisfera avatar Mar 11 '20 21:03 daveisfera

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.

villesau avatar Mar 11 '20 22:03 villesau

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

daveisfera avatar Mar 11 '20 22:03 daveisfera