StefanTerdell / zod-to-json-schema

Converts Zod schemas to Json schemas
ISC License
854 stars 67 forks source link

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

Closed Albert-Gao closed 1 month ago

Albert-Gao commented 1 month ago

Bug Description

a regexp from this lib triggers this error on Hermes(React native).

// node_modules/zod-to-json-schema/dist/cjs/parsers/string.js
exports.zodPatterns = {
  // remove other codes
  emoji: RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u"),
};

image

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

It seems to be a Herms issue according to this: https://github.com/facebook/hermes/issues/1027 So I first created an issue on the Hermes side: https://github.com/facebook/hermes/issues/1460 But if it is really hard to solve on the engine side, I wonder is there a way we can tweak this regexp to make it compatible with Hermes?

Albert-Gao commented 1 month ago

seems it will be solved in the future version of Hermes, so close this one :)

StefanTerdell commented 1 month ago

@Albert-Gao This is now avoided with lazy-loading. Released in 3.23.2.

Albert-Gao commented 1 month ago

@StefanTerdell thanks, i tested, works like a charm with Hermes now :)