@@ -1296,7 +1296,7 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
1296
1296
1297
1297
function $resolvePromise$ (
1298
1298
promise : Promise < unknown > ,
1299
- $addRoot$ : ( obj : unknown ) => string | number ,
1299
+ $addRoot$ : ( obj : unknown ) => number ,
1300
1300
classCreator : ( resolved : boolean , resolvedValue : unknown ) => PromiseResult
1301
1301
) {
1302
1302
const forwardRefId = forwardRefsId ++ ;
@@ -1315,44 +1315,50 @@ async function serialize(serializationContext: SerializationContext): Promise<vo
1315
1315
return forwardRefId ;
1316
1316
}
1317
1317
1318
- $writer$ . write ( '[' ) ;
1318
+ const outputRoots = async ( ) => {
1319
+ $writer$ . write ( '[' ) ;
1319
1320
1320
- let lastRootsLength = 0 ;
1321
- let rootsLength = serializationContext . $roots$ . length ;
1322
- while ( lastRootsLength < rootsLength || promises . size ) {
1323
- if ( lastRootsLength !== 0 ) {
1324
- $writer$ . write ( ',' ) ;
1325
- }
1326
- for ( let i = lastRootsLength ; i < rootsLength ; i ++ ) {
1327
- const root = serializationContext . $roots$ [ i ] ;
1328
- writeValue ( root ) ;
1329
- const isLast = i === rootsLength - 1 ;
1330
- if ( ! isLast ) {
1321
+ let lastRootsLength = 0 ;
1322
+ let rootsLength = serializationContext . $roots$ . length ;
1323
+ while ( lastRootsLength < rootsLength || promises . size ) {
1324
+ if ( lastRootsLength !== 0 ) {
1331
1325
$writer$ . write ( ',' ) ;
1332
1326
}
1333
- }
1334
1327
1335
- if ( promises . size ) {
1336
- try {
1337
- await Promise . race ( promises ) ;
1338
- } catch {
1339
- // ignore rejections, they will be serialized as rejected promises
1328
+ let separator = false ;
1329
+ for ( let i = lastRootsLength ; i < rootsLength ; i ++ ) {
1330
+ if ( separator ) {
1331
+ $writer$ . write ( ',' ) ;
1332
+ } else {
1333
+ separator = true ;
1334
+ }
1335
+ writeValue ( serializationContext . $roots$ [ i ] ) ;
1336
+ }
1337
+
1338
+ if ( promises . size ) {
1339
+ try {
1340
+ await Promise . race ( promises ) ;
1341
+ } catch {
1342
+ // ignore rejections, they will be serialized as rejected promises
1343
+ }
1340
1344
}
1345
+
1346
+ lastRootsLength = rootsLength ;
1347
+ rootsLength = serializationContext . $roots$ . length ;
1341
1348
}
1342
1349
1343
- lastRootsLength = rootsLength ;
1344
- rootsLength = serializationContext . $roots$ . length ;
1345
- }
1350
+ if ( forwardRefs . length ) {
1351
+ $writer$ . write ( ',' ) ;
1352
+ $writer$ . write ( TypeIds . ForwardRefs + ',' ) ;
1353
+ outputArray ( forwardRefs , ( value ) => {
1354
+ $writer$ . write ( String ( value ) ) ;
1355
+ } ) ;
1356
+ }
1346
1357
1347
- if ( forwardRefs . length ) {
1348
- $writer$ . write ( ',' ) ;
1349
- $writer$ . write ( TypeIds . ForwardRefs + ',' ) ;
1350
- outputArray ( forwardRefs , ( value ) => {
1351
- $writer$ . write ( String ( value ) ) ;
1352
- } ) ;
1353
- }
1358
+ $writer$ . write ( ']' ) ;
1359
+ } ;
1354
1360
1355
- $writer$ . write ( ']' ) ;
1361
+ await outputRoots ( ) ;
1356
1362
}
1357
1363
1358
1364
function $getCustomSerializerPromise$ < T , S > ( signal : SerializerSignalImpl < T , S > , value : any ) {
0 commit comments