2024-07-09 17:19:29 +08:00
|
|
|
import { getProxyFactory } from "@lib/utils/lazy";
|
2024-07-30 00:18:01 +08:00
|
|
|
import { findByPropsLazy } from "@metro/wrappers";
|
2024-07-08 19:22:01 +08:00
|
|
|
|
2024-07-20 10:48:49 +08:00
|
|
|
const jsxRuntime = findByPropsLazy("jsx", "jsxs", "Fragment");
|
2024-07-08 19:22:01 +08:00
|
|
|
|
|
|
|
|
function unproxyFirstArg<T>(args: T[]) {
|
2024-10-12 23:07:44 +08:00
|
|
|
if (!args[0]) {
|
|
|
|
|
throw new Error("The first argument (Component) is falsy. Ensure that you are passing a valid component.");
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-09 17:19:29 +08:00
|
|
|
const factory = getProxyFactory(args[0]);
|
2024-07-08 19:22:01 +08:00
|
|
|
if (factory) args[0] = factory();
|
|
|
|
|
return args;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const Fragment = Symbol.for("react.fragment");
|
|
|
|
|
export const jsx = (...args: any[]) => jsxRuntime.jsx(...unproxyFirstArg(args));
|
|
|
|
|
export const jsxs = (...args: any[]) => jsxRuntime.jsxs(...unproxyFirstArg(args));
|