getappmap / appmap-node

AppMap client agent for Node.js
Other
9 stars 4 forks source link

fix: Preserve Unicode escape sequences in transformation #173

Open zermelo-wisen opened 1 month ago

zermelo-wisen commented 1 month ago

Fixes #172.

Ensures that Unicode escape sequences (e.g., "\u{1D306}") are correctly preserved during the code transformation process. This fix addresses an issue where certain escape sequences were incorrectly converted when parsing and regenerating code.

The fix gives raw: true option to the meriyah parse function in transform.ts.

 const tree = parse(code, {
   source: url.toString(),
   next: true,
   loc: true,
   module: true,
   onComment: comments,
   raw: true, // Added this line
 });

This test, which would fail without the fix, is added to transform.test.ts.

it("transforms unicode correctly", () => {
  const input = `const a = "\\u{1D306}";\n`;
  // Ensure that "\u{1D306}" is not converted to "t̆".
  expect(transform(input, new URL("file:///foo"), [new IdentityHook()])).toBe(input);
});