facebook / facebook/jscodeshift

Merge calls to curried function

Ouverte
#369 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
JavaScript
Étoiles
10k
Forks
498
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

lodash/fp supports currying, so you can have calls, like this:
`set(key)(value)(obj)`
And I'd like to use a codemod to change them to be a single call, like this:
`set(key, value, obj)`

But I can't figure out how to get the args from the follow on calls (which appear to come before in the iteration) and make a single call. Is there a way to do this with the current version of `jscodeshift`? If not, can this be considered a bug?

Here's the error:
```
ERR web/sockets/PubSubWatcher.js Transformation error ([{ type: TemplateLiteral, start: 654, end: 671, loc: [object Object], expressions: [object Object], quasis: [object Object],[object Object] }, [{ type: MemberExpression, start: 682, end: 696, loc: [object Object], object: [object Object], property: [object Object], computed: false }]] does not match field "arguments": [Expression | SpreadElement] of type CallExpression)
Error: [{ type: TemplateLiteral, start: 654, end: 671, loc: [object Object], expressions: [object Object], quasis: [object Object],[object Object] }, [{ type: MemberExpression, start: 682, end: 696, loc: [object Object], object: [object Object], property: [object Object], computed: false }]] does not match field "arguments": [Expression | SpreadElement] of type CallExpression
at addParam (/usr/local/lib/node_modules/jscodeshift/node_modules/ast-types/lib/types.js:447:27)
at /usr/local/lib/node_modules/jscodeshift/node_modules/ast-types/lib/types.js:470:25
at Array.forEach ()
at Function.callExpression (/usr/local/lib/node_modules/jscodeshift/node_modules/ast-types/lib/types.js:468:35)
at NodePath. (/Users/dlj/projects/numetric.other/tools/code/migrate-curry.js:56:22)
at NodePath. (/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 ()
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)
```

Guide de contribution

Ouvrir le guide de contribution

Évaluation

Cette issue n'a pas encore été évaluée.

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.