From 6fc986d7e43835f8672b7c8bcd9406c5bbdacd2f Mon Sep 17 00:00:00 2001 From: Mark Lawlor Date: Mon, 13 Jun 2022 11:31:11 +1000 Subject: [PATCH] fix: import detection when using react-native-web babel plugin --- src/babel/utils/has-named-import.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/babel/utils/has-named-import.ts b/src/babel/utils/has-named-import.ts index 1dfb032..7ede17b 100644 --- a/src/babel/utils/has-named-import.ts +++ b/src/babel/utils/has-named-import.ts @@ -1,6 +1,7 @@ import { NodePath } from "@babel/core"; import { ImportDeclaration, + isImportDefaultSpecifier, isImportSpecifier, isStringLiteral, } from "@babel/types"; @@ -13,15 +14,17 @@ export function hasNamedImport( variable: string, source: string ) { - if (path.node.source.value === source) { + if (path.node.source.value.startsWith(source)) { return path.node.specifiers.some((specifier) => { - if (!isImportSpecifier(specifier)) { - return; + if (isImportDefaultSpecifier(specifier)) { + return specifier.local.name === variable; + } else if (isImportSpecifier(specifier)) { + return isStringLiteral(specifier.imported) + ? specifier.imported.value === variable + : specifier.imported.name === variable; } - return isStringLiteral(specifier.imported) - ? specifier.imported.value === variable - : specifier.local.name === variable; + return false; }); }