Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/babel/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { dirname, resolve, sep } from "path";

import tBabelTypes, { type CallExpression } from "@babel/types";

export type BabelTypes = typeof tBabelTypes;
Expand Down Expand Up @@ -38,3 +40,8 @@ export function getInteropRequireDefaultSource(

return requireArg.value;
}

// The handlers match "/"-separated package paths, and path.resolve separates with "\" on Windows
export function resolveImportSource(filename: string, source: string): string {
return resolve(dirname(filename), source).split(sep).join("/");
}
5 changes: 2 additions & 3 deletions src/babel/react-native-web.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { dirname, resolve } from "path";

import { type NodePath } from "@babel/traverse";
import tBabelTypes, {
type CallExpression,
Expand All @@ -10,12 +8,13 @@ import tBabelTypes, {
} from "@babel/types";

import { allowedModules } from "./allowedModules";
import { resolveImportSource } from "./helpers";

type BabelTypes = typeof tBabelTypes;

function parseReactNativeWebSource(source: string, filename: string) {
if (source.startsWith(".")) {
source = resolve(dirname(filename), source);
source = resolveImportSource(filename, source);

const internalPath = source.split("react-native-web/dist")[1];
if (!internalPath) {
Expand Down
5 changes: 2 additions & 3 deletions src/babel/react-native.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { dirname, resolve } from "path";

import { type NodePath } from "@babel/traverse";
import tBabelTypes, {
type ImportDeclaration,
Expand All @@ -9,12 +7,13 @@ import tBabelTypes, {
} from "@babel/types";

import { allowedModules } from "./allowedModules";
import { resolveImportSource } from "./helpers";

type BabelTypes = typeof tBabelTypes;

function parseReactNativeSource(source: string, filename: string) {
if (source.startsWith(".")) {
source = resolve(dirname(filename), source);
source = resolveImportSource(filename, source);

const internalPath = source.split("react-native/Libraries/Components/")[1];
if (!internalPath) {
Expand Down