Skip to content

fix(compat): decode character references in JSX text and attribute values, as @tsrx/core 0.5.2 does - #144

Merged
thejackshelton merged 1 commit into
mainfrom
feat/decode-jsx-references
Sep 29, 2026
Merged

thejackshelton merged 1 commit into
mainfrom
feat/decode-jsx-references

Conversation

@thejackshelton

@thejackshelton thejackshelton commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #111.

In tsrx-core-compat, every JSXText and every string JSXAttribute now gets the same value and raw that @tsrx/core 0.5.2 gives it:

  • value has its character references decoded the way acorn-typescript's jsx_readEntity decodes them: a name from acorn-jsx's XHTML table, or &#…; / &#x…; / &#X…; up to U+10FFFF. It reads at most 10 characters after the &. Anything else stays as written: &bogus;, ✓, &amp with no ;, �, a bare &.
  • raw stays as written.
  • Line breaks. In text, value reads CRLF as LF and raw keeps the CRLF. An attribute's value keeps CRLF, as core's does.
  • Text split by a child or a comment is decoded one piece at a time, so a reference cut off by a comment stays text.
  • Strings inside expression containers are not decoded.

The decoding runs in the facade's existing final walk (materializeCompatibilityProgram), and it is skipped when the source has no & and no \r. The Rust engine and the native parser, lint, format and printer output are unchanged. A test checks that the native parser still gives JSX strings as written.

Verification. I compared against @tsrx/[email protected], looking at value and raw for every JSX text and string attribute:

Input Cases Match
Templates, function and module-level JSX, CRLF, comments, cut-off references, the 10-character limit 70 70
The same 70 cases as .tsx 70 70
Fuzzed sources 3,000 3,000

I added eight tests to tests/parser-api/core-conformance.test.mjs, using core 0.5.2's values. The helper in the #118 test used to assert that raw === value. It now reports raw, because a text's value is decoded now.

Note. As the issue says, Octane decodes these values itself until it reads them from raw (octanejs/octane#1399, octanejs/octane#1330). Until those land, Octane's Node output decodes them twice.

🤖 Generated with Claude Code


Note

Medium Risk
Post-parse AST mutation in the compat facade affects all consumers of decoded JSX value fields; behavior is gated on source content but mismatches with downstream double-decode (e.g. Octane) remain a integration risk.

Overview
Fixes #111 by aligning tsrx-core-compat with @tsrx/core 0.5.2 for JSX string handling: decoded value, unchanged raw.

During materializeCompatibilityProgram, when the source contains & or \r, the facade walks JSXText and string JSXAttribute nodes and decodes character references using acorn-jsx’s XHTML table and acorn-typescript-style rules (&#…;, &#x…;, 10-character limit, invalid refs left as text). JSX text also normalizes CRLF to LF in value; attributes keep CRLF. Expression-container strings are untouched. The native/Rust parser path is unchanged; bundled dist outputs mirror the source.

Tests: eight #111 cases in core-conformance.test.mjs; the #118 children helper now reports raw instead of assuming raw === value.

Reviewed by Cursor Bugbot for commit 52c0586. Bugbot is set up for automated code reviews on this repo. Configure here.

@vercel

vercel Bot commented Sep 29, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
tsrx-website-oxc Ready Ready Preview Sep 29, 2026 8:30pm UTC

Request Review

This branch was successfully deployed

1 active deployment
Preview — 52c05866 Deployed Sep 29, 2026 by vercel[bot]
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

Successfully merging this pull request may close these issues.

Character references in JSX attribute strings aren't decoded into value, and text will need the same after tsrx-org/tsrx#710

1 participant