File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments