lodash / babel-plugin-lodash

Modular Lodash builds without the hassle.
Other
1.95k stars 95 forks source link

_.call causes errors #122

Closed schmod closed 8 years ago

schmod commented 8 years ago

There are a handful of code samples around the web (ie. https://github.com/lodash/lodash/issues/1279) that show _.invokeMap being used with _.call to invoke an array of functions:

_.invokeMap([func1, func2, func3], _.call, null, 1,2,3,4);

In these cases, _.call is simply a shorthand for Function.prototype.call.

Unfortunately, babel-plugin-lodash does not like this, and exits with an error if you try to use it:

The 'lodash' method 'call' is not a known module.

While this is a rather perverse use of lodash, it's indeed valid, and I've seen a few uses of it in the wild.

I think it's safe for us to replace any instances of _.call with Function.prototype.call when _.call is part of a MemberExpression (instead of a CallExpression, ie. _.call()), but I'm not sure if there are any cases where that would be incorrect....

Is this something we should bother supporting, or would it be easier to just print a more descriptive warning, and encourage users to eliminate usages of _.call in their code?

jdalton commented 8 years ago

This plugin is moving in a lib agnostic direction, to become a generic cherry-pick plugin, so I'd like to avoid support for special edge cases like this.