@@ -2,7 +2,7 @@ var Cache = require('../cache')
22var config = require ( '../config' )
33var dirParser = require ( './directive' )
44var regexEscapeRE = / [ - . * + ? ^ $ { } ( ) | [ \] \/ \\ ] / g
5- var cache , tagRE , htmlRE , firstChar , lastChar
5+ var cache , tagRE , htmlRE
66
77/**
88 * Escape a string so it can be used in a RegExp
@@ -15,32 +15,18 @@ function escapeRegex (str) {
1515 return str . replace ( regexEscapeRE , '\\$&' )
1616}
1717
18- /**
19- * Compile the interpolation tag regex.
20- *
21- * @return {RegExp }
22- */
23-
24- function compileRegex ( ) {
25- config . _delimitersChanged = false
26- var open = config . delimiters [ 0 ]
27- var close = config . delimiters [ 1 ]
28- firstChar = open . charAt ( 0 )
29- lastChar = close . charAt ( close . length - 1 )
30- var firstCharRE = escapeRegex ( firstChar )
31- var lastCharRE = escapeRegex ( lastChar )
32- var openRE = escapeRegex ( open )
33- var closeRE = escapeRegex ( close )
18+ exports . compileRegex = function ( ) {
19+ var open = escapeRegex ( config . delimiters [ 0 ] )
20+ var close = escapeRegex ( config . delimiters [ 1 ] )
21+ var unsafeOpen = escapeRegex ( config . unsafeDelimiters [ 0 ] )
22+ var unsafeClose = escapeRegex ( config . unsafeDelimiters [ 1 ] )
3423 tagRE = new RegExp (
35- firstCharRE + '?' + openRE +
36- '(.+?)' +
37- closeRE + lastCharRE + '?' ,
24+ unsafeOpen + '(.+?)' + unsafeClose + '|' +
25+ open + '(.+?)' + close ,
3826 'g'
3927 )
4028 htmlRE = new RegExp (
41- '^' + firstCharRE + openRE +
42- '.*' +
43- closeRE + lastCharRE + '$'
29+ '^' + unsafeOpen + '.*' + unsafeClose + '$'
4430 )
4531 // reset cache
4632 cache = new Cache ( 1000 )
@@ -58,8 +44,8 @@ function compileRegex () {
5844 */
5945
6046exports . parse = function ( text ) {
61- if ( config . _delimitersChanged ) {
62- compileRegex ( )
47+ if ( ! cache ) {
48+ exports . compileRegex ( )
6349 }
6450 var hit = cache . get ( text )
6551 if ( hit ) {
@@ -71,7 +57,7 @@ exports.parse = function (text) {
7157 }
7258 var tokens = [ ]
7359 var lastIndex = tagRE . lastIndex = 0
74- var match , index , value , first , oneTime , twoWay
60+ var match , index , html , value , first , oneTime , twoWay
7561 /* eslint-disable no-cond-assign */
7662 while ( match = tagRE . exec ( text ) ) {
7763 /* eslint-enable no-cond-assign */
@@ -83,16 +69,18 @@ exports.parse = function (text) {
8369 } )
8470 }
8571 // tag token
86- first = match [ 1 ] . charCodeAt ( 0 )
72+ html = htmlRE . test ( match [ 0 ] )
73+ value = html ? match [ 1 ] : match [ 2 ]
74+ first = value . charCodeAt ( 0 )
8775 oneTime = first === 42 // *
8876 twoWay = first === 64 // @
8977 value = oneTime || twoWay
90- ? match [ 1 ] . slice ( 1 )
91- : match [ 1 ]
78+ ? value . slice ( 1 )
79+ : value
9280 tokens . push ( {
9381 tag : true ,
9482 value : value . trim ( ) ,
95- html : htmlRE . test ( match [ 0 ] ) ,
83+ html : html ,
9684 oneTime : oneTime ,
9785 twoWay : twoWay
9886 } )
0 commit comments