@@ -42,12 +42,34 @@ module.exports = function parse (text, reviver) {
42
42
function internalize ( holder , name , reviver ) {
43
43
const value = holder [ name ]
44
44
if ( value != null && typeof value === 'object' ) {
45
- for ( const key in value ) {
46
- const replacement = internalize ( value , key , reviver )
47
- if ( replacement === undefined ) {
48
- delete value [ key ]
49
- } else {
50
- value [ key ] = replacement
45
+ if ( Array . isArray ( value ) ) {
46
+ for ( let i = 0 ; i < value . length ; i ++ ) {
47
+ const key = String ( i )
48
+ const replacement = internalize ( value , key , reviver )
49
+ if ( replacement === undefined ) {
50
+ delete value [ key ]
51
+ } else {
52
+ Object . defineProperty ( value , key , {
53
+ value : replacement ,
54
+ writable : true ,
55
+ enumerable : true ,
56
+ configurable : true ,
57
+ } )
58
+ }
59
+ }
60
+ } else {
61
+ for ( const key in value ) {
62
+ const replacement = internalize ( value , key , reviver )
63
+ if ( replacement === undefined ) {
64
+ delete value [ key ]
65
+ } else {
66
+ Object . defineProperty ( value , key , {
67
+ value : replacement ,
68
+ writable : true ,
69
+ enumerable : true ,
70
+ configurable : true ,
71
+ } )
72
+ }
51
73
}
52
74
}
53
75
}
@@ -973,7 +995,12 @@ function push () {
973
995
if ( Array . isArray ( parent ) ) {
974
996
parent . push ( value )
975
997
} else {
976
- parent [ key ] = value
998
+ Object . defineProperty ( parent , key , {
999
+ value,
1000
+ writable : true ,
1001
+ enumerable : true ,
1002
+ configurable : true ,
1003
+ } )
977
1004
}
978
1005
}
979
1006
0 commit comments