@@ -23,11 +23,10 @@ var tool = {
23
23
//匹配满足规则内容
24
24
query : function ( type , _ , __ ) {
25
25
var types = [
26
- '#([\\s\\S])*?' , //js语句
27
- '#|' , //语句开合
26
+ '#([\\s\\S])+?' , //js语句
28
27
'([^{#}])*?' //普通字段
29
28
] [ type || 0 ] ;
30
- return tool . exp ( ( _ || '' ) + config . open + types + config . close + ( __ || '' ) ) ;
29
+ return exp ( ( _ || '' ) + config . open + types + config . close + ( __ || '' ) ) ;
31
30
} ,
32
31
escape : function ( html ) {
33
32
return String ( html || '' ) . replace ( / & (? ! # ? [ a - z A - Z 0 - 9 ] + ; ) / g, '&' )
@@ -40,7 +39,7 @@ var tool = {
40
39
}
41
40
} ;
42
41
43
- var Tpl = function ( tpl ) {
42
+ var exp = tool . exp , Tpl = function ( tpl ) {
44
43
this . tpl = tpl ;
45
44
} ;
46
45
@@ -49,21 +48,24 @@ Tpl.pt = Tpl.prototype;
49
48
//核心引擎
50
49
Tpl . pt . parse = function ( tpl , data ) {
51
50
var that = this , tplog = tpl ;
52
-
53
- tpl = tpl . replace ( / \n | \t | \r / g, '' ) . replace ( / (? = \" | \' ) / g, '\\' ) . replace ( tool . query ( ) , function ( str ) {
54
- str = str . replace ( / \\ " | \\ ' / g, '"' ) ;
55
- return '";' + str . replace ( tool . query ( 1 , '^' , '$' ) , '' ) + '; view+="' ;
56
- } ) . replace ( tool . query ( 2 ) , function ( str ) {
51
+ var jss = exp ( '^' + config . open + '#' , '' ) , jsse = exp ( config . close + '$' , '' ) ;
52
+
53
+ tpl = tpl . replace ( / [ \r \t \n ] / g, ' ' ) . replace ( exp ( config . open + '#' ) , config . open + '# ' )
54
+ . replace ( exp ( config . close + '}' ) , '} ' + config . close )
55
+ . replace ( / (? = " | ' ) / g, '\\' ) . replace ( tool . query ( ) , function ( str ) {
56
+ str = str . replace ( jss , '' ) . replace ( jsse , '' ) ;
57
+ return '";' + str . replace ( / \\ / g, '' ) + '; view+="' ;
58
+ } ) . replace ( tool . query ( 1 ) , function ( str ) {
59
+ var start = '"+(' ;
57
60
if ( str . replace ( / \s / g, '' ) === config . open + config . close ) {
58
61
return '' ;
59
62
}
60
- var sexp = '^ '+ config . open , start = '(' ;
61
- if ( tool . exp ( sexp + '=' ) . test ( str ) ) {
62
- sexp += '=' ;
63
- start = '_escape_('
63
+ str = str . replace ( exp ( config . open + '| '+ config . close ) , '' ) ;
64
+ if ( / ^ = / . test ( str ) ) {
65
+ str = str . replace ( / ^ = / , '' ) ;
66
+ start = '"+ _escape_(' ;
64
67
}
65
- str = str . replace ( tool . exp ( sexp ) , '"+' + start ) . replace ( tool . exp ( config . close + '$' ) , ')+"' ) ;
66
- return str . replace ( / \\ " | \\ ' / g, '"' ) ;
68
+ return start + str . replace ( / \\ / g, '' ) + ')+"' ;
67
69
} ) ;
68
70
69
71
tpl = '"use strict";var view = "' + tpl + '";return view;' ;
0 commit comments