1- var config = require ( './config' ) ,
2- toString = ( { } ) . toString ,
3- win = window ,
4- console = win . console ,
5- def = Object . defineProperty ,
6- OBJECT = 'object' ,
7- THIS_RE = / [ ^ \w ] t h i s [ ^ \w ] / ,
1+ var config = require ( './config' ) ,
2+ toString = ( { } ) . toString ,
3+ win = window ,
4+ console = win . console ,
5+ def = Object . defineProperty ,
6+ OBJECT = 'object' ,
7+ THIS_RE = / [ ^ \w ] t h i s [ ^ \w ] / ,
8+ BRACKET_RE_S = / \[ ' ( [ ^ ' ] + ) ' \] / g,
9+ BRACKET_RE_D = / \[ " ( [ ^ " ] + ) " \] / g,
810 hasClassList = 'classList' in document . documentElement ,
911 ViewModel // late def
1012
@@ -13,6 +15,16 @@ var defer =
1315 win . webkitRequestAnimationFrame ||
1416 win . setTimeout
1517
18+ /**
19+ * Normalize keypath with possible brackets into dot notations
20+ */
21+ function normalizeKeypath ( key ) {
22+ return key . indexOf ( '[' ) < 0
23+ ? key
24+ : key . replace ( BRACKET_RE_S , '.$1' )
25+ . replace ( BRACKET_RE_D , '.$1' )
26+ }
27+
1628var utils = module . exports = {
1729
1830 /**
@@ -25,6 +37,7 @@ var utils = module.exports = {
2537 */
2638 get : function ( obj , key ) {
2739 /* jshint eqeqeq: false */
40+ key = normalizeKeypath ( key )
2841 if ( key . indexOf ( '.' ) < 0 ) {
2942 return obj [ key ]
3043 }
@@ -41,6 +54,7 @@ var utils = module.exports = {
4154 */
4255 set : function ( obj , key , val ) {
4356 /* jshint eqeqeq: false */
57+ key = normalizeKeypath ( key )
4458 if ( key . indexOf ( '.' ) < 0 ) {
4559 obj [ key ] = val
4660 return
0 commit comments