Parent: #459
Problem
Every RegExp pattern defect collapses to one constant. JavaScriptCore prefixes
Invalid regular expression: and names the reason — 12 distinct reasons observed in an
18-case differential.
| pattern | zig-js | JavaScriptCore |
|---|---|---|
/(/ | invalid regular expression | Invalid regular expression: missing ) |
/[a/ | invalid regular expression | Invalid regular expression: missing terminating ] for character class |
/a{2,1}/ | invalid regular expression | Invalid regular expression: numbers out of order in {} quantifier |
/*/ | invalid regular expression | Invalid regular expression: nothing to repeat |
/a\\/ | invalid regular expression | Invalid regular expression: \ at end of pattern |
/(?<1>a)/ | invalid regular expression | Invalid regular expression: invalid group specifier name |
/[z-a]/ | invalid regular expression | Invalid regular expression: range out of order in character class |
Other observed reasons: duplicate group specifier name, invalid \k<> named
backreference, invalid property expression, invalid escaped character for Unicode
pattern, invalid range in character class for Unicode pattern, invalid Unicode code
point \u{} escape.
Flags are a separate constant, and JSC uses one string for all of them — unknown flag,
duplicate flag, and the u+v conflict alike:
zig-js: SyntaxError: Invalid regular expression flags
JavaScriptCore: SyntaxError: Invalid flags supplied to RegExp constructor.Note the trailing period, which zig-js's version lacks.
Why this one is structural
Unlike the Intl case, this is not a string table. The reason is lost at a module
boundary: zig-regex's compile error is flattened to a single value before zig-js sees
it. The dependency has to carry a reason discriminant across the boundary — which makes
this a change in ../zig-regex as well as in zig-js.
The same flattened message is reached through RegExp.prototype.compile as well as the
constructor and literals, so the mapping belongs at the compile-error boundary, not at
any one caller.
Verification
scratchpad/sweep/probe.sh, against a real JavaScriptCore backend. Note a regex literal
with a bad pattern is a parse-time error, so probe those through eval or the RegExp
constructor to keep them catchable.