Skip to content

Commit

Permalink
Remove closures used to simulate block scope in compiled output
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Sep 24, 2010
1 parent 483f8d4 commit 31d25f1
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions lib/compiler.js
Expand Up @@ -223,17 +223,30 @@ 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 + ')';
this.buf.push("buf.push(" + val + ");");
} 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('}');
}
},

Expand Down

0 comments on commit 31d25f1

Please sign in to comment.