mirror of
https://github.com/zhigang1992/nativewind.git
synced 2026-06-17 23:05:59 +08:00
fix: import detection when using react-native-web babel plugin
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
import { NodePath } from "@babel/core";
|
import { NodePath } from "@babel/core";
|
||||||
import {
|
import {
|
||||||
ImportDeclaration,
|
ImportDeclaration,
|
||||||
|
isImportDefaultSpecifier,
|
||||||
isImportSpecifier,
|
isImportSpecifier,
|
||||||
isStringLiteral,
|
isStringLiteral,
|
||||||
} from "@babel/types";
|
} from "@babel/types";
|
||||||
@@ -13,15 +14,17 @@ export function hasNamedImport(
|
|||||||
variable: string,
|
variable: string,
|
||||||
source: string
|
source: string
|
||||||
) {
|
) {
|
||||||
if (path.node.source.value === source) {
|
if (path.node.source.value.startsWith(source)) {
|
||||||
return path.node.specifiers.some((specifier) => {
|
return path.node.specifiers.some((specifier) => {
|
||||||
if (!isImportSpecifier(specifier)) {
|
if (isImportDefaultSpecifier(specifier)) {
|
||||||
return;
|
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)
|
return false;
|
||||||
? specifier.imported.value === variable
|
|
||||||
: specifier.local.name === variable;
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user