You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(codegen-js): emit \uXXXX/\u{X} for non-ASCII (closes#460)
OCaml's `String.escaped` emits non-ASCII bytes as `\NNN` *decimal*
sequences. JavaScript parses `\NNN` as *octal* escapes which strict-mode
ESM rejects outright (`SyntaxError: Octal escape sequences are not
allowed in strict mode`), and which would decode to wrong characters
even outside strict mode.
Adds `Js_codegen.js_string_lit` that walks the UTF-8 byte sequence,
decodes code points, and emits `\uXXXX` (BMP) or `\u{XXXXX}` (non-BMP)
Unicode escapes. ASCII printable bytes pass through unchanged; `\\` `\"`
`\n` `\r` `\t` use conventional escapes; ASCII control bytes use
`\xHH`. Wired into both `js_codegen.ml` (Node target) and
`codegen_deno.ml` (Deno-ESM target) LitString/LitChar emit sites.
Regression fixture `tests/codegen-deno/non_ascii.affine` + harness
exercise BMP emoji (❌ ✓), CJK (你好), Latin accents (café résumé),
non-BMP code points (😭 = U+1F62D), mixed strings, and the
existing-escape regression path (\\ and \"). Pre-fix: harness
`import` itself fails with SyntaxError. Post-fix: 8/8 assertions pass.
Verified: full `tools/run_codegen_deno_tests.sh` (13/13 harnesses
green); full `dune test` suite (352/352 green).
Closes#460
Refs hyperpolymath/standards#284 (the seam-analyst PR that surfaced
this)
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments