1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:57:44 +00:00

LibJS: Allow invalid string in tagged template literals

Since tagged template literals can inspect the raw string it is not a
syntax error to have invalid escapes. However the cooked value should be
`undefined`.
We accomplish this by tracking whether parse_string_literal
fails and then using a NullLiteral (since UndefinedLiteral is not a
thing) and finally converting null in tagged template execution to
undefined.
This commit is contained in:
davidot 2022-08-17 02:04:27 +02:00 committed by Linus Groh
parent 0f9434a02c
commit e5adc51e27
5 changed files with 67 additions and 8 deletions

View file

@ -63,3 +63,9 @@ test("line continuation in literals (not characters)", () => {
test("reference error from expressions", () => {
expect(() => `${b}`).toThrowWithMessage(ReferenceError, "'b' is not defined");
});
test("invalid escapes should give syntax error", () => {
expect("`\\u`").not.toEval();
expect("`\\01`").not.toEval();
expect("`\\u{10FFFFF}`").not.toEval();
});