Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxError: Invalid RegExp: Invalid escape, js engine: hermes #1460

Closed
Albert-Gao opened this issue Jul 19, 2024 · 3 comments
Closed

SyntaxError: Invalid RegExp: Invalid escape, js engine: hermes #1460

Albert-Gao opened this issue Jul 19, 2024 · 3 comments
Labels
need more info Awating additional info before proceeding

Comments

@Albert-Gao
Copy link

Albert-Gao commented Jul 19, 2024

Bug Description

a regexp from a library zod-to-json-schema triggers this error on Hermes.

image

  • "expo": "~51.0.21",
  • "react-native": "0.74.3"

Steps To Reproduce

a repo to reproduce it.

https://github.com/Albert-Gao/rn-invalid-regexp

The Expected Behavior

It should work. (Works on JSC)

More

Is it related to this?
#1027

Also created an issue on the lib side to see if we can update this regexp, if it is hard to solve on an engine level.
StefanTerdell/zod-to-json-schema#129

@Albert-Gao Albert-Gao added the bug Something isn't working label Jul 19, 2024
@tmikov tmikov added need more info Awating additional info before proceeding and removed bug Something isn't working labels Jul 19, 2024
@tmikov
Copy link
Contributor

tmikov commented Jul 19, 2024

Can you please provide a minimal repro of the regexp for the Hermes CLI. Ideally it should be one line. We are not able to test RN apps.

@Albert-Gao
Copy link
Author

sure :)

I found a test here:
https://github.com/facebook/hermes/blob/main/test/hermes/regexp-icase.js

the regexp causing problem is this one:
RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u")

should i just put it in the test like that, because it fails on the initialization? so it is suffice as a test case?

@neildhar
Copy link
Contributor

Hey @Albert-Gao, that feature has been implemented in trunk in #1295, but isn't yet in the latest version of React Native. It should work when the next version of RN becomes available.

In the interim, if you have static RegExps that use this feature, you can consider using this babel transform: https://babeljs.io/docs/babel-plugin-transform-unicode-property-regex

Note that if you are using the babel transform, you will need to write your RegExp in the style /^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$/u, instead of invoking new RegExp

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
need more info Awating additional info before proceeding
Projects
None yet
Development

No branches or pull requests

3 participants