Skip to content

Doesn't handle curried versions of get() and getOr() #24

@daveisfera

Description

@daveisfera

One last big thanks for the awesome codemod!

Curried versions of get() and getOr() cause an error:

TypeError: Cannot read property 'type' of undefined
    at skip (/Users/dlj/projects/optional-chaining-codemod/transform.js:82:35)
    at NodePath.<anonymous> (/Users/dlj/projects/optional-chaining-codemod/transform.js:133:9)
    at NodePath.<anonymous> (/usr/local/lib/node_modules/jscodeshift/src/collections/Node.js:142:47)
    at /usr/local/lib/node_modules/jscodeshift/src/Collection.js:75:36
    at Array.forEach (<anonymous>)
    at Collection.forEach (/usr/local/lib/node_modules/jscodeshift/src/Collection.js:74:18)
    at Collection.replaceWith (/usr/local/lib/node_modules/jscodeshift/src/collections/Node.js:140:17)
    at Collection.replaceWith (/usr/local/lib/node_modules/jscodeshift/src/Collection.js:413:43)
    at mangleLodashGets (/Users/dlj/projects/optional-chaining-codemod/transform.js:132:8)
    at module.exports (/Users/dlj/projects/optional-chaining-codemod/transform.js:313:3)

But they could be turned into fat arrow functions using the existing logic, like the following:
get('value') to v => v?.value
getOr(default, 'value') to v => v?.value ?? default

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions