1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-15 13:37:35 +00:00
serenity/Userland/Libraries/LibJS/Tests/unicode-identifier-escape.js
Timothy Flynn 1259dc3623 LibJS: Allow Unicode escape sequences in identifiers
For example, "property.br\u{64}wn" should resolve to "property.brown".

To support this behavior, this commit changes the Token class to hold
both the evaluated identifier name and a view into the original source
for the unevaluated name. There are some contexts in which identifiers
are not allowed to contain Unicode escape sequences; for example, export
statements of the form "export {} from foo.js" forbid escapes in the
identifier "from".

The test file is added to .prettierignore because prettier will replace
all escaped Unicode sequences with their unescaped value.
2021-08-19 23:49:25 +02:00

19 lines
585 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

test("basic escapes", () => {
var foo = {};
foo.brown = 12389;
expect(foo.brown).toBe(12389);
expect(foo.br\u006fwn).toBe(12389);
expect(foo.br\u{6f}wn).toBe(12389);
expect(foo.\u{62}\u{72}\u{6f}\u{77}\u{6e}).toBe(12389);
});
test("non-ascii escapes", () => {
var foo = {};
foo.𝓑𝓻𝓸𝔀𝓷 = 12389;
expect(foo.𝓑𝓻𝓸𝔀𝓷).toBe(12389);
expect(foo.𝓑𝓻\ud835\udcf8𝔀𝓷).toBe(12389);
expect(foo.𝓑𝓻\u{1d4f8}𝔀𝓷).toBe(12389);
expect(foo.\u{1d4d1}\u{1d4fb}\u{1d4f8}\u{1d500}\u{1d4f7}).toBe(12389);
});