Add support for arbitrary code inside template tags without the 'do' keyword
Do-Expressions are still floating around Stage 0, there’s no guarantee that they will be incorporated into the language.
The feature is implemented in v8 behind a flag, and can be used in Chrome Canary by launching the browser with —js-flags=“—harmony-do-expressions”
, which would enable you to try it out.
INTERMISSION — Slightly more on-topic portion of post follows after a short coffee break
However, to answer your question, you can implement an immediately-invoked-function-expression, like this:
`Hello ${_ => {
if (a == 2) {
console.log(‘world’);
}
}()}`;
So this wouldn’t depend on the Do-Expressions proposal, and wouldn’t require a keyword per se, although you’d still have some extra tokens making things a bit harder to read.
It’s unlikely that the grammar would be changed to accommodate this use case, given that people are using template literals already, and the use-case is already supported by other means.
Do-Expressions are still floating around Stage 0, there’s no guarantee that they will be incorporated into the language. The feature is implemented in v8 behind a flag, and can be used in Chrome Canary by launching the browser with `—js-flags=“—harmony-do-expressions”`, which would enable you to try it out. **INTERMISSION — Slightly more on-topic portion of post follows after a short coffee break** However, to answer your question, you can implement an immediately-invoked-function-expression, like this: ```js `Hello ${_ => { if (a == 2) { console.log(‘world’); } }()}`; ``` So this wouldn’t depend on the Do-Expressions proposal, and wouldn’t require a keyword per se, although you’d still have some extra tokens making things a bit harder to read. It’s unlikely that the grammar would be changed to accommodate this use case, given that people are using template literals already, and the use-case is already supported by other means. > On Jan 10, 2016, at 9:23 PM, Manuel Di Iorio <xeryan at gmail.com> wrote: > > Hi, I asked around and somebody said that there will be the possibility to execute arbitrary code inside the template tags, using the 'do' keyword in this example way: > > `Hello ${ do if (a == 2) { > console.log(' world'); > } }` > > Is there the possibility in future to implement that feature without the keyword? > What is the plan (read 'estimated date') for the rollout of this feature ? > > The idea to develop in native way a good templating engine is exciting and I'm looking forward for its complete implementation :) > _______________________________________________ > 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/20160110/e848ff29/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 842 bytes Desc: Message signed with OpenPGP using GPGMail URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160110/e848ff29/attachment.sig>
Watch your precedence, Caitlin. You'll need to wrap that arrow in parentheses like so:
`Hello ${(_ => {
if (a == 2) {
console.log(‘world’);
}
})()}`;
Michael
Watch your precedence, Caitlin. You'll need to wrap that arrow in parentheses like so: ```js `Hello ${(_ => { if (a == 2) { console.log(‘world’); } })()}`; ``` Michael On Sun, Jan 10, 2016 at 7:12 PM, Caitlin Potter <caitpotter88 at gmail.com> wrote: > Do-Expressions are still floating around Stage 0, there’s no guarantee > that they will be incorporated into the language. > > The feature is implemented in v8 behind a flag, and can be used in Chrome > Canary by launching the browser with `—js-flags=“—harmony-do-expressions”`, > which would enable you to try it out. > > **INTERMISSION — Slightly more on-topic portion of post follows after a > short coffee break** > > However, to answer your question, you can implement an > immediately-invoked-function-expression, like this: > > ```js > `Hello ${_ => { > if (a == 2) { > console.log(‘world’); > } > }()}`; > ``` > > So this wouldn’t depend on the Do-Expressions proposal, and wouldn’t > require a keyword per se, although you’d still have some extra tokens > making things a bit harder to read. > > It’s unlikely that the grammar would be changed to accommodate this use > case, given that people are using template literals already, and the > use-case is already supported by other means. > > On Jan 10, 2016, at 9:23 PM, Manuel Di Iorio <xeryan at gmail.com> wrote: > > Hi, I asked around and somebody said that there will be the possibility to > execute arbitrary code inside the template tags, using the *'do'* keyword > in this example way: > > `Hello ${ do if (a == 2) { >> console.log(' world'); >> } }` > > > Is there the possibility in future to implement that feature without the > keyword? > What is the plan *(read 'estimated date')* for the rollout of this > feature ? > > The idea to develop in native way a good templating engine is exciting and > I'm looking forward for its complete implementation :) > _______________________________________________ > 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 > > -- Shape Security is hiring outstanding individuals. Check us out at *https://shapesecurity.com/jobs/ <https://shapesecurity.com/jobs/>* -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160110/c4f1e7e4/attachment-0001.html>
Thanks Caitlin for the workaround ;)
However, as you can note, to write the following is not that much praticable and readable:
${()=>{
//code here
}()}
At least, the *do *keyword will improve the situation with i.e:
${do {
//code here
}}
Hope to see news about the 'do' keyword adoption or something even better in the early future! :D
Thanks Caitlin for the workaround ;) However, as you can note, to write the following is not that much praticabile and readable: ${()=>{ //code here }()} At least, the *do *keyword will improve the situation with i.e: ${do { //code here }} PS: Is w/ or w/o the curly braces after the *do* keyword (?) Hope to see news about the 'do' keyword adoption or something even better in the early future! :D -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160111/907d5197/attachment.html>
If it's any consolation, you can currently use Babel (f.e with Webpack, Browserify, etc) to compile do-expressions (babeljs.io/docs/plugins/syntax-do-expressions), so you can use the syntax right now.
If it's any consolation, you can currently use Babel (f.e with Webpack, Browserify, etc) to compile do-expressions (babeljs.io/docs/plugins/syntax-do-expressions), so you can use the syntax right now. On Sun, Jan 10, 2016 at 11:07 PM, Manuel Di Iorio <xeryan at gmail.com> wrote: > Thanks Caitlin for the workaround ;) > > However, as you can note, to write the following is not that much > praticabile and readable: > > ${()=>{ > //code here > }()} > > At least, the do keyword will improve the situation with i.e: > > ${do { > //code here > }} > > PS: Is w/ or w/o the curly braces after the do keyword (?) > > > Hope to see news about the 'do' keyword adoption or something even better in > the early future! :D > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
Watch your precedence, Caitlin. You'll need to wrap that arrow in parentheses like so:
Yes, I guess arrow functions aren’t a PrimaryExpression — doesn’t really matter, though
> Watch your precedence, Caitlin. You'll need to wrap that arrow in parentheses like so: Yes, I guess arrow functions aren’t a PrimaryExpression — doesn’t really matter, though > On Jan 10, 2016, at 11:58 PM, Michael Ficarra <mficarra at shapesecurity.com> wrote: > > Watch your precedence, Caitlin. You'll need to wrap that arrow in parentheses like so: > > ```js > `Hello ${(_ => { > if (a == 2) { > console.log(‘world’); > } > })()}`; > ``` > > Michael > > On Sun, Jan 10, 2016 at 7:12 PM, Caitlin Potter <caitpotter88 at gmail.com <mailto:caitpotter88 at gmail.com>> wrote: > Do-Expressions are still floating around Stage 0, there’s no guarantee that they will be incorporated into the language. > > The feature is implemented in v8 behind a flag, and can be used in Chrome Canary by launching the browser with `—js-flags=“—harmony-do-expressions”`, which would enable you to try it out. > > **INTERMISSION — Slightly more on-topic portion of post follows after a short coffee break** > > However, to answer your question, you can implement an immediately-invoked-function-expression, like this: > > ```js > `Hello ${_ => { > if (a == 2) { > console.log(‘world’); > } > }()}`; > ``` > > So this wouldn’t depend on the Do-Expressions proposal, and wouldn’t require a keyword per se, although you’d still have some extra tokens making things a bit harder to read. > > It’s unlikely that the grammar would be changed to accommodate this use case, given that people are using template literals already, and the use-case is already supported by other means. > >> On Jan 10, 2016, at 9:23 PM, Manuel Di Iorio <xeryan at gmail.com <mailto:xeryan at gmail.com>> wrote: >> >> Hi, I asked around and somebody said that there will be the possibility to execute arbitrary code inside the template tags, using the 'do' keyword in this example way: >> >> `Hello ${ do if (a == 2) { >> console.log(' world'); >> } }` >> >> Is there the possibility in future to implement that feature without the keyword? >> What is the plan (read 'estimated date') for the rollout of this feature ? >> >> The idea to develop in native way a good templating engine is exciting and I'm looking forward for its complete implementation :) >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> >> https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org <mailto:es-discuss at mozilla.org> > https://mail.mozilla.org/listinfo/es-discuss <https://mail.mozilla.org/listinfo/es-discuss> > > > > > -- > Shape Security is hiring outstanding individuals. Check us out at https://shapesecurity.com/jobs/ <https://shapesecurity.com/jobs/> -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160111/f708b023/attachment.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 842 bytes Desc: Message signed with OpenPGP using GPGMail URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160111/f708b023/attachment.sig>
The idea to develop in native way a good templating engine is exciting
and I'm looking forward for its complete implementation :)
This topic arose in an earlier thread that I'm too lazy to track down. Some insane person from Microsoft? actually showed us how to write ifs and everything using horribly nested template strings.
Bottom line, template strings, with or without do
, which is both
unnecessary and would break everything, are not a good starting point for
writing a templating engine. I'd definitely take a different approach.
Bob
> The idea to develop in native way a good templating engine is exciting and I'm looking forward for its complete implementation :) This topic arose in an earlier thread that I'm too lazy to track down. Some insane person from Microsoft? actually showed us how to write ifs and everything using horribly nested template strings. Bottom line, template strings, with or without `do`, which is both unnecessary and would break everything, are not a good starting point for writing a templating engine. I'd definitely take a different approach. Bob On Mon, Jan 11, 2016 at 6:06 PM, Caitlin Potter <caitpotter88 at gmail.com> wrote: > > Watch your precedence, Caitlin. You'll need to wrap that arrow in > parentheses like so: > > Yes, I guess arrow functions aren’t a PrimaryExpression — doesn’t really > matter, though > > On Jan 10, 2016, at 11:58 PM, Michael Ficarra <mficarra at shapesecurity.com> > wrote: > > Watch your precedence, Caitlin. You'll need to wrap that arrow in > parentheses like so: > > ```js > `Hello ${(_ => { > if (a == 2) { > console.log(‘world’); > } > })()}`; > ``` > > Michael > > On Sun, Jan 10, 2016 at 7:12 PM, Caitlin Potter <caitpotter88 at gmail.com> > wrote: > >> Do-Expressions are still floating around Stage 0, there’s no guarantee >> that they will be incorporated into the language. >> >> The feature is implemented in v8 behind a flag, and can be used in Chrome >> Canary by launching the browser with `—js-flags=“—harmony-do-expressions”`, >> which would enable you to try it out. >> >> **INTERMISSION — Slightly more on-topic portion of post follows after a >> short coffee break** >> >> However, to answer your question, you can implement an >> immediately-invoked-function-expression, like this: >> >> ```js >> `Hello ${_ => { >> if (a == 2) { >> console.log(‘world’); >> } >> }()}`; >> ``` >> >> So this wouldn’t depend on the Do-Expressions proposal, and wouldn’t >> require a keyword per se, although you’d still have some extra tokens >> making things a bit harder to read. >> >> It’s unlikely that the grammar would be changed to accommodate this use >> case, given that people are using template literals already, and the >> use-case is already supported by other means. >> >> On Jan 10, 2016, at 9:23 PM, Manuel Di Iorio <xeryan at gmail.com> wrote: >> >> Hi, I asked around and somebody said that there will be the possibility >> to execute arbitrary code inside the template tags, using the *'do'* >> keyword in this example way: >> >> `Hello ${ do if (a == 2) { >>> console.log(' world'); >>> } }` >> >> >> Is there the possibility in future to implement that feature without the >> keyword? >> What is the plan *(read 'estimated date')* for the rollout of this >> feature ? >> >> The idea to develop in native way a good templating engine is exciting >> and I'm looking forward for its complete implementation :) >> _______________________________________________ >> 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 >> >> > > > -- > Shape Security is hiring outstanding individuals. Check us out at *https://shapesecurity.com/jobs/ > <https://shapesecurity.com/jobs/>* > > > > _______________________________________________ > 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/20160111/f0c7660a/attachment-0001.html>
Yes Bob, after a personal testing with a complete template engine using the ES6 template strings, I realized that their use (in my use case, of course) is slowest than the approach that I'm using right now (like the Underscore template). Thanks everyone :)
Yes Bob, after a personal testing with a complete template engine using the ES6 template strings, I realized that their use (in mine use case, of course) is slowest than the approach that I'm using right now (like the Underscore template). Thanks everyone :) -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160111/b26d8454/attachment.html>
The thing with template strings is that they are used at runtime. This could be slow if we're compiling things at runtime all the time, whereas a server-side templating solution might lead JavaScript functions compiled from templates (like in the case with Meteor Blaze Spacebars or React JSX), which can be faster at runtime.
What are template strings good for besides the obvious benefit that they make things like
var str = "llo"
console.log(`he${str} world!`)
easier to read than
var str = "llo"
console.log('he'+'str'+' world!')
?
Maybe writing regexes can be nicer with template strings? I gave it a try at npmjs.com/regexr.
The thing with template strings is that they are used at runtime. This could be slow if we're compiling things at runtime all the time, whereas a server-side templating solution might lead JavaScript functions compiled from templates (like in the case with Meteor Blaze Spacebars or React JSX), which can be faster at runtime. What are template strings good for besides the obvious benefit that they make things like ``` var str = "llo" console.log(`he${str} world!`) ``` easier to read than ``` var str = "llo" console.log('he'+'str'+' world!') ``` ? Maybe writing regexes can be nicer with template strings? I gave it a try at npmjs.com/regexr. On Mon, Jan 11, 2016 at 8:43 AM, Manuel Di Iorio <xeryan at gmail.com> wrote: > Yes Bob, after a personal testing with a complete template engine using the > ES6 template strings, I realized that their use (in mine use case, of > course) is slowest than the approach that I'm using right now (like the > Underscore template). Thanks everyone :) > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org > https://mail.mozilla.org/listinfo/es-discuss >
The two code samples you posted are equivalent (modulo the obvious mistake). AFAIU there is still only a single parsing pass for template strings.
The two code samples you posted are equivalent (modulo the obvious mistake). AFAIU there is still only a single parsing pass for template strings. On Tuesday, 12 January 2016, /#!/JoePea <joe at trusktr.io> wrote: > The thing with template strings is that they are used at runtime. This > could be slow if we're compiling things at runtime all the time, > whereas a server-side templating solution might lead JavaScript > functions compiled from templates (like in the case with Meteor Blaze > Spacebars or React JSX), which can be faster at runtime. > > What are template strings good for besides the obvious benefit that > they make things like > > ``` > var str = "llo" > console.log(`he${str} world!`) > ``` > > easier to read than > > ``` > var str = "llo" > console.log('he'+'str'+' world!') > ``` > > ? > > Maybe writing regexes can be nicer with template strings? I gave it a > try at npmjs.com/regexr. > > On Mon, Jan 11, 2016 at 8:43 AM, Manuel Di Iorio <xeryan at gmail.com > <javascript:;>> wrote: > > Yes Bob, after a personal testing with a complete template engine using > the > > ES6 template strings, I realized that their use (in mine use case, of > > course) is slowest than the approach that I'm using right now (like the > > Underscore template). Thanks everyone :) > > > > _______________________________________________ > > es-discuss mailing list > > es-discuss at mozilla.org <javascript:;> > > https://mail.mozilla.org/listinfo/es-discuss > > > _______________________________________________ > es-discuss mailing list > es-discuss at mozilla.org <javascript:;> > https://mail.mozilla.org/listinfo/es-discuss > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20160112/1648e251/attachment.html>
A use I thought up (although I got lazy and abandoned it later) was an
exec
template tag, for executing commands. Or, and this just came off the
to of my head, you could use it as a vdom library as almost like a Lisp
reader macro:
n`.form-ctrl`(
n`input#input`("input"),
n`a[href="/submit.html"]`("Submit"))
A use I thought up (although I got lazy and abandoned it later) was an `exec` template tag, for executing commands. Or, and this just came off the to of my head, you could use it as a vdom library as almost like a Lisp reader macro: ```js n`.form-ctrl`( n`input#input`("input"), n`a[href="/submit.html"]`("Submit")) ``` On Tue, Jan 12, 2016, 17:34 Alexander Jones <alex at weej.com> wrote: > The two code samples you posted are equivalent (modulo the obvious > mistake). AFAIU there is still only a single parsing pass for template > strings. > > On Tuesday, 12 January 2016, /#!/JoePea <joe at trusktr.io> wrote: > >> The thing with template strings is that they are used at runtime. This >> could be slow if we're compiling things at runtime all the time, >> whereas a server-side templating solution might lead JavaScript >> functions compiled from templates (like in the case with Meteor Blaze >> Spacebars or React JSX), which can be faster at runtime. >> >> What are template strings good for besides the obvious benefit that >> they make things like >> >> ``` >> var str = "llo" >> console.log(`he${str} world!`) >> ``` >> >> easier to read than >> >> ``` >> var str = "llo" >> console.log('he'+'str'+' world!') >> ``` >> >> ? >> >> Maybe writing regexes can be nicer with template strings? I gave it a >> try at npmjs.com/regexr. >> >> On Mon, Jan 11, 2016 at 8:43 AM, Manuel Di Iorio <xeryan at gmail.com> >> wrote: >> > Yes Bob, after a personal testing with a complete template engine using >> the >> > ES6 template strings, I realized that their use (in mine use case, of >> > course) is slowest than the approach that I'm using right now (like the >> > Underscore template). Thanks everyone :) >> > >> > _______________________________________________ >> > 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 >> > _______________________________________________ > 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/20160113/a2286963/attachment-0001.html>
modulo the obvious mistake
Oops. x]
you could use it as a vdom library as almost like a Lisp reader macro:
That would be interesting. There's still lots of runtime processing though. Maybe a build-time tool can also optimize it though, but if it happens to be executed at runtime it'll just work. Here's a JSX-like concept, let's call it 'xjs' for sake of argument:
let style = {background: 'turquoise'}
let content = xjs`<p>hello</p>`
let el = xjs`
<div style=${styleObject}>
${content}
</div>
`
It could be compiled statically as well as have a runtime template-tag implementation.
> modulo the obvious mistake Oops. x] > you could use it as a vdom library as almost like a Lisp reader macro: That would be interesting. There's still lots of runtime processing though. Maybe a build-time tool can also optimize it though, but if it happens to be executed at runtime it'll just work. Here's a JSX-like concept, let's call it 'xjs' for sake of argument: ``` let style = {background: 'turquoise'} let content = xjs`<p>hello</p>` let el = xjs` <div style=${styleObject}> ${content} </div> ` ``` It could be compiled statically as well as have a runtime template-tag implementation. On Wed, Jan 13, 2016 at 12:05 AM, Isiah Meadows <isiahmeadows at gmail.com> wrote: > A use I thought up (although I got lazy and abandoned it later) was an > `exec` template tag, for executing commands. Or, and this just came off the > to of my head, you could use it as a vdom library as almost like a Lisp > reader macro: > > ```js > n`.form-ctrl`( > n`input#input`("input"), > n`a[href="/submit.html"]`("Submit")) > ``` > > > On Tue, Jan 12, 2016, 17:34 Alexander Jones <alex at weej.com> wrote: >> >> The two code samples you posted are equivalent (modulo the obvious >> mistake). AFAIU there is still only a single parsing pass for template >> strings. >> >> On Tuesday, 12 January 2016, /#!/JoePea <joe at trusktr.io> wrote: >>> >>> The thing with template strings is that they are used at runtime. This >>> could be slow if we're compiling things at runtime all the time, >>> whereas a server-side templating solution might lead JavaScript >>> functions compiled from templates (like in the case with Meteor Blaze >>> Spacebars or React JSX), which can be faster at runtime. >>> >>> What are template strings good for besides the obvious benefit that >>> they make things like >>> >>> ``` >>> var str = "llo" >>> console.log(`he${str} world!`) >>> ``` >>> >>> easier to read than >>> >>> ``` >>> var str = "llo" >>> console.log('he'+'str'+' world!') >>> ``` >>> >>> ? >>> >>> Maybe writing regexes can be nicer with template strings? I gave it a >>> try at npmjs.com/regexr. >>> >>> On Mon, Jan 11, 2016 at 8:43 AM, Manuel Di Iorio <xeryan at gmail.com> >>> wrote: >>> > Yes Bob, after a personal testing with a complete template engine using >>> > the >>> > ES6 template strings, I realized that their use (in mine use case, of >>> > course) is slowest than the approach that I'm using right now (like the >>> > Underscore template). Thanks everyone :) >>> > >>> > _______________________________________________ >>> > 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 >> >> _______________________________________________ >> es-discuss mailing list >> es-discuss at mozilla.org >> https://mail.mozilla.org/listinfo/es-discuss
Problem is: your idea has already been tried and found to be pretty slow. React devs did briefly consider this, but found that it had fundamental speed limitations. And precompilation is already happening with existing templates, even though building them normally is still cheap to do.
Problem is: your idea has already been tried and found to be pretty slow. React devs did briefly consider this, but found that it had fundamental speed limitations. And precompilation is already happening with existing templates, even though building them normally is still cheap to do. http://facebook.github.io/jsx/#why-not-template-literals On Wed, Jan 13, 2016, 05:45 /#!/JoePea <joe at trusktr.io> wrote: > > modulo the obvious mistake > > Oops. x] > > > you could use it as a vdom library as almost like a Lisp reader macro: > > That would be interesting. There's still lots of runtime processing > though. Maybe a build-time tool can also optimize it though, but if it > happens to be executed at runtime it'll just work. Here's a JSX-like > concept, let's call it 'xjs' for sake of argument: > > ``` > let style = {background: 'turquoise'} > let content = xjs`<p>hello</p>` > let el = xjs` > <div style=${styleObject}> > ${content} > </div> > ` > ``` > > It could be compiled statically as well as have a runtime template-tag > implementation. > > On Wed, Jan 13, 2016 at 12:05 AM, Isiah Meadows <isiahmeadows at gmail.com> > wrote: > > A use I thought up (although I got lazy and abandoned it later) was an > > `exec` template tag, for executing commands. Or, and this just came off > the > > to of my head, you could use it as a vdom library as almost like a Lisp > > reader macro: > > > > ```js > > n`.form-ctrl`( > > n`input#input`("input"), > > n`a[href="/submit.html"]`("Submit")) > > ``` > > > > > > On Tue, Jan 12, 2016, 17:34 Alexander Jones <alex at weej.com> wrote: > >> > >> The two code samples you posted are equivalent (modulo the obvious > >> mistake). AFAIU there is still only a single parsing pass for template > >> strings. > >> > >> On Tuesday, 12 January 2016, /#!/JoePea <joe at trusktr.io> wrote: > >>> > >>> The thing with template strings is that they are used at runtime. This > >>> could be slow if we're compiling things at runtime all the time, > >>> whereas a server-side templating solution might lead JavaScript > >>> functions compiled from templates (like in the case with Meteor Blaze > >>> Spacebars or React JSX), which can be faster at runtime. > >>> > >>> What are template strings good for besides the obvious benefit that > >>> they make things like > >>> > >>> ``` > >>> var str = "llo" > >>> console.log(`he${str} world!`) > >>> ``` > >>> > >>> easier to read than > >>> > >>> ``` > >>> var str = "llo" > >>> console.log('he'+'str'+' world!') > >>> ``` > >>> > >>> ? > >>> > >>> Maybe writing regexes can be nicer with template strings? I gave it a > >>> try at npmjs.com/regexr. > >>> > >>> On Mon, Jan 11, 2016 at 8:43 AM, Manuel Di Iorio <xeryan at gmail.com> > >>> wrote: > >>> > Yes Bob, after a personal testing with a complete template engine > using > >>> > the > >>> > ES6 template strings, I realized that their use (in mine use case, of > >>> > course) is slowest than the approach that I'm using right now (like > the > >>> > Underscore template). Thanks everyone :) > >>> > > >>> > _______________________________________________ > >>> > 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 > >> > >> _______________________________________________ > >> 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/20160113/0fe746d7/attachment-0001.html>
That link details other reasons, such as tooling.
That link details other reasons, such as tooling. On Wed, Jan 13, 2016, 18:11 Isiah Meadows <isiahmeadows at gmail.com> wrote: > Problem is: your idea has already been tried and found to be pretty slow. > React devs did briefly consider this, but found that it had fundamental > speed limitations. And precompilation is already happening with existing > templates, even though building them normally is still cheap to do. > > http://facebook.github.io/jsx/#why-not-template-literals > > On Wed, Jan 13, 2016, 05:45 /#!/JoePea <joe at trusktr.io> wrote: > >> > modulo the obvious mistake >> >> Oops. x] >> >> > you could use it as a vdom library as almost like a Lisp reader macro: >> >> That would be interesting. There's still lots of runtime processing >> though. Maybe a build-time tool can also optimize it though, but if it >> happens to be executed at runtime it'll just work. Here's a JSX-like >> concept, let's call it 'xjs' for sake of argument: >> >> ``` >> let style = {background: 'turquoise'} >> let content = xjs`<p>hello</p>` >> let el = xjs` >> <div style=${styleObject}> >> ${content} >> </div> >> ` >> ``` >> >> It could be compiled statically as well as have a runtime template-tag >> implementation. >> >> On Wed, Jan 13, 2016 at 12:05 AM, Isiah Meadows <isiahmeadows at gmail.com> >> wrote: >> > A use I thought up (although I got lazy and abandoned it later) was an >> > `exec` template tag, for executing commands. Or, and this just came off >> the >> > to of my head, you could use it as a vdom library as almost like a Lisp >> > reader macro: >> > >> > ```js >> > n`.form-ctrl`( >> > n`input#input`("input"), >> > n`a[href="/submit.html"]`("Submit")) >> > ``` >> > >> > >> > On Tue, Jan 12, 2016, 17:34 Alexander Jones <alex at weej.com> wrote: >> >> >> >> The two code samples you posted are equivalent (modulo the obvious >> >> mistake). AFAIU there is still only a single parsing pass for template >> >> strings. >> >> >> >> On Tuesday, 12 January 2016, /#!/JoePea <joe at trusktr.io> wrote: >> >>> >> >>> The thing with template strings is that they are used at runtime. This >> >>> could be slow if we're compiling things at runtime all the time, >> >>> whereas a server-side templating solution might lead JavaScript >> >>> functions compiled from templates (like in the case with Meteor Blaze >> >>> Spacebars or React JSX), which can be faster at runtime. >> >>> >> >>> What are template strings good for besides the obvious benefit that >> >>> they make things like >> >>> >> >>> ``` >> >>> var str = "llo" >> >>> console.log(`he${str} world!`) >> >>> ``` >> >>> >> >>> easier to read than >> >>> >> >>> ``` >> >>> var str = "llo" >> >>> console.log('he'+'str'+' world!') >> >>> ``` >> >>> >> >>> ? >> >>> >> >>> Maybe writing regexes can be nicer with template strings? I gave it a >> >>> try at npmjs.com/regexr. >> >>> >> >>> On Mon, Jan 11, 2016 at 8:43 AM, Manuel Di Iorio <xeryan at gmail.com> >> >>> wrote: >> >>> > Yes Bob, after a personal testing with a complete template engine >> using >> >>> > the >> >>> > ES6 template strings, I realized that their use (in mine use case, >> of >> >>> > course) is slowest than the approach that I'm using right now (like >> the >> >>> > Underscore template). Thanks everyone :) >> >>> > >> >>> > _______________________________________________ >> >>> > 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 >> >> >> >> _______________________________________________ >> >> 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/20160113/88b2d975/attachment.html>
Interesting!
Interesting! On Wed, Jan 13, 2016 at 3:12 PM, Isiah Meadows <isiahmeadows at gmail.com> wrote: > That link details other reasons, such as tooling. > > > On Wed, Jan 13, 2016, 18:11 Isiah Meadows <isiahmeadows at gmail.com> wrote: >> >> Problem is: your idea has already been tried and found to be pretty slow. >> React devs did briefly consider this, but found that it had fundamental >> speed limitations. And precompilation is already happening with existing >> templates, even though building them normally is still cheap to do. >> >> http://facebook.github.io/jsx/#why-not-template-literals >> >> >> On Wed, Jan 13, 2016, 05:45 /#!/JoePea <joe at trusktr.io> wrote: >>> >>> > modulo the obvious mistake >>> >>> Oops. x] >>> >>> > you could use it as a vdom library as almost like a Lisp reader macro: >>> >>> That would be interesting. There's still lots of runtime processing >>> though. Maybe a build-time tool can also optimize it though, but if it >>> happens to be executed at runtime it'll just work. Here's a JSX-like >>> concept, let's call it 'xjs' for sake of argument: >>> >>> ``` >>> let style = {background: 'turquoise'} >>> let content = xjs`<p>hello</p>` >>> let el = xjs` >>> <div style=${styleObject}> >>> ${content} >>> </div> >>> ` >>> ``` >>> >>> It could be compiled statically as well as have a runtime template-tag >>> implementation. >>> >>> On Wed, Jan 13, 2016 at 12:05 AM, Isiah Meadows <isiahmeadows at gmail.com> >>> wrote: >>> > A use I thought up (although I got lazy and abandoned it later) was an >>> > `exec` template tag, for executing commands. Or, and this just came off >>> > the >>> > to of my head, you could use it as a vdom library as almost like a Lisp >>> > reader macro: >>> > >>> > ```js >>> > n`.form-ctrl`( >>> > n`input#input`("input"), >>> > n`a[href="/submit.html"]`("Submit")) >>> > ``` >>> > >>> > >>> > On Tue, Jan 12, 2016, 17:34 Alexander Jones <alex at weej.com> wrote: >>> >> >>> >> The two code samples you posted are equivalent (modulo the obvious >>> >> mistake). AFAIU there is still only a single parsing pass for template >>> >> strings. >>> >> >>> >> On Tuesday, 12 January 2016, /#!/JoePea <joe at trusktr.io> wrote: >>> >>> >>> >>> The thing with template strings is that they are used at runtime. >>> >>> This >>> >>> could be slow if we're compiling things at runtime all the time, >>> >>> whereas a server-side templating solution might lead JavaScript >>> >>> functions compiled from templates (like in the case with Meteor Blaze >>> >>> Spacebars or React JSX), which can be faster at runtime. >>> >>> >>> >>> What are template strings good for besides the obvious benefit that >>> >>> they make things like >>> >>> >>> >>> ``` >>> >>> var str = "llo" >>> >>> console.log(`he${str} world!`) >>> >>> ``` >>> >>> >>> >>> easier to read than >>> >>> >>> >>> ``` >>> >>> var str = "llo" >>> >>> console.log('he'+'str'+' world!') >>> >>> ``` >>> >>> >>> >>> ? >>> >>> >>> >>> Maybe writing regexes can be nicer with template strings? I gave it a >>> >>> try at npmjs.com/regexr. >>> >>> >>> >>> On Mon, Jan 11, 2016 at 8:43 AM, Manuel Di Iorio <xeryan at gmail.com> >>> >>> wrote: >>> >>> > Yes Bob, after a personal testing with a complete template engine >>> >>> > using >>> >>> > the >>> >>> > ES6 template strings, I realized that their use (in mine use case, >>> >>> > of >>> >>> > course) is slowest than the approach that I'm using right now (like >>> >>> > the >>> >>> > Underscore template). Thanks everyone :) >>> >>> > >>> >>> > _______________________________________________ >>> >>> > 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 >>> >> >>> >> _______________________________________________ >>> >> es-discuss mailing list >>> >> es-discuss at mozilla.org >>> >> https://mail.mozilla.org/listinfo/es-discuss
On Thu, Jan 14, 2016, 01:11 Isiah Meadows <isiahmeadows at gmail.com> wrote:
Problem is: your idea has already been tried and found to be pretty slow. React devs did briefly consider this, but found that it had fundamental speed limitations. And precompilation is already happening with existing templates, even though building them normally is still cheap to do.
facebook.github.io/jsx/#, facebook.github.io/jsx/#why-not-template-literals why-not-template-literals
Substack recently released a package that may contribute to this discussion: substack/hyperx
On Thu, Jan 14, 2016, 01:11 Isiah Meadows <isiahmeadows at gmail.com> wrote: > Problem is: your idea has already been tried and found to be pretty slow. > React devs did briefly consider this, but found that it had fundamental > speed limitations. And precompilation is already happening with existing > templates, even though building them normally is still cheap to do. > > http://facebook.github.io/jsx/# > <http://facebook.github.io/jsx/#why-not-template-literals> > why-not-template-literals > Substack recently released a package that may contribute to this discussion: https://github.com/substack/hyperx > On Wed, Jan 13, 2016, 05:45 /#!/JoePea <joe at trusktr.io> wrote: > >> > modulo the obvious mistake >> >> Oops. x] >> >> > you could use it as a vdom library as almost like a Lisp reader macro: >> >> That would be interesting. There's still lots of runtime processing >> though. Maybe a build-time tool can also optimize it though, but if it >> happens to be executed at runtime it'll just work. Here's a JSX-like >> concept, let's call it 'xjs' for sake of argument: >> >> ``` >> let style = {background: 'turquoise'} >> let content = xjs`<p>hello</p>` >> let el = xjs` >> <div style=${styleObject}> >> ${content} >> </div> >> ` >> ``` >> >> It could be compiled statically as well as have a runtime template-tag >> implementation. >> >> On Wed, Jan 13, 2016 at 12:05 AM, Isiah Meadows <isiahmeadows at gmail.com> >> wrote: >> > A use I thought up (although I got lazy and abandoned it later) was an >> > `exec` template tag, for executing commands. Or, and this just came off >> the >> > to of my head, you could use it as a vdom library as almost like a Lisp >> > reader macro: >> > >> > ```js >> > n`.form-ctrl`( >> > n`input#input`("input"), >> > n`a[href="/submit.html"]`("Submit")) >> > ``` >> > >> > >> > On Tue, Jan 12, 2016, 17:34 Alexander Jones <alex at weej.com> wrote: >> >> >> >> The two code samples you posted are equivalent (modulo the obvious >> >> mistake). AFAIU there is still only a single parsing pass for template >> >> strings. >> >> >> >> On Tuesday, 12 January 2016, /#!/JoePea <joe at trusktr.io> wrote: >> >>> >> >>> The thing with template strings is that they are used at runtime. This >> >>> could be slow if we're compiling things at runtime all the time, >> >>> whereas a server-side templating solution might lead JavaScript >> >>> functions compiled from templates (like in the case with Meteor Blaze >> >>> Spacebars or React JSX), which can be faster at runtime. >> >>> >> >>> What are template strings good for besides the obvious benefit that >> >>> they make things like >> >>> >> >>> ``` >> >>> var str = "llo" >> >>> console.log(`he${str} world!`) >> >>> ``` >> >>> >> >>> easier to read than >> >>> >> >>> ``` >> >>> var str = "llo" >> >>> console.log('he'+'str'+' world!') >> >>> ``` >> >>> >> >>> ? >> >>> >> >>> Maybe writing regexes can be nicer with template strings? I gave it a >> >>> try at npmjs.com/regexr. >> >>> >> >>> On Mon, Jan 11, 2016 at 8:43 AM, Manuel Di Iorio <xeryan at gmail.com> >> >>> wrote: >> >>> > Yes Bob, after a personal testing with a complete template engine >> using >> >>> > the >> >>> > ES6 template strings, I realized that their use (in mine use case, >> of >> >>> > course) is slowest than the approach that I'm using right now (like >> the >> >>> > Underscore template). Thanks everyone :) >> >>> > >> >>> > _______________________________________________ >> >>> > 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 >> >> >> >> _______________________________________________ >> >> 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/20160114/6c7ee8b6/attachment-0001.html>
I asked around and somebody said that there will be the possibility to execute arbitrary code inside the template tags, using the 'do' keyword in this example way:
Is there the possibility in future to implement that feature without the keyword? What is the plan (read 'estimated date') for the rollout of this feature ?
The idea to develop in native way a good templating engine is exciting and I'm looking forward for its complete implementation :)