Skip to content

Commit

Permalink
Only crawl on exception
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeanjones committed Feb 11, 2021
1 parent 68ac71e commit d1df8e7
Show file tree
Hide file tree
Showing 2 changed files with 234 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ module.exports = function (babel) {
])
);
} else {
path.scope.crawl();

// Replace the occurences of the imported name with the global name.
let binding = path.scope.getBinding(local.name);
let referencePaths = binding.referencePaths;
Expand Down Expand Up @@ -214,10 +212,17 @@ module.exports = function (babel) {
});
}

// Replace the occurences of the imported name with the global name.
// Replace the occurrences of the imported name with the global name.
referencePaths.forEach((referencePath) => {
if (!isTypescriptNode(referencePath.parentPath)) {
referencePath.replaceWith(getMemberExpressionFor(global));
const memberExpression = getMemberExpressionFor(global);

try {
referencePath.replaceWith(memberExpression);
} catch (e) {
referencePath.scope.crawl();
referencePath.replaceWith(memberExpression);
}
}
});
}
Expand Down
Loading

0 comments on commit d1df8e7

Please sign in to comment.