File tree Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Expand file tree Collapse file tree 2 files changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ const newlineRE = /\n/g
2626const saveRE = / [ \{ , ] \s * [ \w \$ _ ] + \s * : | ( ' (?: [ ^ ' \\ ] | \\ .) * ' | " (?: [ ^ " \\ ] | \\ .) * " ) | n e w | t y p e o f | v o i d / g
2727const restoreRE = / " ( \d + ) " / g
2828const pathTestRE = / ^ [ A - Z a - z _ $ ] [ \w $ ] * (?: \. [ A - Z a - z _ $ ] [ \w $ ] * | \[ ' .* ?' \] | \[ " .* ?" \] | \[ \d + \] | \[ [ A - Z a - z _ $ ] [ \w $ ] * \] ) * $ /
29- const pathReplaceRE = / [ ^ \w $ \. ] (?: [ A - Z a - z _ $ ] [ \w $ ] * (?: \. [ A - Z a - z _ $ ] [ \w $ ] * | \[ ' . * ? ' \] | \[ " . * ? " \] ) * ) / g
29+ const identRE = / [ ^ \w $ \. ] (?: [ A - Z a - z _ $ ] [ \w $ ] * ) / g
3030const booleanLiteralRE = / ^ (?: t r u e | f a l s e ) $ /
3131
3232/**
@@ -119,7 +119,7 @@ function compileGetter (exp) {
119119 // rewrite all paths
120120 // pad 1 space here becaue the regex matches 1 extra char
121121 body = ( ' ' + body )
122- . replace ( pathReplaceRE , rewrite )
122+ . replace ( identRE , rewrite )
123123 . replace ( restoreRE , restore )
124124 return makeGetterFn ( body )
125125}
Original file line number Diff line number Diff line change @@ -181,6 +181,18 @@ var testCases = [
181181 expected : "a\'b\'c" ,
182182 paths : [ 'c' ]
183183 } ,
184+ {
185+ // dynamic sub path
186+ exp : "a['b' + i + 'c']" ,
187+ scope : {
188+ i : 0 ,
189+ a : {
190+ 'b0c' : 123
191+ }
192+ } ,
193+ expected : 123 ,
194+ paths : [ 'a' , 'i' ]
195+ } ,
184196 {
185197 // Math global, simple path
186198 exp : 'Math.PI' ,
You can’t perform that action at this time.
0 commit comments