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

hermes support for react native? #19

Open
subtleGradient opened this issue Aug 21, 2024 · 3 comments
Open

hermes support for react native? #19

subtleGradient opened this issue Aug 21, 2024 · 3 comments

Comments

@subtleGradient
Copy link
Contributor

Not sure what it would take to make it work on RN in Hermes.
https://github.com/facebook/hermes/blob/main/README.md


https://github.com/facebook/hermes/blob/73cb6664fe233150e1313553a135ffc472c16227/doc/RegExp.md

## RegExp


The Hermes regexp engine is a traditional engine using a backtracking stack. 
It compiles a regexp into bytecode which can be executed efficiently. For regexp literals like `/abc/`, 
this occurs at compile time: the regexp bytecode is embedded into the Hermes bytecode file. 
Note regexp bytecode is distinct from Hermes bytescode.


The regexp engine proceeds as follows:


1. *Parse phase.* The regexp parser emits a tree of nodes, effectively an IR.
1. *Optimization phase.* The node tree is traversed and optimized in various ways.
1. *Emitting phase.* The node tree is traversed and emits regexp bytecode.
1. *Execution phase.* The bytecode is executed against an input string.


## Supported Syntax


As of this writing, Hermes regexp supports


1. All of ES6, including global, case-insensitive, multiline, sticky, and Unicode (and legacy).
1. ES9 lookbehinds.
1. Named capture groups.
1. Unicode property escapes.
@slevithan
Copy link
Owner

What errors or problems are you seeing when running regex in React Native?

regex's core processing relies on a few somewhat-modern regex features that the Hermes document you quoted claims to support -- things like ES6/ES2015's u flag and ES9/ES2018's named capture and lookbehind. It also uses ES2018's s flag, which is not mentioned. But I don't see any fundamental issue (apart from lack of support for s, or potential Hermes bugs / divergences from the ES RegExp spec) that would prevent it from working.

Lack of flag s would be disappointing (hopefully that's just an omission in the docs), but could be worked around. Swapping . with [^] in the core code would be trivial, but it would require a bit more work in regex-utilities.

Note that, a few days ago, Hermes 0.13.0 added support for ES2018's Unicode properties (\p{...}), and the Hermes version was bumped to include this in React Native 0.75.1. Can you check if it works in RN 0.75.1 or later?

@subtleGradient
Copy link
Contributor Author

I'll check again once we upgrade to 75

@slevithan
Copy link
Owner

slevithan commented Aug 21, 2024

Cool, thanks! I'd be very happy to see regex working in React Native 0.75.1+, but I have zero experience with RN so any and all help with identifying/reproducing issues would be super helpful. The prior version of Hermes (0.12.0) is from 2 years ago, so it probably makes sense to limit support to RN 0.75.1+.

Without knowing what error you ran into, another possibility for the source of the problem is that Hermes (or at least older versions of it) doesn't support some other modern JS feature, unrelated to regexes. In regex's source, I've tried to limit to JS features supported in Node.js 14 and 2020-era browsers, but this includes the use of features like private class properties, string matchAll, array flatMap, and the ?? and ?. operators.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants