inokawa / react-native-react-bridge

An easy way to integrate your React (or Preact/React Native Web) app into React Native app with WebView.
https://www.npmjs.com/package/react-native-react-bridge
MIT License
256 stars 18 forks source link

Expecting Unicode escape sequence \uXXXX #144

Closed farwayer closed 3 months ago

farwayer commented 9 months ago

Describe the bug

Transformation failed in some cases with the error

 [Error: TransformError SyntaxError: Expecting Unicode escape sequence \uXXXX

To Reproduce

import {webViewRender} from 'react-native-react-bridge/lib/web'

let Root = () => {
  let issue = function inspect(value) {
    switch (typeof value) {
      case 'string':
        if (value.includes("'")) {
          if (!value.includes('"')) {
            return `"${value}"`;
          } else if (!value.includes('`') && !value.includes('${')) {
            return `\`${value}\``;
          }
        }
    }
  };
  console.log(issue)

  return null
}

export default webViewRender(<Root/>)

Platform:

Additional context

Look like the issue is inside createContent() while processing react bundle

farwayer commented 9 months ago

2023_11_19T21 57 18

ieow commented 9 months ago

try add resolve in metro.config.js file

const config =  {
    resolver: {
      extraNodeModules: {
        stream: require.resolve('stream-browserify'),
farwayer commented 9 months ago

@theprashant-one just added the hack to remove the sequence that causes the problem in my case

diff --git a/lib/plugin/index.js b/lib/plugin/index.js
const createContent = (js) => {
+  js = js.replace('return`\\`${t}\\``', 'return')
   js = js.replace(/([`$])/g, '\\$1');
   return "export default String.raw`\n"+wrapByHtml(js)+"\n`.replace(/\\\\([`$])/g, '\\$1')"; 
 };