From 0fa6466a5d202dea57390dc1bc6722a37259aef3 Mon Sep 17 00:00:00 2001 From: Tj Holowaychuk Date: Fri, 2 Jul 2010 17:13:47 -0700 Subject: [PATCH] Better reporting for js syntax errors Big hack, but if we could catch the syntax errors, we could apply a real lineno to the stack trace. At least this exposes the contents of the line --- examples/users.jade | 2 +- lib/jade.js | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/users.jade b/examples/users.jade index 99270e5bc..a97542b90 100644 --- a/examples/users.jade +++ b/examples/users.jade @@ -7,4 +7,4 @@ users - user.roles.forEach(function(role){ role= role - }) - - }) \ No newline at end of file + - }) diff --git a/lib/jade.js b/lib/jade.js index a0e4e70ee..4e1f6b815 100644 --- a/lib/jade.js +++ b/lib/jade.js @@ -679,8 +679,14 @@ exports.render = function(str, options){ } // Generate function - var fn = Function('locals, attrs, escape, _', 'with (locals) {' + js + '}'); - + try { + var fn = Function('locals, attrs, escape, _', 'with (locals) {' + js + '}'); + } catch (err) { + // TODO: re-catch and apply real lineno + process.compile(js, filename || 'Jade'); + return; + } + try { var _ = { lineno: 1 }; return fn.call(options.scope,