diff --git a/lib/compiler.js b/lib/compiler.js index 0a2085e99..31dd4a293 100644 --- a/lib/compiler.js +++ b/lib/compiler.js @@ -223,6 +223,18 @@ Compiler.prototype = { */ visitCode: function(code){ + var end; + + if (code.block) { + // Optimize for if / else + if (0 == code.val.trim().indexOf('if') || + 0 == code.val.trim().indexOf('else')) { + end = true; + code.val += ' {'; + } + } + + // Buffer code if (code.buffer) { var val = code.val.trimLeft(); if (code.escape) val = 'escape(' + val + ')'; @@ -230,10 +242,11 @@ Compiler.prototype = { } else { this.buf.push(code.val); } + + // Block support if (code.block) { - this.buf.push(' (function(){'); this.visit(code.block); - this.buf.push(' }).call(this);'); + if (end) this.buf.push('}'); } },