Quasi-literals for templating?

Gavin Barraclough barraclough at apple.com
Mon Jun 13 15:53:30 PDT 2011

On Jun 12, 2011, at 4:35 AM, Axel Rauschmayer wrote:

> BTW: “Desugaring” at the beginning of “Semantics” seems mangled.

I was just about to hit send an email saying the same thing!

Also, the section on the default quasi tag the name expandedLP is used, where I think this should be unescapedLP?

On this topic, rawLP and unescapedLP seem to be poor names.  'LP' seems to be meaningless line noise to developers using the feature who are not familiar with the grammar in the spec (and should not need to be).  Maybe these could just raw & unescaped? - or rawLiterals/rawLiteralPortion/etc for something more verbose?

> Has that been considered as a use case (e.g. after a compilation/generation step?). But it doesn’t seem like identifier names are accessible to quasi handlers, which would make this difficult.

This too!  Given the example for the proposal:

	msg`Welcome to ${siteName}, you are visitor number ${visitorNumber}!`

It would seem useful if the same quasi could handle both of these formatting tasks:

	msg`Welcome to ${siteName}, you are visitor number ${visitorNumber}!`
	msg`Welcome, you are visitor number ${visitorNumber} to ${siteName}!`

And it seems the identifiers could help.  Presumably the identifier names could be stored in a new frozen array on the call site specific object?  Might it also be useful to provide a mechanism to override the identifier with something clearer, for example, if the visitor number were being read from the property 'obj().x',

	msg`Welcome to ${siteName}, you are visitor number ${visitorNumber: obj().x}!`

Also, what is the 'this' object passed to the quasi handler? - might it make sense for 'this' to be the site specific object, rather than the passing this as an argument? - this seems to make some logical sense, and makes the arguments passed to function simpler to comprehend - they are all the substitution values, and arguments.length now matches the number of substitutions, indexed from zero, rather than being arguments length - 1.  E.g. the first example in the proposal:
// hoisted declaration.
const callSiteId1234 = {
    rawLP: ['quasiLiteralPart1 ', ' quasiLiteralPart2'],
    unescapedLP: ['quasiLiteralPart1 ', ' quasiLiteralPart2']

// in-situ
quasiHandlerName(callSiteId1234, quasiSubstitution)
would instead call:
// in-situ
quasiHandlerName.call(callSiteId1234, quasiSubstitution)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110613/0f8a6c74/attachment-0001.html>

More information about the es-discuss mailing list