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

fails on regular expressions with Unicode property escapes #177

Open
cataggar opened this issue Dec 31, 2024 · 2 comments
Open

fails on regular expressions with Unicode property escapes #177

cataggar opened this issue Dec 31, 2024 · 2 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@cataggar
Copy link
Contributor

cataggar commented Dec 31, 2024

I am trying to wrap typespec into a component. It pulls in change-case library which uses regular expressions with Unicode. componetize is failing on these regular expressions:

var SPLIT_LOWER_UPPER_RE = /([\p{Ll}\d])(\p{Lu})/gu;
var SPLIT_UPPER_UPPER_RE = /(\p{Lu})([\p{Lu}][\p{Ll}])/gu;
var SPLIT_SEPARATE_NUMBER_RE = /(\d)\p{Ll}|(\p{L})\d/u;
var DEFAULT_STRIP_REGEXP = /[^\p{L}\d]+/giu;

The code is from here:
node_modules/.pnpm/[email protected]/node_modules/change-case/dist/index.js
https://www.npmjs.com/package/change-case
https://github.com/blakeembrey/change-case/blob/main/packages/change-case/src/index.ts

$ bunx jco componentize world.js --wit wit -o ts-typescript.wasm -d clocks -d random -d http

Exception while evaluating top-level script
world.js:31083:32 SyntaxError: invalid class property name in regular expression:
world.js:31083:32 ([\p{Ll}\d])(\p{Lu})
world.js:31083:32 ....^
Error: the `componentize.wizer` function trapped

Caused by:
    0: error while executing at wasm backtrace:
           0: 0x79597a - <unknown>!<wasm function 12739>
           1: 0x7962ed - <unknown>!<wasm function 12755>
           2: 0x20646 - <unknown>!<wasm function 98>
           3: 0x1f5f9 - <unknown>!<wasm function 96>
           4: 0xa6a5 - <unknown>!<wasm function 78>
           5: 0x22acba - <unknown>!<wasm function 5037>
    1: Exited with i32 exit status 1
Error: Failed to initialize the compiled Wasm binary with Wizer:
Wizering failed to complete
    at componentize (file:///Users/cataggar/ms/ComponentizeJS/src/componentize.js:305:13)
    at async componentize (file:///Users/cataggar/ms/jco/src/cmd/componentize.js:11:25)
    at async file:///Users/cataggar/ms/jco/src/jco.js:213:9
error: script "componentize" exited with code 1
(jco componentize) 
In 'typescript' script 'componentize' failed with exit code 1

Copilot says:

SpiderMonkey, the JavaScript and WebAssembly engine used in Mozilla Firefox, supports Unicode property escapes as part of the ECMAScript 2018 (ES9) specification. This feature allows you to use Unicode property escapes in regular expressions to match characters based on their Unicode properties.

Enabling Unicode Property Escapes in SpiderMonkey

To ensure that SpiderMonkey is compiled with support for Unicode property escapes, you need to use a version of SpiderMonkey that supports ECMAScript 2018 or later. Most modern versions of SpiderMonkey, including those used in recent versions of Firefox, already include this support.

@cataggar
Copy link
Contributor Author

My temporary hack is get past the error was to have it use ASCII regular expressions.

var SPLIT_LOWER_UPPER_RE = /([a-z\d])([A-Z])/g;
var SPLIT_UPPER_UPPER_RE = /([A-Z])([A-Z][a-z])/g;
var SPLIT_SEPARATE_NUMBER_RE = /(\d)[a-z]|([a-zA-Z])\d/g;
var DEFAULT_STRIP_REGEXP = /[^a-zA-Z\d]+/g;

@guybedford guybedford added the bug Something isn't working label Jan 2, 2025
@guybedford
Copy link
Collaborator

Thanks for bringing this up, your workaround is roughly the right sort of approach. Posted an upstream issue in bytecodealliance/StarlingMonkey#192.

In the meantime we could inline an approach similar to Fastly's in ComponentizeJS specifically, based on the code here - https://github.com/fastly/js-compute-runtime/blob/main/src/precompile.js. Should be an easy PR.

@guybedford guybedford added the good first issue Good for newcomers label Jan 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants