Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 17 additions & 2 deletions src/__tests__/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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) {}

Expand Down
1 change: 1 addition & 0 deletions src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down