squirrellyjs / squirrelly

Semi-embedded JS template engine that supports helpers, filters, partials, and template inheritance. 4KB minzipped, written in TypeScript ⛺
https://squirrelly.js.org
MIT License
555 stars 81 forks source link

Handling "undefined" references #220

Closed Shanery closed 3 years ago

Shanery commented 3 years ago

At the moment I want to use useWith: true. The problem is that it always throws a reference error when the reference doesn't exist.

Sqrl.render("{{ key }}", { anotherKey: 'test' }, {useWith: true})

This causes a Reference error as key isn't defined... I want to be able to handle these cases (preferable just return an empty string). Any suggestions?

Shanery commented 3 years ago

After reading through how this works I solved this by forking the library and putting all the tR+= into try catch. I’m not sure it affects performance but there’s no other work around as it is a reference error...