@@ -68,7 +68,10 @@ function getRel (path, compiler) {
6868 }
6969 }
7070 compiler = vm . $compiler
71- if ( ! hasOwn . call ( compiler . bindings , path ) ) {
71+ if (
72+ ! hasOwn . call ( compiler . bindings , path ) &&
73+ path . charAt ( 0 ) !== '$'
74+ ) {
7275 compiler . createBinding ( path )
7376 }
7477 return rel
@@ -90,6 +93,15 @@ function makeGetter (exp, raw) {
9093 return fn
9194}
9295
96+ /**
97+ * Escape a leading dollar sign for regex construction
98+ */
99+ function escapeDollar ( v ) {
100+ return v . charAt ( 0 ) === '$'
101+ ? '\\' + v
102+ : v
103+ }
104+
93105module . exports = {
94106
95107 /**
@@ -105,11 +117,22 @@ module.exports = {
105117 }
106118 vars = utils . unique ( vars )
107119 var accessors = '' ,
108- pathRE = new RegExp ( "\\b(" + vars . join ( '|' ) + ")[$\\w\\.]*\\b" , 'g' ) ,
109- body = 'return ' + exp . replace ( pathRE , function ( path ) {
120+ // construct a regex to extract all valid variable paths
121+ // ones that begin with "$" are particularly tricky
122+ // because we can't use \b for them
123+ pathRE = new RegExp (
124+ "[^$\\w\\.](" +
125+ vars . map ( escapeDollar ) . join ( '|' ) +
126+ ")[$\\w\\.]*\\b" , 'g'
127+ ) ,
128+ body = ( 'return ' + exp ) . replace ( pathRE , function ( path ) {
129+ // keep track of the first char
130+ var c = path . charAt ( 0 )
131+ path = path . slice ( 1 )
110132 var val = 'this.' + getRel ( path , compiler ) + path
111133 accessors += val + ';'
112- return val
134+ // don't forget to put that first char back
135+ return c + val
113136 } )
114137 body = accessors + body
115138 return makeGetter ( body , exp )
0 commit comments