Skip to content

Commit d1df8e7

Browse files
committed
Only crawl on exception
1 parent 68ac71e commit d1df8e7

2 files changed

Lines changed: 234 additions & 4 deletions

File tree

src/index.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,6 @@ module.exports = function (babel) {
183183
])
184184
);
185185
} else {
186-
path.scope.crawl();
187-
188186
// Replace the occurences of the imported name with the global name.
189187
let binding = path.scope.getBinding(local.name);
190188
let referencePaths = binding.referencePaths;
@@ -214,10 +212,17 @@ module.exports = function (babel) {
214212
});
215213
}
216214

217-
// Replace the occurences of the imported name with the global name.
215+
// Replace the occurrences of the imported name with the global name.
218216
referencePaths.forEach((referencePath) => {
219217
if (!isTypescriptNode(referencePath.parentPath)) {
220-
referencePath.replaceWith(getMemberExpressionFor(global));
218+
const memberExpression = getMemberExpressionFor(global);
219+
220+
try {
221+
referencePath.replaceWith(memberExpression);
222+
} catch (e) {
223+
referencePath.scope.crawl();
224+
referencePath.replaceWith(memberExpression);
225+
}
221226
}
222227
});
223228
}

0 commit comments

Comments
 (0)