@@ -15,14 +15,16 @@ 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) => string | void } replacer
18
+ * @param {(value: any, callback: (value: any ) => 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 ( ) ;
27
+
26
28
/** @param {any } thing */
27
29
function walk ( thing ) {
28
30
if ( typeof thing === 'function' ) {
@@ -37,6 +39,18 @@ export function uneval(value, replacer) {
37
39
38
40
counts . set ( thing , 1 ) ;
39
41
42
+ if ( replacer ) {
43
+ const str = replacer ( thing , ( child ) => {
44
+ walk ( child ) ;
45
+ return '<pending>' ;
46
+ } ) ;
47
+
48
+ if ( typeof str === 'string' ) {
49
+ custom . add ( thing ) ;
50
+ return ;
51
+ }
52
+ }
53
+
40
54
const type = get_type ( thing ) ;
41
55
42
56
switch ( type ) {
@@ -118,6 +132,11 @@ export function uneval(value, replacer) {
118
132
return stringify_primitive ( thing ) ;
119
133
}
120
134
135
+ if ( custom . has ( thing ) ) {
136
+ const str = replacer ( thing , stringify ) ;
137
+ if ( typeof str === 'string' ) return str ;
138
+ }
139
+
121
140
const type = get_type ( thing ) ;
122
141
123
142
switch ( type ) {
@@ -175,6 +194,11 @@ export function uneval(value, replacer) {
175
194
names . forEach ( ( name , thing ) => {
176
195
params . push ( name ) ;
177
196
197
+ if ( custom . has ( thing ) ) {
198
+ values . push ( /** @type {string } */ ( replacer ( thing , stringify ) ) ) ;
199
+ return ;
200
+ }
201
+
178
202
if ( is_primitive ( thing ) ) {
179
203
values . push ( stringify_primitive ( thing ) ) ;
180
204
return ;
0 commit comments