Skip to content

Commit

Permalink
Update deserializer.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
lxsmnsyc committed Dec 6, 2023
1 parent 346020a commit f42763c
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions packages/seroval/src/core/context/deserializer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable prefer-spread */
import { deserializeString } from '../string';
import type { BigIntTypedArrayValue, TypedArrayValue } from '../../types';
import { getReference } from '../reference';
Expand All @@ -7,12 +6,14 @@ import type {
SerovalArrayBufferNode,
SerovalArrayNode,
SerovalAsyncIteratorFactoryInstanceNode,
SerovalAsyncIteratorFactoryNode,
SerovalBigIntTypedArrayNode,
SerovalBoxedNode,
SerovalDataViewNode,
SerovalDateNode,
SerovalErrorNode,
SerovalIteratorFactoryInstanceNode,
SerovalIteratorFactoryNode,
SerovalMapNode,
SerovalNode,
SerovalNullConstructorNode,
Expand Down Expand Up @@ -331,13 +332,15 @@ export default abstract class BaseDeserializerContext implements PluginAccessOpt
private deserializeIteratorFactoryInstance(
node: SerovalIteratorFactoryInstanceNode,
): unknown {
this.deserialize(node.a[0]);
const source = this.deserialize(node.a[1]);
return sequenceToIterator(source as Sequence);
}

private deserializeAsyncIteratorFactoryInstance(
node: SerovalAsyncIteratorFactoryInstanceNode,
): unknown {
this.deserialize(node.a[0]);
const source = this.deserialize(node.a[1]);
return streamToAsyncIterable(source as Stream<any>);
}
Expand Down Expand Up @@ -391,6 +394,20 @@ export default abstract class BaseDeserializerContext implements PluginAccessOpt
return undefined;
}

private deserializeIteratorFactory(
node: SerovalIteratorFactoryNode,
): unknown {
this.deserialize(node.f);
return undefined;
}

private deserializeAsyncIteratorFactory(
node: SerovalAsyncIteratorFactoryNode,
): unknown {
this.deserialize(node.a[1]);
return undefined;
}

deserialize(node: SerovalNode): unknown {
switch (node.t) {
case SerovalNodeType.Constant:
Expand Down Expand Up @@ -455,9 +472,11 @@ export default abstract class BaseDeserializerContext implements PluginAccessOpt
return this.deserializeStreamThrow(node);
case SerovalNodeType.StreamReturn:
return this.deserializeStreamReturn(node);
case SerovalNodeType.SpecialReference:
case SerovalNodeType.IteratorFactory:
return this.deserializeIteratorFactory(node);
case SerovalNodeType.AsyncIteratorFactory:
return this.deserializeAsyncIteratorFactory(node);
case SerovalNodeType.SpecialReference:
default:
throw new Error('invariant');
}
Expand Down

0 comments on commit f42763c

Please sign in to comment.