Quasi-literals for templating?

Brendan Eich brendan at mozilla.com
Wed Jun 15 21:54:34 PDT 2011


On Jun 15, 2011, at 9:51 PM, Brendan Eich wrote:

> My two cents: Ruby (with #{...} in its interpolated quasi-literal strings) and other languages allow pretty arbitrary expressions. The lexical issues are not insuperable. We are not really playing it "safe" by making narrow restrictions (such as Identifier expression only, or dotted identifier member expression only), so much as simplifying our spec work. Not even the drafting, which IIRC Mike already did. Rather, the validation that we would need to do.
> 
> I think we should step up, validate MIke's work, and formalize it fully. I thereby summon Waldemar. ;-)

Forgot to say that if we don't, then JS hackers can use let to hoist expressions into initializers of local bindings whose identifiers are used as substitutions, but they will rightly curse us. The needs of the many outweigh the needs of the few on TC39....

/be


> 
> /be
> 
> 
> On Jun 15, 2011, at 6:04 PM, Axel Rauschmayer wrote:
> 
>> With a let-block it’s probably not a deal breaker, but it seems like a shame that this is necessary for such a frequent use case.
>> 
>> It might be worth it to ask someone who has written a templating engine.
>> 
>> On Jun 16, 2011, at 2:41 , Mark S. Miller wrote:
>> 
>>> 
>>> 
>>> On Wed, Jun 15, 2011 at 5:36 PM, Allen Wirfs-Brock <allen at wirfs-brock.com> wrote:
>>> 
>>> On Jun 15, 2011, at 4:43 PM, Mark S. Miller wrote:
>>> 
>>>> 
>>>> 
>>>> On Wed, Jun 15, 2011 at 4:42 PM, Axel Rauschmayer <axel at rauschma.de> wrote:
>>>> Ah, very clever. It’d be nice to have an example of using this to compile templates (like jQuery templates). Maybe not even the implementation, just a quasi literal and why it works.
>>>> 
>>>> var myTmpl = tmpl`Dear ${{first}} ${{last}}`; // (*)
>>>> alert(myTempl.render({ first: "Jane", last: "Doe" }));
>>>> 
>>>> The handler (at (*)) is called like this:
>>>> tmpl(callSiteId73654, { first: undefined }, { last: undefined });
>>>> 
>>>> BTW: won’t it be a problem (for this use case) if the variables first and last don’t exist?
>>>> 
>>>> It would indeed be a problem. How much does this matter?
>>> 
>>> In ES.next unresolved resolved references to lexical bindings are early errors.  {first}  is equivalent to {first: first} so the RHS reference to first is a lexically bound unresolved reference that would produce an early error before the code ever ran.
>>> 
>>> I understand that. I'm asking how much of a problem is it if, in order to use the pattern in question, you had to define the variables first?
>>> 
>>>  
>>> 
>>> Allen
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> -- 
>>>     Cheers,
>>>     --MarkM
>> 
>> -- 
>> Dr. Axel Rauschmayer
>> 
>> axel at rauschma.de
>> twitter.com/rauschma
>> 
>> home: rauschma.de
>> blog: 2ality.com
>> 
>> 
>> 
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org
>> https://mail.mozilla.org/listinfo/es-discuss
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110615/5d83fe23/attachment.html>


More information about the es-discuss mailing list