1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 04:08:11 +00:00

LibJS: Add raw strings to tagged template literals

When calling a function with a tagged template, the first array that is
passed in now contains a "raw" property with the raw, escaped strings.
This commit is contained in:
Matthew Olsson 2020-05-06 16:34:14 -07:00 committed by Andreas Kling
parent 9d0c6a32bd
commit b5f1df57ed
5 changed files with 52 additions and 9 deletions

View file

@ -1347,6 +1347,16 @@ Value TaggedTemplateLiteral::execute(Interpreter& interpreter) const
else
arguments.append(value);
}
auto* raw_strings = Array::create(interpreter.global_object());
for (auto& raw_string : m_template_literal->raw_strings()) {
auto value = raw_string.execute(interpreter);
if (interpreter.exception())
return {};
raw_strings->elements().append(value);
}
strings->put("raw", raw_strings, 0);
return interpreter.call(tag_function, js_undefined(), move(arguments));
}