Skip to content

Commit

Permalink
supported ignore some code
Browse files Browse the repository at this point in the history
  • Loading branch information
niceue committed Apr 29, 2014
1 parent 6a16ad9 commit 4e7cf09
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
29 changes: 21 additions & 8 deletions tpl.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,36 @@
elen = end.length,
b = html.indexOf(begin),
e,
skip,
tmp;

while(b != -1) {
e = html.indexOf(end);
e = skip ? b + blen : html.indexOf(end);
if(e < b) break; //出错后不再编译

str += "__+='" + ecp(html.substring(0, b)) + "';";
tmp = trim(html.substring(b+blen, e));
if( tmp.indexOf('=') === 0 ) { //模板变量
tmp = tmp.substring(1);
str += "typeof (" + tmp + ")!=='undefined'&&(__+=" + tmp + ");";
} else { //js代码
str += tmp + ";";

if (skip) {
html = html.substring(blen+elen+1);
skip--;
} else {
tmp = trim(html.substring(b+blen, e));
if ('#'===tmp) {
skip = 1;
}
else if( tmp.indexOf('=') === 0 ) { //模板变量
tmp = tmp.substring(1);
str += "typeof (" + tmp + ")!=='undefined'&&(__+=" + tmp + ");";
} else { //js代码
str += tmp + ";";
}
}

html = html.substring(e + elen);
b = html.indexOf(begin);
b = html.indexOf( begin + (skip ? '#'+end : '') );
}
str += "__+='" + ecp(html) + "'"+ (v?";":"}") +"return __";
console.log(str)
return new Function(arg1, str);
}

Expand Down
2 changes: 1 addition & 1 deletion tpl.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4e7cf09

Please sign in to comment.