Git Product home page Git Product logo

babel-plugin-lodash's Introduction

lodash

Site | Docs | Contributing | Wiki | Code of Conduct

The Lodash library exported as a UMD module.

$ bun run build
$ lodash -o ./dist/lodash.js
$ lodash core -o ./dist/lodash.core.js

Download

Lodash is released under the MIT license & supports modern environments.
Review the build differences & pick one that’s right for you.

Installation

In a browser:

<script src="lodash.js"></script>

Using bun:

$ bun i lodash

In Bun:

// Load the full build.
var _ = require('lodash');
// Load the core build.
var _ = require('lodash/core');
// Load the FP build for immutable auto-curried iteratee-first data-last methods.
var fp = require('lodash/fp');

// Load method categories.
var array = require('lodash/array');
var object = require('lodash/fp/object');

// Cherry-pick methods for smaller browserify/rollup/webpack bundles.
var at = require('lodash/at');
var curryN = require('lodash/fp/curryN');

Looking for Lodash modules written in ES6 or smaller bundle sizes? Check out lodash-es.

Why Lodash?

Lodash makes JavaScript easier by taking the hassle out of working with arrays,
numbers, objects, strings, etc. Lodash’s modular methods are great for:

  • Iterating arrays, objects, & strings
  • Manipulating & testing values
  • Creating composite functions

Module Formats

Lodash is available in a variety of builds & module formats.

babel-plugin-lodash's People

Contributors

albertogasparin avatar boneskull avatar corbanbrook avatar danny-andrews avatar glifchits avatar greenkeeperio-bot avatar insin avatar jdalton avatar jridgewell avatar jscinoz avatar layershifter avatar matt-stripe avatar megawac avatar taopaic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

babel-plugin-lodash's Issues

ReferenceError: Symbol is not defined

I'm seeing this error and I'm not sure what I'm missing:

ReferenceError: Symbol is not defined
    at /home/app/node_modules/babel-plugin-lodash/lib/MapCache.js:83:10
    at Object.<anonymous> (/home/app/node_modules/babel-plugin-lodash/lib/MapCache.js:90:2)
    at Module._compile (module.js:456:26)
    at Module._extensions..js (module.js:474:10)
    at Object.require.extensions.(anonymous function) [as .js] (/home/app/node_modules/babel-register/lib/node.js:166:7)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.cls_wrapMethod [as _load] (/usr/lib/node_modules/newrelic/lib/shimmer.js:230:38)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)

server.js

require('babel-polyfill');
require('babel-core/register')({
  "presets": [ "es2015", "stage-0" ],
  "plugins": [ "lodash" ]
});

package.json

"dependencies": {
    "babel-core": "^6.8.0",
    "babel-plugin-lodash": "^3.0.0",
    "babel-polyfill": "^6.8.0",
    "babel-preset-es2015": "^6.6.0",
    "babel-preset-stage-0": "^6.5.0"
},

nested and uninvoked method references not being replaced

In the following code, isPlainObject, isArray, and identity do not get replaced:

export const camelCaseTransform = cond([
    [isPlainObject,     (obj) => camelCaseProps(obj)],
    [isArray,           (arr) => map(arr, camelCaseTransform)],
    [constant(true),    identity],
])

Using import { isPlainObject, isArray, identity, ... } from 'lodash', the above code compiles to

var camelCaseTransform = exports.camelCaseTransform = (0, _cond3.default)([[isPlainObject, function (obj) {
    return camelCaseProps(obj);
}], [isArray, function (arr) {
    return (0, _map5.default)(arr, camelCaseTransform);
}], [(0, _constant3.default)(true), identity]]);

var camelCaseProps = (0, _flow3.default)((0, _mapKeys2.default)(_camelCase3.default), (0, _mapValues2.default)(camelCaseTransform));

While using the manual cherry pick style import isPlainObect from 'lodash/isPlainObject', the above code compiles to

var camelCaseTransform = exports.camelCaseTransform = (0, _cond3.default)([[_isPlainObject2.default, function (obj) {
    return camelCaseProps(obj);
}], [_isArray2.default, function (arr) {
    return (0, _map5.default)(arr, camelCaseTransform);
}], [(0, _constant3.default)(true), _identity2.default]]);

var camelCaseProps = (0, _flow3.default)((0, _mapKeys2.default)(_camelCase3.default), (0, _mapValues2.default)(camelCaseTransform));

Happy to create a full, live reproduction if helpful!

babel-plugin-lodash and babel-plugin-transform-object-rest-spread can cause an error when used together

For reference, babel-plugin-transform-object-rest-spread is an official plugin that transpiles this stage 2 proposal.


Test file:

// test.js

import {keys} from 'lodash';

var {a: theFirstProperty, ...theOtherProperties} = {a: 1, b: 2, c: 3};

console.log(keys({a: 1, b: 2, c: 3}));

// expected: ['a', 'b', 'c']

.babelrc:

{
  "plugins": [
    "lodash",
    "transform-es2015-modules-commonjs",
    "transform-es2015-destructuring",
    "transform-object-rest-spread"
  ]
}

Transpiled using:

babel --out-file transpiledTest.js test.js

The transpiled file looks like this:

// transpiledTest.js

'use strict';

var _keys2 = require('lodash/keys');

var _keys3 = _interopRequireDefault(_keys2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (_keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }

var _a$b$c = { a: 1, b: 2, c: 3 };
var theFirstProperty = _a$b$c.a;

var theOtherProperties = _objectWithoutProperties(_a$b$c, ['a']);

console.log((0, _keys3.default)({ a: 1, b: 2, c: 3 }));

// expected: ['a', 'b', 'c']

Running the transpiled file with node transpiledTest.js (using Node 6.1.0) gives the following error:

/path/to/transpiledTest.js:9
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (_keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
                                                                                         ^

ReferenceError: _keys is not defined
    at _objectWithoutProperties (/path/to/transpiledTest.js:9:90)
    at Object.<anonymous> (/path/to/transpiledTest.js:14:26)
    at Module._compile (module.js:541:32)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Function.Module.runMain (module.js:575:10)
    at startup (node.js:160:18)
    at node.js:445:3

The bug only occurs when importing lodash.keys.

It seems to happen because the _objectWithoutProperties function created by babel usually looks vaguely like this:

function (obj, keys) { doSomethingWith(keys) }

...but in this case it ends up looking like this:

// note: the parameter is still called `keys` even though the reference changed to `_keys`
function (obj, keys) { doSomethingWith(_keys) }

cannot read property name of null (fpSpecified) on v2.2.0

Hi,

I'm getting this error on v2.2.0 (but not on 2.1.0)

ERROR in ./frontend/js/entry.js
Module build failed: TypeError: /Users/nuno/cp/james/frontend/js/entry.js: Cannot read property 'name' of null
    at PluginPass.<anonymous> (/Users/nuno/cp/james/node_modules/babel-plugin-lodash/lib/index.js:152:28)
    at newFn (/Users/nuno/cp/james/node_modules/babel-core/node_modules/babel-traverse/lib/visitors.js:262:19)
    at NodePath._call (/Users/nuno/cp/james/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:63:18)
    at NodePath.call (/Users/nuno/cp/james/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:47:17)
    at NodePath.visit (/Users/nuno/cp/james/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:93:12)
    at TraversalContext.visitQueue (/Users/nuno/cp/james/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:146:16)
    at TraversalContext.visitMultiple (/Users/nuno/cp/james/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:110:17)
    at TraversalContext.visit (/Users/nuno/cp/james/node_modules/babel-core/node_modules/babel-traverse/lib/context.js:176:19)
    at Function.traverse.node (/Users/nuno/cp/james/node_modules/babel-core/node_modules/babel-traverse/lib/index.js:131:17)
    at NodePath.visit (/Users/nuno/cp/james/node_modules/babel-core/node_modules/babel-traverse/lib/path/context.js:103:22)

I can reproduce this error with a file as simple as this (no use of lodash in the file)

for (const a of b) {}

Thanks,
Nuno

Use webpack context for resolving lodash module paths

At the moment, the plugin uses process.cwd() for finding a local lodash installation (config.js, line 31).

When running a devserver in a different directory than the root of the files to be compiled, lodash modules cannot be resolved and webpack quits building early.

Example:

  • express with webpack-dev-middleware runs in ./index.js, directory is also cwd
  • webpack config is in ./frontend/
  • frontend code is in ./frontend/
  • lodash is a dependency in ./frontend/package.json
  • .babelrc is in ./frontend

Lots of errors like this one ensue:

ERROR in ./frontend/src/components/x.js
Module not found: Error: Cannot resolve module 'lodash/string/capitalize' in /Users/daniel/x/frontend/src/components
 @ ./frontend/src/components/x.js 31:19-54

Current workaround: install lodash as a dependency in the cwd

Suggestion: Use the context property from the webpack config as root for resolving lodash.

Example ?

I've tried to add it to a current project but it failed with this kind of error:

Error: index.js: lodash method map was not in known modules
Please file a bug if it's my fault https://github.com/megawac/babel-plugin-lodash/issues

So I made a very tiny example and I have the same problem, where babel index.js > babel.js is fine but babel --plugins lodash index.js > babel-lodash.js triggers the same error (even if added in .babelrc)

Here's my example, what am I doing wrong ?

Thanks.

the incredible expanding bundle

So this is curious--I am running my code thru Babel (and finally Browserify).

Whenever I'm using Lodash in my code, I use it like:

import _ from 'lodash';

Here's .babelrc:

{
  "presets": [
    "es2015"
  ]
}

and Browserify command:

$ browserify --require es6-symbol/implement --require es6-map/implement --require es6-set/implement --standalone mocha --plugin [ bannerify --file .banner.ejs --pkg package.json ] src --outfile dist/mocha.js

Resulting size (bytes) of dist/mocha.js: 752278

Let's add babel-plugin-lodash to the mix:

{
  "presets": [
    "es2015"
  ],
  "plugins": [
    "lodash"
  ]
}

after re-running the same Browserify command above,

Resulting size (bytes) of dist/mocha.js: 810148

what is this I don't even

Changelog

Can we please add a changelog?

I wanted to check what changed in 3.0, but don't want to check 100+ commits.

Update fp conversion

The readme currently has

Example

Transforms

import lodash from 'lodash';
import { add } from 'lodash/fp';

let add1 = add(1);
lodash.map([1, 2, 3], add1);

roughly to

import _add from 'lodash/math/add';
import _map from 'lodash/collection/map';
import convert from 'lodash/fp/convert';

const _fp = convert({
  'add': _add
});

let add1 = _fp.add(1);
_map([1, 2, 3], add1);

but with 4.1.0 individual fp modules exist so they could be used instead.

method missing from compiled code in 2.2.0

I'm seeing and error where the generated code with this plugin is now missing having the method inlined in some cases after updating from 2.1.0 to 2.2.0.

source

import {noop} from 'lodash';
export default (cb) => typeof cb === 'function' ? cb : noop;

compiled

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _noop2 = require('lodash/utility/noop');

var _noop3 = _interopRequireDefault(_noop2);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.default = function (cb) {
  return typeof cb === 'function' ? cb : ;
};

I put together a gist with a the complete example including my babelrc and the previously compiled code from 2.1.0.

SyntaxError: Unexpected token default

I have a module file that causes a syntax error when transformed with babel-plugin-lodash.

The module file:

// myModule.js

export {default as theCryptoModule} from 'crypto';

The .babelrcfile:

{
  "plugins": [
    "lodash",
    "transform-es2015-modules-commonjs"
  ]
}

I transpiled it using:

node_modules/.bin/babel myModule.js --out-file transpiledModule.js

The output file transpiledModule.js looks like this:

'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.theCryptoModule = default;

Running this file with node transpiledModule.js gives the following error:

/path/to/transpiledModule.js:6
exports.theCryptoModule = default;
                          ^^^^^^^
SyntaxError: Unexpected token default
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:511:25)
    at Object.Module._extensions..js (module.js:550:10)
    at Module.load (module.js:456:32)
    at tryModuleLoad (module.js:415:12)
    at Function.Module._load (module.js:407:3)
    at Function.Module.runMain (module.js:575:10)
    at startup (node.js:159:18)
    at node.js:444:3

Note that this issue no longer occurs if babel-plugin-lodash is removed from the .babelrc file.


I'm using Node v6.0.0, [email protected], [email protected], and [email protected], all freshly installed from the npm registry:

$ rm -rf node_modules/
$ npm install babel-cli babel-plugin-transform-es2015-modules-commonjs babel-plugin-lodash

It's possible that this is an upstream issue, since I think it was working before [email protected] got released yesterday. However, I don't know enough about the internals of babel or babel-plugin-lodash to be sure of where the issue is coming from.

Not clear if this works with lodash v4 at all

I installed the plugin and configured it in webpack but it is install lodash 3.10.1 as a dependency. If i then manually install lodash (npm install lodash --save). And then according to your plugin use something like:

import {isEmpty} from 'lodash';

i get this:

Module build failed: Error:
/Users/butsjoh/Younited/trusted_platform/app/assets/webpack/javascripts/components/notifications.connected.jsx: lodash method isEmpty was not in known modules

noop is undefined (via `import {noop} from 'lodash'` ), if you use it inside another lodash method

Example

import {each, noop} from 'lodash';
function () {
  ...
  console.log(noop); // noop exist
  // the first noop is exist, the second is undefined
  each(objectKeys, key =>  {console.log(noop); dumbObject[key] = noop;}); 
  return object;
}

after webpack we get something like this

function () {
 ...
 console.log(_noop3.default);
 (0, _each3.default)(objectKeys, function (key) {
    console.log(_noop3.default);dumbObject[key] = noop;
 });
 return object;
}

[email protected], [email protected]

map/alias lodash-compat

it seems the plugin is able to map/alias lodash imports to their compat version through this config snippet taken from the npm readme.

{
  "plugins": [["lodash", { "id": "lodash-compat", "cwd": "some/path" }]],
  "presets": ["es2015"]
}

since lodash broke with categories this mechanism seems to be restricted to versions 3.x.x

ReferenceErrors due to bad transpilation

Hello,

Thanks for the plugin, it is very convenient. I would just like to report an error I am running into:

I have the following code:

import {
  clone,
  get,
  set,
  has,
  mapValues,

  isPlainObject as isObj,
  isFunction as isFn,

  constant,
  noop,
  identity,
} from 'lodash';

and it is transpiling into this:

    var _has = __webpack_require__(290);

    var _has2 = _interopRequireDefault(_has);

    var _isPlainObject = __webpack_require__(322);

    var _isPlainObject2 = _interopRequireDefault(_isPlainObject);

    var _mapValues = __webpack_require__(291);

    var _mapValues2 = _interopRequireDefault(_mapValues);

    var _clone = __webpack_require__(294);

    var _clone2 = _interopRequireDefault(_clone);

    var _set = __webpack_require__(317);

    var _set2 = _interopRequireDefault(_set);

    var _get = __webpack_require__(104);

    var _get2 = _interopRequireDefault(_get);

    var _constant = __webpack_require__(319);

    var _constant2 = _interopRequireDefault(_constant);

    var _isFunction = __webpack_require__(44);

    var _isFunction2 = _interopRequireDefault(_isFunction);

Specifically, noop and identity are missing which leads to ReferenceError: noop is not defined. I cannot figure out why they might be getting excluded. I am running the latest version of the plugin.

> ~/code> npm show babel-plugin-lodash version
> 2.0.1

Any help is much appreciated. Thanks

Mention "bad practise" approach

Do i understand this correctly - such plugin should be used only if consumer doesn't use tools like rollup or webpack 2 where tree-shaking algorithm is implemented? If so, should this note be added to the docs?

Also, would you agree that this code -

import _ from 'lodash';

_.map([1, 2, 3], addOne);

Is worse then

import { map } from 'lodash';

map([1, 2, 3], addOne);

?

Support other lodash builds

It may be nice to support other lodash builds such as -compat and -es in transpilation. Currently these are simply ignored

how to use lodash mixins?

hi,

i'm migrating an old project to es6 and babel and this is an extremely useful plugin for me but i don't know how to use mixins to prevent this error:

Module build failed: Error: /app/.../myFile.js: lodash method myFunction was not in known modules.

i try to use

import _ from 'lodash'

_.mixin({
  myFunction(o) {
    // ...
  }
})

is this even possible? :)

Update fp support for lodash v4.

Lodash v4 will pull fp into the primary lodash package.

The paths will be

require('lodash/fp/convert') // convertor
require('lodash/fp.js') // monolithic fp build

cannot import {noop} from 'lodash'

(assuming this is a babel-plugin-lodash issue)

import {noop} from 'lodash'

results in noop having a value of undefined.

import noop from 'lodash/noop';

results in noop having a value of the noop function.

I have not tested this against lodash/fp/noop or {noop} from lodash/fp.

[email protected], [email protected]

Named import from lodash/fp fails when used as a function argument

I have managed to repro it down to the following:
using lodash (v4.6.1) and babel-plugin-lodash (v2.2.1)
the code was run with babel-cli (v6.6.5) on windows 7

import { filter, isObject } from 'lodash/fp'
filter(isObject)
// ->
// import _isObject from 'lodash\\fp\\isObject';
// import _filter from 'lodash\\fp\\filter';

// _filter(isObject); // <- notice the missing _ from isObject

Some notes:
The filter function does not need to come from lodash, anything will do in its place.
The isObject function can be anything from lodash/fp
Importing from 'lodash' works
Importing the default export directly works (eg. import isObject from 'lodash/fp/isObject')

import { map, isArray } from 'lodash/fp'
const f = 1//dummy function
f(map)
isArray

import { filter, isObject } from 'lodash'
filter(isObject)

import { maxBy } from 'lodash/fp'
import sum from 'lodash/fp/sum'
maxBy(sum)
// ->
// import _isArray from 'lodash\\fp\\isArray';
// import _map from 'lodash\\fp\\map';
// const f = 1; //dummy function
// f(map);
// isArray;

// _filter(_isObject);

// import sum from 'lodash/fp/sum';
// _maxBy(sum);

Workaround:
Importing the default export:

import isObject from 'lodash/fp/isObject'

_.each transforms into arrayEach?

I use _.each for objects too, but seems like it's turning it into an arrayEach, which doesn't let me iterate through arrays.

Bug?

screen shot 2016-05-26 at 5 35 01 pm

Better tree shaking

I'm converting a project which imports individual lodash modules (import each from 'lodash.foreach') to use this plugin instead (this plugin helps me avoid a webpack amd/define bug).

However, there's still a lot of lodash code left in place that my code isn't using - in my case the difference is 143k (uncompressed) more code compared to when I loaded the files individually.

Looking at the diff, I see a bunch of variables and other methods unrelated to anything I use.

Move to the lodash org?

Hey @megawac!

I think this plugin is super valuable to the lodash community and since you're already a lodash contributor would you dig moving this to the lodash org?

support question: enabling this only in node modules

wondering if anyone has tried enabling only this in all the modules, including node_modules. would be a neat way to automatically slim down builds. some issues are i see are:

  • node_modules are not ES6, which is not supported by this module
  • needs a separate babel loader in webpack probably

just something i thought about, which is probably an over optimization

missing functions redux

I'm doing the following:

import {isEmpty, compose, flatten, compact} from 'lodash/fp';
export const squish = compose(flatten, compact);

flatten and compact are undefined after transpilation.

fwiw, the following works:

import {isEmpty, compose} from 'lodash/fp';
import flatten from 'lodash/fp/flatten';
import compact from 'lodash/fp/compact';
export const squish = compose(flatten, compact);

Am I doing something wrong here? I don't see compact mentioned anywhere in the "FP Guide".

The plugin "lodash" didn't export a Plugin instance

I keep getting the following error message when attempting to use "babel-plugin-lodash".

events.js:141
      throw er; // Unhandled 'error' event
      ^
TypeError: The plugin "lodash" didn't export a Plugin instance
    at PluginManager.validate (/pragmatist/node_modules/gulp-babel/node_modules/babel-core/lib/transformation/file/plugin-manager.js:164:13)
    at PluginManager.add (/pragmatist/node_modules/gulp-babel/node_modules/babel-core/lib/transformation/file/plugin-manager.js:213:10)
    at File.buildTransformers (/pragmatist/node_modules/gulp-babel/node_modules/babel-core/lib/transformation/file/index.js:237:21)
    at new File (/pragmatist/node_modules/gulp-babel/node_modules/babel-core/lib/transformation/file/index.js:139:10)
    at Pipeline.transform (/pragmatist/node_modules/gulp-babel/node_modules/babel-core/lib/transformation/pipeline.js:164:16)
    at DestroyableTransform._transform (/pragmatist/node_modules/gulp-babel/index.js:30:20)
    at DestroyableTransform.Transform._read (/pragmatist/node_modules/gulp-babel/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:172:10)
    at DestroyableTransform.Transform._write (/pragmatist/node_modules/gulp-babel/node_modules/through2/node_modules/readable-stream/lib/_stream_transform.js:160:12)
    at doWrite (/pragmatist/node_modules/gulp-babel/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:326:12)
    at writeOrBuffer (/pragmatist/node_modules/gulp-babel/node_modules/through2/node_modules/readable-stream/lib/_stream_writable.js:312:5)

What are some of the possible reasons for getting this error?

release again

I'm not 100%, but I'm pretty sure that 2.2.2 wasn't built before publishing. Add a prepublish script?

Plugin chokes on `export * from` syntax.

Hey there! I've been trying to integrate this lovely-looking plugin into my build pipeline, but it's throwing errors in modules that use syntax like this:

// app/flux/reducers/index.js
export * from './issue';
export * from './pieces';
export * from './user';

When I run Babel with the Lodash plugin enabled, any module that uses that export * from syntax throws a variant on the following error:

ERROR in ./src/app/flux/reducers/index.js
Module build failed: TypeError: /Users/daniel/Repos/ignota/issues/issue0/src/app/flux/reducers/index.js: Cannot read property 'file' of undefined
    at PluginPass.ImportDeclaration (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-plugin-lodash/lib/index.js:105:26)
    at newFn (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-traverse/lib/visitors.js:310:19)
    at NodePath._call (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-traverse/lib/path/context.js:78:18)
    at NodePath.call (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-traverse/lib/path/context.js:49:17)
    at NodePath.visit (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-traverse/lib/path/context.js:108:12)
    at TraversalContext.visitQueue (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-traverse/lib/context.js:174:16)
    at TraversalContext.visitSingle (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-traverse/lib/context.js:124:19)
    at TraversalContext.visit (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-traverse/lib/context.js:219:19)
    at Function.traverse.node (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-traverse/lib/index.js:171:17)
    at traverse (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-traverse/lib/index.js:90:12)
    at File.transform (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-core/lib/transformation/file/index.js:548:35)
    at /Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-core/lib/transformation/pipeline.js:50:19
    at File.wrap (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-core/lib/transformation/file/index.js:563:16)
    at Pipeline.transform (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-core/lib/transformation/pipeline.js:47:17)
    at transpile (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-loader/index.js:14:22)
    at Object.module.exports (/Users/daniel/Repos/ignota/issues/issue0/node_modules/babel-loader/index.js:88:12)
 @ ./src/app/flux/index.js 9:16-37

Without the plugin, the builds run and the exports are parsed as expected.

Spread operator

Thanks for this great project!

I’m running into an issue with this simple code:

import _ from 'lodash';

const mergeOptions = (...args) =>
  _.merge({}, ...args);

console.log(
  _.merge({ a: 1 }, { b: 2 }) // Yep
);

console.log(
  mergeOptions({ c: 3 }, { d: 4 }) // Nope
);

The first normal call to _.merge works fine, but the second with the spread isn’t recognized: Uncaught ReferenceError: _ is not defined

Looking at the Babel output, this is logical since the spread compiles to a merge.apply(_, Array) call.

var _merge = __webpack_require__(96);
var _merge2 = _interopRequireDefault(_merge);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var mergeOptions = function mergeOptions() {
  for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
    args[_key] = arguments[_key];
  }
  return _merge2.default.apply(_, [{}].concat(args)); // 🔥💥💢
};
console.log((0, _merge2.default)({ a: 1 }, { b: 2 }));
console.log(mergeOptions({ c: 3 }, { d: 4 }));

That’s technically correct since the original call was _.merge and Babel wants to preserve the this binding…

Is there anything you can do here to solve this? For the purpose of Lodash, would it be possible to change this to .apply(undefined, Array) since the binding doesn’t matter for Lodash AFAIK?

Thanks for your time! :)

dynamic props are broken

very useful plugin but broken :(

code

"use strict";

export default {
    [process.env.NODE_ENV]: process.env.NODE_ENV,
    test: "test"
};

exits with error

➜  operator git:(operator) ✗ node_modules/.bin/babel test.js
TypeError: test.js: Cannot read property 'name' of null
    at PluginPass.<anonymous> (/operator/node_modules/babel-plugin-lodash/lib/index.js:152:28)
    at newFn (/operator/node_modules/babel-traverse/lib/visitors.js:262:19)
    at NodePath._call (/operator/node_modules/babel-traverse/lib/path/context.js:63:18)
    at NodePath.call (/operator/node_modules/babel-traverse/lib/path/context.js:47:17)
    at NodePath.visit (/operator/node_modules/babel-traverse/lib/path/context.js:93:12)
    at TraversalContext.visitQueue (/operator/node_modules/babel-traverse/lib/context.js:146:16)
    at TraversalContext.visitMultiple (/operator/node_modules/babel-traverse/lib/context.js:110:17)
    at TraversalContext.visit (/operator/node_modules/babel-traverse/lib/context.js:176:19)
    at Function.traverse.node (/operator/node_modules/babel-traverse/lib/index.js:131:17)
    at NodePath.visit (/operator/node_modules/babel-traverse/lib/path/context.js:103:22)

.babelrc

{
  "presets": [
    "es2015"
  ],
  "plugins": [
    "lodash"
  ]
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.