From 80b4b7120bbb085d4837f01597ec281e4229c434 Mon Sep 17 00:00:00 2001 From: Logan Smyth Date: Wed, 22 Nov 2017 13:27:31 -0800 Subject: [PATCH] Quick fix for typescript import crash. (#6879) --- packages/babel-plugin-transform-typescript/src/index.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/babel-plugin-transform-typescript/src/index.js b/packages/babel-plugin-transform-typescript/src/index.js index 096ba09f44..d1fe9e8345 100644 --- a/packages/babel-plugin-transform-typescript/src/index.js +++ b/packages/babel-plugin-transform-typescript/src/index.js @@ -44,7 +44,14 @@ export default function() { for (const specifier of path.node.specifiers) { const binding = path.scope.getBinding(specifier.local.name); - if (isImportTypeOnly(binding, state.programPath)) { + + // The binding may not exist if the import node was explicitly + // injected by another plugin. Currently core does not do a good job + // of keeping scope bindings synchronized with the AST. For now we + // just bail if there is no binding, since chances are good that if + // the import statement was injected then it wasn't a typescript type + // import anyway. + if (binding && isImportTypeOnly(binding, state.programPath)) { importsToRemove.push(binding.path); } else { allElided = false;