Skip to content
Browse files

Feature: Added option `quiet` for supressing some errors (currently o…

…nly not_defined errors)
  • Loading branch information...
1 parent 0376b60 commit 2f33c468f91ecd286cf7cae0a9af0f761d579ef3 @stagas committed
Showing with 37 additions and 5 deletions.
  1. +37 −5 lib/jade.js
View
42 lib/jade.js
@@ -134,20 +134,52 @@ function parse(str, options){
exports.compile = function(str, options){
var options = options || {}
+ , quiet = options.quiet
, client = options.client
, filename = options.filename
? JSON.stringify(options.filename)
: 'undefined'
- , fn;
+ , fn
+ , code_pre
+ , code_post;
+
+ if (quiet) {
+ code_pre = [
+ 'var err;'
+ , 'do {'
+ , ' err = undefined;'
+ , ' try {'
+ ].join('\n');
+
+ code_post = [
+ ' } catch (e) {'
+ , ' err = e'
+ , ' if (err.type == \'not_defined\') {'
+ , ' locals[err.arguments[0]] = undefined;'
+ , ' } else {'
+ , ' rethrow(err, __jade[0].filename, __jade[0].lineno);'
+ , ' }'
+ , ' }'
+ , '} while (err && err.type == \'not_defined\');'
+ ].join('\n');
+ } else {
+ code_pre = [
+ 'try {'
+ ].join('\n');
+
+ code_post = [
+ '} catch (err) {'
+ , ' rethrow(err, __jade[0].filename, __jade[0].lineno);'
+ , '}'
+ ].join('\n');
+ }
if (options.compileDebug !== false) {
fn = [
'var __jade = [{ lineno: 1, filename: ' + filename + ' }];'
- , 'try {'
+ , code_pre
, parse(String(str), options)
- , '} catch (err) {'
- , ' rethrow(err, __jade[0].filename, __jade[0].lineno);'
- , '}'
+ , code_post
].join('\n');
} else {
fn = parse(String(str), options);

0 comments on commit 2f33c46

Please sign in to comment.
Something went wrong with that request. Please try again.