Tommy Hodgins: I looked into using template literals, but I wrote it the way I did for a couple of reasons:
- It's less complicated, at least to me.
{{if(options.num === 3)}}
Display this
{{#else}}
Display that
{{/if}}
is just a little bit easier for me than using ternary operators, like${num === 3 ? 'Display this' : 'Display that'}
- It supports precompilation--the string is transformed into a function that can be saved, so you don't have to compile again when you call it. So it turns into native code, and the function can be minified. This theoretically beats calling Function() and returning a template literal, which then has to be run in JS, each time you want to render.
- You can have custom tags and comments
- Not all browsers support ES6 template literals
That being said, your template engine looks really cool. I'll be sure to check it out sometime :).