1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:17:36 +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

@ -82,6 +82,18 @@ try {
var rating = "great";
assert(review`${name} is a ${rating} project!` === "**SerenityOS** is a _great_ project!");
const getTemplateObject = (...rest) => rest;
const getRawTemplateStrings = arr => arr.raw;
let o = getTemplateObject`foo\nbar`;
assert(Object.getOwnPropertyNames(o[0]).includes('raw'));
let raw = getRawTemplateStrings`foo${1 + 3}\nbar`;
assert(!Object.getOwnPropertyNames(raw).includes('raw'));
assert(raw.length === 2);
assert(raw[0] === 'foo');
assert(raw[1].length === 5 && raw[1] === '\\nbar');
console.log("PASS");
} catch (e) {
console.log("FAIL: " + e);