File tree Expand file tree Collapse file tree 3 files changed +29
-19
lines changed Expand file tree Collapse file tree 3 files changed +29
-19
lines changed Original file line number Diff line number Diff line change @@ -45,8 +45,14 @@ export function parse(serialized) {
45
45
case 'Set' :
46
46
const set = new Set ( ) ;
47
47
values [ i ] = set ;
48
- for ( let j = 1 ; j < value . length ; j += 1 ) {
49
- set . add ( get_value ( value [ j ] ) ) ;
48
+ for ( const n of value [ 1 ] ) set . add ( get_value ( n ) ) ;
49
+ break ;
50
+
51
+ case 'Map' :
52
+ const map = new Map ( ) ;
53
+ values [ i ] = map ;
54
+ for ( let i = 0 ; i < value [ 1 ] . length ; i += 2 ) {
55
+ map . set ( get_value ( value [ i ] ) , get_value ( value [ i + 1 ] ) ) ;
50
56
}
51
57
break ;
52
58
@@ -90,6 +96,5 @@ export function parse(serialized) {
90
96
}
91
97
}
92
98
93
- console . log ( values ) ;
94
99
return values [ 0 ] ;
95
100
}
Original file line number Diff line number Diff line change @@ -132,21 +132,25 @@ export function stringify(value) {
132
132
) ;
133
133
}
134
134
135
- /** @type {string[] } */
136
- const flattened_object = [ ] ;
137
-
138
- for ( const key in thing ) {
139
- keys . push ( `.${ key } ` ) ;
140
- flattened_object . push (
141
- `${ stringify_string ( key ) } :${ flatten ( thing [ key ] ) } `
142
- ) ;
143
- keys . pop ( ) ;
144
- }
145
-
146
- stringified [ index ] = `{${ flattened_object . join ( ',' ) } }` ;
147
-
148
135
if ( Object . getPrototypeOf ( thing ) === null ) {
149
- stringified [ index ] = `["null",${ stringified [ index ] } ]` ;
136
+ let str = '["null"' ;
137
+ for ( const key in thing ) {
138
+ keys . push ( `.${ key } ` ) ;
139
+ str += `,${ stringify_string ( key ) } ,${ flatten ( thing [ key ] ) } ` ;
140
+ keys . pop ( ) ;
141
+ }
142
+ stringified [ index ] = str + ']' ;
143
+ } else {
144
+ let str = '{' ;
145
+ let started = false ;
146
+ for ( const key in thing ) {
147
+ if ( started ) str += ',' ;
148
+ started = true ;
149
+ keys . push ( `.${ key } ` ) ;
150
+ str += `${ stringify_string ( key ) } :${ flatten ( thing [ key ] ) } ` ;
151
+ keys . pop ( ) ;
152
+ }
153
+ stringified [ index ] = str + '}' ;
150
154
}
151
155
}
152
156
}
Original file line number Diff line number Diff line change
1
+ import * as util from 'util' ;
1
2
import * as vm from 'vm' ;
2
3
import * as assert from 'uvu/assert' ;
3
4
import * as uvu from 'uvu' ;
@@ -256,7 +257,7 @@ const fixtures = {
256
257
name : 'Object with null prototype (cyclical)' ,
257
258
value : obj ,
258
259
js : '(function(a){a.self=a;return a}(Object.create(null)))' ,
259
- json : '[["null",{ "self":0} ]]'
260
+ json : '[["null","self",0 ]]'
260
261
} ;
261
262
} ) ( Object . create ( null ) ) ,
262
263
@@ -307,7 +308,7 @@ const fixtures = {
307
308
name : 'Object without prototype' ,
308
309
value : Object . create ( null ) ,
309
310
js : 'Object.create(null)' ,
310
- json : '[["null",{} ]]'
311
+ json : '[["null"]]'
311
312
} ,
312
313
{
313
314
name : 'cross-realm POJO' ,
You can’t perform that action at this time.
0 commit comments