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

Commit

Permalink
Use a more robust check for member expressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdalton committed May 9, 2016
1 parent 5acb7ec commit 4a9f946
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ export default function({ types: types }) {

MemberExpression(path) {
const { file } = path.hub;
const { node } = path;
const { node, scope } = path;
const { bindings } = scope;
const { object } = node;

if (!types.isIdentifier(object)) {
return;
}
const key = node.property.name;
const parent = _.get(bindings, [object.name, 'path', 'parent']);
const pkgStore = store.getStoreBy('default', object.name);

if (pkgStore) {
Expand All @@ -122,7 +124,7 @@ export default function({ types: types }) {
// Transform `_.foo` to `_foo`.
path.replaceWith(importModule(key, file, getImportBase(pkgStore)));
}
else if (key == 'placeholder') {
else if (types.isImportDeclaration(parent) && store.has(parent.source.value)) {
// Allow things like `bind.placeholder = {}`.
node.object = store.getValueBy('member', object.name) || object;
}
Expand Down

0 comments on commit 4a9f946

Please sign in to comment.