Skip to content

Commit

Permalink
Changed the variable used in buildTmplFn from _ to __. (Issue 10)
Browse files Browse the repository at this point in the history
Compromise choice: a variable name that is unlikely to exist as a global,
or as a field name on data, but is not too long, to keep code size down.
  • Loading branch information
BorisMoore committed Feb 4, 2011
1 parent f9b00c8 commit fe9d7e4
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions jquery.tmpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -207,15 +207,15 @@
tag: {
"tmpl": {
_default: { $2: "null" },
open: "if($notnull_1){_=_.concat($item.nest($1,$2));}"
open: "if($notnull_1){__=__.concat($item.nest($1,$2));}"
// tmpl target parameter can be of type function, so use $1, not $1a (so not auto detection of functions)
// This means that {{tmpl foo}} treats foo as a template (which IS a function).
// Explicit parens can be used if foo is a function that returns a template: {{tmpl foo()}}.
},
"wrap": {
_default: { $2: "null" },
open: "$item.calls(_,$1,$2);_=[];",
close: "call=$item.calls();_=call._.concat($item.wrap(call,_));"
open: "$item.calls(__,$1,$2);__=[];",
close: "call=$item.calls();__=call._.concat($item.wrap(call,__));"
},
"each": {
_default: { $2: "$index, $value" },
Expand All @@ -232,12 +232,12 @@
},
"html": {
// Unecoded expression evaluation.
open: "if($notnull_1){_.push($1a);}"
open: "if($notnull_1){__.push($1a);}"
},
"=": {
// Encoded expression evaluation. Abbreviated form is ${}.
_default: { $1: "$data" },
open: "if($notnull_1){_.push($.encode($1a));}"
open: "if($notnull_1){__.push($.encode($1a));}"
},
"!": {
// Comment tag. Skipped by parser
Expand Down Expand Up @@ -314,10 +314,11 @@
// Generate a reusable function that will serve to render a template against data
function buildTmplFn( markup ) {
return new Function("jQuery","$item",
"var $=jQuery,call,_=[],$data=$item.data;" +
// Use the variable __ to hold a string array while building the compiled template. (See https://github.com/jquery/jquery-tmpl/issues#issue/10).
"var $=jQuery,call,__=[],$data=$item.data;" +

// Introduce the data as local variables using with(){}
"with($data){_.push('" +
"with($data){__.push('" +

// Convert the template into pure JavaScript
jQuery.trim(markup)
Expand Down Expand Up @@ -352,9 +353,9 @@
.split( "$1a" ).join( exprAutoFnDetect )
.split( "$1" ).join( expr )
.split( "$2" ).join( fnargs || def.$2 || "" ) +
"_.push('";
"__.push('";
}) +
"');}return _;"
"');}return __;"
);
}
function updateWrapped( options, wrapped ) {
Expand Down

0 comments on commit fe9d7e4

Please sign in to comment.