Skip to content
This repository has been archived by the owner on Sep 16, 2023. It is now read-only.

Commit

Permalink
Use types.clone to avoid Babel’s replaceWith cache. [closes #91]
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed Jul 15, 2016
1 parent 432502d commit 84dbe7b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default function lodash({ types }) {
if (isLodash && name == 'chain' && path.parentPath.isCallExpression()) {
throw path.buildCodeFrameError(CHAIN_ERROR);
}
path.replaceWith(identifier);
path.replaceWith(types.clone(identifier));
});
});

Expand All @@ -85,7 +85,7 @@ export default function lodash({ types }) {
pkgStore.set(identifier.name, identifier);

// Replace reference with its modular version.
parentPath.replaceWith(identifier);
parentPath.replaceWith(types.clone(identifier));
}
else if (isLodash) {
const callee = getCallee(path);
Expand Down
5 changes: 5 additions & 0 deletions test/fixtures/lodash-repeat-identifiers/actual.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import _, { noop } from 'lodash';

const array = [_, _, _.noop, _.noop, noop, noop];

noop(_, _, _.noop, _.noop, noop, noop);
11 changes: 11 additions & 0 deletions test/fixtures/lodash-repeat-identifiers/expected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'use strict';

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

var _noop3 = _interopRequireDefault(_noop2);

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

var array = [undefined, undefined, _noop3.default, _noop3.default, _noop3.default, _noop3.default];

This comment has been minimized.

Copy link
@sidx1024

sidx1024 Dec 14, 2021

@jdalton Should the first two values be undefined? This also occurs if you have something like

import _ from 'lodash';

const { map } = _;

get converted to

var b = undefined.map;

Probably relates to Issue #235 as well.


(0, _noop3.default)(_noop3.default.placeholder, _noop3.default.placeholder, _noop3.default, _noop3.default, _noop3.default, _noop3.default);

0 comments on commit 84dbe7b

Please sign in to comment.