Skip to content

Commit

Permalink
Update Build
Browse files Browse the repository at this point in the history
  • Loading branch information
evanplaice committed Jan 22, 2020
1 parent 5e544a1 commit 8097f3e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
20 changes: 19 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,25 @@
function interpolate (template, tags = {}) {
const keys = Object.keys(tags);
const values = Object.values(tags);
return new Function(...keys, `return \`${template}\`;`)(...values);
try {
return new Function(...keys, `return \`${template}\`;`)(...values);
} catch (e) {
throw new TemplateException(template, tags, e);
}
}

class TemplateException extends Error {
constructor (template, tags, message) {
super();
this.name = 'TemplateError';
let msg = '\n------------------\n';
msg += `Template: \`${template}\``;
msg += '\n------------------\n';
msg += `Tags: ${JSON.stringify(tags, null, 2)}`;
msg += '\n------------------\n';
msg += message;
this.message = msg;
}
}

/* eslint no-undef: 0 */
Expand Down
2 changes: 1 addition & 1 deletion index.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8097f3e

Please sign in to comment.