Skip to content

Starling JS parser: valid regex Unicode property escapes (\p{Mark}) are rejected — whole scripts fail to parse #74

Description

@codymullins

A regex literal using a valid Unicode property escape such as /\p{Mark}/u fails to parse with invalid regular expression: Unsupported Unicode property: Mark. One bad regex kills the whole script: x.com's bundle.Communities.16ac38ba.js fails to parse entirely, so none of its webpack modules register, and any module that requires into it dies mid-evaluation (Cannot read properties of undefined (reading 'call')). Webpack caches the half-evaluated module, which later resurfaces as a confusing Cannot access a lexical binding before initialization ReferenceError from an export getter — observed on every x.com load.

What happens

The Starling JS parser eagerly validates every regex literal at parse time: ValidateRegExpLiteral (src/Starling.Js/Parse/JsParser.cs:1329-1342) compiles the pattern through the Starling RegExp engine and converts any syntax failure into a parse-phase error. That eager validation is spec-correct — an invalid regex literal is an early SyntaxError in ECMAScript.

The actual bug is that the Starling RegExp engine's property support is a small whitelist. RegexParser.ParsePropertyEscape (src/Starling.RegExp/RegexParser.cs:595-615, throw at 610) accepts only the names in RegexCharClass.SupportedProperties (src/Starling.RegExp/RegexCharClass.cs:103-116): Letter, Number, Decimal_Number, White_Space, Punctuation, Symbol, Uppercase_Letter, Lowercase_Letter, ID_Start, ID_Continue, and their short aliases. Mark/M and most of the spec's required properties are missing, so a perfectly valid pattern is treated as a syntax error and takes the whole file down with it.

Two more gaps in the same code:

  • ParsePropertyEscape ignores the property name in Name=Value form (it keeps only the value), so \p{Script=Greek} and \p{General_Category=L} are conflated.
  • BuildPropertyRanges (RegexCharClass.cs:120+) scans code points only up to 0xFFFF, so even supported properties miss astral-plane characters.

Fix

Real fix: extend the Starling RegExp engine to the ECMAScript \p{...} surface:

  • all General_Category values and aliases (Mark/M, Mn, Mc, Me, Cf, and the rest), accepting both bare-value and General_Category=Value forms
  • the spec's required binary properties (Alphabetic, White_Space, Assigned, and so on), adding to the existing table approach
  • Script= / Script_Extensions= handled as their own namespace instead of being conflated with category names
  • property ranges built over the full code-point space, not just the BMP

.NET's System.Globalization.UnicodeCategory and CharUnicodeInfo can generate the category ranges, so most of this is table plumbing, not algorithm work.

Not a fix: moving validation from parse time to construction time. Eager parse-phase SyntaxError is what the spec requires for genuinely invalid literals. The whitelist being too small is the defect.

Context

Found during the x.com/nasa boot investigation on 2026-06-10 (branch feat/js-stack-trampoline). Verified against the real chunk with the exact message above. Same blast-radius pattern as two sibling parser issues (template-substitution comma, parenthesized in): one parse error silently kills every webpack module in a chunk and produces misleading downstream errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    browserRelates to the browser subsystembugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions