@@ -12,6 +12,7 @@ import {
1212 createNumberNode ,
1313 createPluginNode ,
1414 createRegExpNode ,
15+ createSequenceNode ,
1516 createSetNode ,
1617 createStreamConstructorNode ,
1718 createStreamNextNode ,
@@ -27,6 +28,11 @@ import { FALSE_NODE, NULL_NODE, TRUE_NODE, UNDEFINED_NODE } from '../literals';
2728import { createSerovalNode } from '../node' ;
2829import { OpaqueReference } from '../opaque-reference' ;
2930import type { SerovalMode } from '../plugin' ;
31+ import {
32+ createSequenceFromIterable ,
33+ isSequence ,
34+ type Sequence ,
35+ } from '../sequence' ;
3036import { SpecialReference } from '../special-reference' ;
3137import type { Stream } from '../stream' ;
3238import { createStreamFromAsyncIterable , isStream } from '../stream' ;
@@ -46,18 +52,19 @@ import type {
4652 SerovalErrorNode ,
4753 SerovalMapNode ,
4854 SerovalNode ,
55+ SerovalNodeWithID ,
4956 SerovalNullConstructorNode ,
5057 SerovalObjectNode ,
5158 SerovalObjectRecordKey ,
5259 SerovalObjectRecordNode ,
5360 SerovalPluginNode ,
5461 SerovalPromiseNode ,
62+ SerovalSequenceNode ,
5563 SerovalSetNode ,
5664 SerovalStreamConstructorNode ,
5765 SerovalTypedArrayNode ,
5866} from '../types' ;
5967import { getErrorOptions } from '../utils/error' ;
60- import { iteratorToSequence } from '../utils/iterator-to-sequence' ;
6168import promiseToResult from '../utils/promise-to-result' ;
6269import type {
6370 BigIntTypedArrayValue ,
@@ -155,11 +162,13 @@ async function parseProperties(
155162 valueNodes . push (
156163 createIteratorFactoryInstanceNode (
157164 parseIteratorFactory ( ctx . base ) ,
158- await parseAsync (
165+ ( await parseAsync (
159166 ctx ,
160167 depth ,
161- iteratorToSequence ( properties as unknown as Iterable < unknown > ) ,
162- ) ,
168+ createSequenceFromIterable (
169+ properties as unknown as Iterable < unknown > ,
170+ ) ,
171+ ) ) as SerovalNodeWithID ,
163172 ) ,
164173 ) ;
165174 }
@@ -168,13 +177,13 @@ async function parseProperties(
168177 valueNodes . push (
169178 createAsyncIteratorFactoryInstanceNode (
170179 parseAsyncIteratorFactory ( ctx . base ) ,
171- await parseAsync (
180+ ( await parseAsync (
172181 ctx ,
173182 depth ,
174183 createStreamFromAsyncIterable (
175184 properties as unknown as AsyncIterable < unknown > ,
176185 ) ,
177- ) ,
186+ ) ) as SerovalNodeWithID ,
178187 ) ,
179188 ) ;
180189 }
@@ -435,6 +444,19 @@ async function parseStream(
435444 ) ;
436445}
437446
447+ async function parseSequence (
448+ ctx : AsyncParserContext ,
449+ depth : number ,
450+ id : number ,
451+ current : Sequence ,
452+ ) : Promise < SerovalSequenceNode > {
453+ const nodes : SerovalNode [ ] = [ ] ;
454+ for ( let i = 0 , len = current . v . length ; i < len ; i ++ ) {
455+ nodes [ i ] = await parseAsync ( ctx , depth , current . v [ i ] ) ;
456+ }
457+ return createSequenceNode ( id , nodes , current . t , current . d ) ;
458+ }
459+
438460export async function parseObjectAsync (
439461 ctx : AsyncParserContext ,
440462 depth : number ,
@@ -447,6 +469,9 @@ export async function parseObjectAsync(
447469 if ( isStream ( current ) ) {
448470 return parseStream ( ctx , depth , id , current ) ;
449471 }
472+ if ( isSequence ( current ) ) {
473+ return parseSequence ( ctx , depth , id , current ) ;
474+ }
450475 const currentClass = current . constructor ;
451476 if ( currentClass === OpaqueReference ) {
452477 return parseAsync (
0 commit comments