Getting the full text of Quasi Literals

# Erik Arvidsson (14 years ago)

With the current proposal it is not possible to get the raw string, including the place holders and everything.

One possible use case: It is often common to want to have the textual content of an expression to provide better output for unit testing. Today, this is often done using global evals which requires global variables everywhere.

For example we could add an expressions property to the parameter.

testa $b c ${d} e

could be desugared t to something like:

const unguessableCallSiteId1234 = Object.freeze({ raw: Object.freeze(["a ", " c ", " e"]), cooked: Object.freeze(["a ", " c ", " e"]), expressions: Object.freeze(["$b", "${d}"]) });

test(unguessableCallSiteId1234)

# Mark S. Miller (14 years ago)

I think it is important not to provide the source text of the hole expressions to the quasi parser, for the same reason that we shouldn't provide the source text of the rest of the enclosing file. The output of the quasi parser should depend only on its legitimate inputs, which are the quasi strings and the values of the hole expressions, not their sources. If you provide the sources as well, then source to source transformations which should otherwise be correctness preserving would no longer be.

OTOH, we already have this problem with Function.prototype.toString. People do source to source transformations anyway. An earlier version of the quasis proposal implicitly thunkified the hold expressions, in which case Function.prototype.toString would have provided the holes anyway. So I don't suppose this is any worse.

+1-1 = 0, i.e., I don't know if I'm in favor or not.