1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 18:28:12 +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

@ -3545,6 +3545,11 @@ Completion TaggedTemplateLiteral::execute(Interpreter& interpreter, GlobalObject
// tag`${foo}` -> "", foo, "" -> tag(["", ""], foo)
// tag`foo${bar}baz${qux}` -> "foo", bar, "baz", qux, "" -> tag(["foo", "baz", ""], bar, qux)
if (i % 2 == 0) {
// If the string contains invalid escapes we get a null expression here, which we then convert
// to the expected `undefined` TV.
if (value.is_nullish())
value = js_undefined();
strings->indexed_properties().append(value);
} else {
arguments.append(value);