diff --git a/src/__tests__/transform.test.ts b/src/__tests__/transform.test.ts index 558aa2f..763bb45 100644 --- a/src/__tests__/transform.test.ts +++ b/src/__tests__/transform.test.ts @@ -9,12 +9,12 @@ describe(transform, () => { const testHooks: Hook[] = [new TestHook(/foo/), new TestHook(/bar/)]; const transforms = testHooks.map((t) => jest.spyOn(t, "transform")); - expect(transform("'hello'", new URL("file:///foo"), testHooks)).toBe('"hello";\n"/foo/";\n'); + expect(transform("'hello'", new URL("file:///foo"), testHooks)).toBe("'hello';\n\"/foo/\";\n"); expect(transforms[0]).toBeCalled(); expect(transforms[1]).not.toBeCalled(); transforms[0].mockReset(); - expect(transform("'hello'", new URL("file:///bar"), testHooks)).toBe('"hello";\n"/bar/";\n'); + expect(transform("'hello'", new URL("file:///bar"), testHooks)).toBe("'hello';\n\"/bar/\";\n"); expect(transforms[0]).not.toBeCalled(); expect(transforms[1]).toBeCalled(); transforms[1].mockReset(); @@ -40,8 +40,23 @@ describe(transform, () => { expect(jest.mocked(warn).mock.calls).toMatchSnapshot(); }); + + 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); + }); }); +class IdentityHook implements Hook { + shouldInstrument(): boolean { + return true; + } + transform(program: ESTree.Program): ESTree.Program { + return program; + } +} + class TestHook implements Hook { constructor(public pattern: RegExp) {} diff --git a/src/transform.ts b/src/transform.ts index afb991b..8987334 100644 --- a/src/transform.ts +++ b/src/transform.ts @@ -84,6 +84,7 @@ export default function transform(code: string, url: URL, hooks = defaultHooks): loc: true, module: true, onComment: comments, + raw: true, }); const xformed = hook.transform(tree, getSourceMap_(), comments);