The main issue with it is, because of how you write it, you can’t really do anything useful with it. For instance, you can’t run a “compile()”’d template through a tag function — you can’t use useful expressions in template expressions, and in the current design there’s no real way around that, unless you’re willing to use `eval()` or `new Function()` to accomplish it.
> On Dec 16, 2014, at 12:55 PM, Alex Kocharin <[email protected]> wrote: > > > > 16.12.2014, 20:44, "Caitlin Potter" <[email protected]>: >> The compile() tag wouldn’t work the way tagged templates are currently. The >> `args` array would be initialized at compile()-time, and those same >> arguments would always be used no matter what you’d passed in to the >> returned function. > > That's funny, because my code works already in the FireFox 34. Pay attention > to WHAT exactly is passed to the compile function. :) > > >> >> >> It would be cool if there were some sugar for this, but I don’t think tagged >> templates will get you there. Worse than that, you’d ideally be able to run >> “compiled” templates through tag functions (e.g. for markup sanitization), >> and it’s not clear how you’d do that from this. Maybe a new builtin like >> global.Template, maybe Reflect.compileTemplate, which would accept a >> template string as input (this wouldn’t really make sense unless it were >> somehow a “magic” function which processed templates differently though :() >> >>> On Dec 16, 2014, at 12:30 PM, Alex Kocharin <[email protected] >>> <mailto:[email protected]>> wrote: >>> >>> >>> I think ES6 is more awesome than people usually realize. Oh by the way, >>> here is some sugar: >>> >>> var template = compile`Hello, ${"name"}!` >>> console.log(template({ name: "world" })) >>> >>> >>> >>> Of course, ES6 does not have a compile function built-in, but I surely have >>> one: >>> >>> function compile(strs, ...args) { >>> return function(object) { >>> var chunks = [] >>> for (var i=0; i<strs.length-1; i++) { >>> chunks.push(strs[i]) >>> chunks.push(object[args[i]]) >>> } >>> chunks.push(strs[i]) >>> return chunks.join('') >>> } >>> } >>> >>> >>> >>> 16.12.2014, 20:03, "Claude Pache" <[email protected] >>> <mailto:[email protected]>>: >>>> >>>>> Le 16 déc. 2014 à 16:42, Matthew Robb <[email protected] >>>>> <mailto:[email protected]>> a écrit : >>>>> >>>>> Actually, it would be cool if some sugar could be done for the example I >>>>> just did: >>>>> >>>>> var template = compile` >>>>> Hello ${{first_name}} >>>>> `; >>>>> >>>>> template({ first_name: "John" }); >>>>> >>>> >>>> I guess you want sugar for the following valid ES6 code? >>>> >>>> >>>> ```javascript >>>> >>>> var template = _ => ` >>>> Hello ${_.first_name} >>>> `; >>>> >>>> template({ first_name: "John" }); >>>> >>>> ``` >>>> >>>> —Claude >>>> >>>> , >>>> _______________________________________________ >>>> es-discuss mailing list >>>> [email protected] <mailto:[email protected]> >>>> https://mail.mozilla.org/listinfo/es-discuss >>>> <https://mail.mozilla.org/listinfo/es-discuss>_______________________________________________ >>> es-discuss mailing list >>> [email protected] <mailto:[email protected]> >>> https://mail.mozilla.org/listinfo/es-discuss >>> <https://mail.mozilla.org/listinfo/es-discuss>
_______________________________________________ es-discuss mailing list [email protected] https://mail.mozilla.org/listinfo/es-discuss

