From 6c122f487f495de48b5b3c2381afefcb91146b2f Mon Sep 17 00:00:00 2001 From: ieow Date: Tue, 22 Oct 2024 15:47:41 +0800 Subject: [PATCH] fix: test out using escape placeholder --- src/plugin/bundler.ts | 4 +++- src/plugin/index.ts | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/plugin/bundler.ts b/src/plugin/bundler.ts index bb7a1dc..110cc36 100644 --- a/src/plugin/bundler.ts +++ b/src/plugin/bundler.ts @@ -10,8 +10,10 @@ export interface RNRBConfig { web?: boolean; } +export const ESCAPE = "REACT_NATIVE_REACT_BRIDGE_ESCAPE" + /** @internal */ -export const escape = (src: string) => src.replace(/([`])/g, "\\$1"); +export const escape = (src: string) => src.replace(/`/g, ESCAPE); const injectString = async (path: string): Promise => { const src = await readFile(path, "utf8"); diff --git a/src/plugin/index.ts b/src/plugin/index.ts index 211fd67..c79b3e4 100644 --- a/src/plugin/index.ts +++ b/src/plugin/index.ts @@ -6,7 +6,7 @@ import type { BuildOptions } from "esbuild"; import { isEntryFile } from "./babel"; -import { RNRBConfig, bundle, escape } from "./bundler"; +import { ESCAPE, RNRBConfig, bundle, escape } from "./bundler"; import { join } from "path"; const metroTransformer = (() => { @@ -45,7 +45,8 @@ export const createTransformer = ( src: "export default String.raw`" + escape(res).replace(/\$/g, '\\$') + - "`.replace(/\\\\([`$])/g, '\\$1')", + "`.replace(/\\\\([`$])/g, '\\$1')" + + `.replace('${ESCAPE}','\`')` }); }