String identity template tag

T.J. Crowder tj.crowder at
Thu Dec 13 18:37:17 UTC 2018

On Thu, Dec 13, 2018 at 5:56 PM Mark Miller
<erights at> wrote:
> I like String.cooked best. While I agree that method names should
> generally be verbs, I suggest this rule should *not* be used for
> template literal tag names.

Fair enough, but the primary use of this function is *not* using it as a
tag function, but rather as a normal function. It doesn't make sense to use
it as a tag function, the result is the same as an untagged template. The
only use case I could see for using it as a tag function is if you were
selecting from several tag functions at runtime and needed a "no-op" option.

But called normally, it's a useful helper, for instance in Isiah's `escape`
(where I assume the literal strings are already trusted, the substitutions
are not):

const escapeHTML = val => String(val).replace(/&/g, "&").replace(/</g,

const escape = (strings, ...subs) => {
    return *String.cook(strings,*);

const foo = "<script>alert('maliciousness!');<\/script>";
// => <p><script>alert('maliciousness!');</script></p>

I'm not that bothered either way, but I'd say it's a utility for tag
functions to use, not a tag function itself.

-- T.J. Crowder
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list