Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

make if and elseif throw a better error message when the tag body is omitted #425

Merged
merged 2 commits into from
Mar 7, 2014

Conversation

greelgorke
Copy link
Contributor

I discovered a bug by accident, while composing a template:

{% if name %}
  {{name}}
{% elseif %}
  Someone
{% endif %}

i forgot the body of elseif and used up about a half of a day to find out whats wrong. mostly because the parser nor the compiler complains about it, but the compiled function contains a syntax error. at the end the js engine complains with SyntaxError: Unexpected token ) without any sign of location at runtime.

The patch turns this mess to the error at parsetime: No conditional statement provided on line 5.

@@ -12,6 +12,7 @@ var opts = {
};

var cases = [
{ code: undefined, result: false },
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an empty string?

{ code: '', result: false }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

while debugging the value str was undefined. not exactly sure why, but that was, what i've seen.

@paularmstrong paularmstrong merged commit 8ab5bfb into paularmstrong:master Mar 7, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants