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,
8
10
hasClassList = 'classList' in document . documentElement ,
9
11
ViewModel // late def
10
12
@@ -13,6 +15,16 @@ var defer =
13
15
win . webkitRequestAnimationFrame ||
14
16
win . setTimeout
15
17
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
+
16
28
var utils = module . exports = {
17
29
18
30
/**
@@ -25,6 +37,7 @@ var utils = module.exports = {
25
37
*/
26
38
get : function ( obj , key ) {
27
39
/* jshint eqeqeq: false */
40
+ key = normalizeKeypath ( key )
28
41
if ( key . indexOf ( '.' ) < 0 ) {
29
42
return obj [ key ]
30
43
}
@@ -41,6 +54,7 @@ var utils = module.exports = {
41
54
*/
42
55
set : function ( obj , key , val ) {
43
56
/* jshint eqeqeq: false */
57
+ key = normalizeKeypath ( key )
44
58
if ( key . indexOf ( '.' ) < 0 ) {
45
59
obj [ key ] = val
46
60
return
0 commit comments