Skip to content

Commit

Permalink
fix: test out using escape placeholder
Browse files Browse the repository at this point in the history
  • Loading branch information
ieow committed Oct 22, 2024
1 parent 8da61d0 commit 6c122f4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/plugin/bundler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> => {
const src = await readFile(path, "utf8");
Expand Down
5 changes: 3 additions & 2 deletions src/plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (() => {
Expand Down Expand Up @@ -45,7 +45,8 @@ export const createTransformer = (
src:
"export default String.raw`" +
escape(res).replace(/\$/g, '\\$') +
"`.replace(/\\\\([`$])/g, '\\$1')",
"`.replace(/\\\\([`$])/g, '\\$1')" +
`.replace('${ESCAPE}','\`')`
});
}

Expand Down

0 comments on commit 6c122f4

Please sign in to comment.