@@ -15,15 +15,15 @@ const reserved =
15
15
/**
16
16
* Turn a value into the JavaScript that creates an equivalent value
17
17
* @param {any } value
18
- * @param {(value: any, callback: (value: any) => any ) => string | void } [replacer]
18
+ * @param {(value: any) => string | void } [replacer]
19
19
*/
20
20
export function uneval ( value , replacer ) {
21
21
const counts = new Map ( ) ;
22
22
23
23
/** @type {string[] } */
24
24
const keys = [ ] ;
25
25
26
- const custom = new Set ( ) ;
26
+ const custom = new Map ( ) ;
27
27
28
28
/** @param {any } thing */
29
29
function walk ( thing ) {
@@ -40,13 +40,10 @@ export function uneval(value, replacer) {
40
40
counts . set ( thing , 1 ) ;
41
41
42
42
if ( replacer ) {
43
- const str = replacer ( thing , ( child ) => {
44
- walk ( child ) ;
45
- return '<pending>' ;
46
- } ) ;
43
+ const str = replacer ( thing ) ;
47
44
48
45
if ( typeof str === 'string' ) {
49
- custom . add ( thing ) ;
46
+ custom . set ( thing , str ) ;
50
47
return ;
51
48
}
52
49
}
@@ -133,8 +130,7 @@ export function uneval(value, replacer) {
133
130
}
134
131
135
132
if ( custom . has ( thing ) ) {
136
- const str = replacer ( thing , stringify ) ;
137
- if ( typeof str === 'string' ) return str ;
133
+ return custom . get ( thing ) ;
138
134
}
139
135
140
136
const type = get_type ( thing ) ;
@@ -195,7 +191,7 @@ export function uneval(value, replacer) {
195
191
params . push ( name ) ;
196
192
197
193
if ( custom . has ( thing ) ) {
198
- values . push ( /** @type {string } */ ( replacer ( thing , stringify ) ) ) ;
194
+ values . push ( /** @type {string } */ ( custom . get ( thing ) ) ) ;
199
195
return ;
200
196
}
201
197
0 commit comments