If the template expands to bad javascript, #104

Closed
wants to merge 5 commits into from

2 participants

@patmoore

provide a message that show the bad expansion to the user for them to debug.

Previously the user would see a SyntaxError from this line :
code = new Function( "data, view, j, b, u", fnDeclStr
+ (getsValue ? "v," : "")
+ (hasTag ? "t=j.tag," : "")
+ (hasConverter ? "c=j.convert," : "")
+ (hasEncoder ? "e=j.converters.html," : "")
+ "ret; try{\n\n"
+ (tmplOptions.debug ? "debugger;" : "")
+ (allowCode ? 'ret=' : 'return ')
+ code.slice( 0, -1 ) + ";\n\n"
+ (allowCode ? "return ret;" : "")
+ "}catch(e){return j.err(e);}";

which is misleading because the natural inclination is to think that jsrender.js has a syntax error.

The user is shown the expanded problematic template as well.

@BorisMoore
Owner

I agree with you that the error message when the compiled template has a syntax error was potentially confusing, so I have taken your idea on this, though I have tried to implement it without impacting file size too much. See the latest commit.

@BorisMoore BorisMoore closed this Apr 24, 2012
@patmoore

thanks for this fix!

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