File tree Expand file tree Collapse file tree 3 files changed +11
-8
lines changed
Expand file tree Collapse file tree 3 files changed +11
-8
lines changed Original file line number Diff line number Diff line change 3333 ast ;
3434 // Extend the Templating engine with a print method for the generated functions:
3535 tmpl . print = function ( str ) {
36- var helper = helperRegexp . test ( str ) ? tmpl . helper : "" ;
36+ // Only add helper functions if they are used inside of the template:
37+ var helper = helperRegexp . test ( str ) ? tmpl . helper : "" ,
38+ body = str . replace ( tmpl . regexp , tmpl . func ) ;
39+ if ( helper || ( / _ e \s * \( / . test ( body ) ) ) {
40+ helper = "_e=tmpl.encode" + helper + "," ;
41+ }
3742 return "function(" + tmpl . arg + ",tmpl){" +
38- ( "var _s='',_e=tmpl.encode" + helper + ";_s+='" +
39- str . replace ( tmpl . regexp , tmpl . func ) +
40- "';return _s;" ) . split ( "_s+='';" ) . join ( "" ) +
41- "}" ;
43+ ( "var " + helper + "_s='" + body + "';return _s;" )
44+ . split ( "_s+='';" ) . join ( "" ) + "}" ;
4245 } ;
4346 // Loop through the command line arguments:
4447 process . argv . forEach ( function ( file , index ) {
Original file line number Diff line number Diff line change 2222 tmpl ( tmpl . load ( str ) ) :
2323 new Function (
2424 tmpl . arg + ',tmpl' ,
25- ( "var _s='', _e=tmpl.encode" + tmpl . helper + ";_s+ ='" +
25+ ( "var _e=tmpl.encode" + tmpl . helper + ",_s ='" +
2626 str . replace ( tmpl . regexp , tmpl . func ) +
27- "';return _s;" ) . split ( "_s+='';" ) . join ( "" )
27+ "';return _s;" )
2828 ) ;
2929 return data ? f ( data , tmpl ) : function ( data ) {
3030 return f ( data , tmpl ) ;
You can’t perform that action at this time.
0 commit comments