Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There should be a (perhaps configurable) warning when using undefined variables #167

Open
jakub-g opened this issue May 6, 2014 · 2 comments

Comments

@jakub-g
Copy link
Collaborator

jakub-g commented May 6, 2014

When I use an undefined variable in a template, hashspace wants to be user-friendly and treats this as an empty string.

That's okay, it's certainly better than to break the whole application, but I think things like this should be logged into the console, because they can hide a developer's bug and it might be tricky to immediately know that in big apps with complex logic. The experience of many projects shows that too much user-friendliness can bite in the least expected moments and make debugging painful.

http://plnkr.co/edit/FNuImk92ug07LxzZU7ue?p=preview

# template mytest()
    <div>
    {let foo = 1}
    <p>Fuu has a value of: {fuu}</p>
    // oh I wanted to use foo, but I was really sloppy when writing that, and I forgot to validate
    </div>
# /template

mytest().render("output");
@b-laporte
Copy link
Member

Well today you have 2 solutions:

  • TDD (!)
  • or use {log}

Having said that I am not against a specific option - but I guess it should be scoped, like {let} - otherwise you may have many logs in a large application, which would result in painful troubleshooting..

@piuccio
Copy link
Contributor

piuccio commented May 7, 2014

In this specific case, I'd prefer to have an option to throw an error!

var foo = 1;
console.log(fuu);
// this throws a ReferenceError

But in general the current behavior seems the best option, finding these errors is responsibility of a linter, not the template engine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants