From f42763c081f5a7446cf94c1c9c026bf194f19f60 Mon Sep 17 00:00:00 2001 From: "Alexis H. Munsayac" Date: Wed, 6 Dec 2023 12:15:34 +0800 Subject: [PATCH] Update deserializer.ts --- .../seroval/src/core/context/deserializer.ts | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/seroval/src/core/context/deserializer.ts b/packages/seroval/src/core/context/deserializer.ts index 93496896..72f0691a 100644 --- a/packages/seroval/src/core/context/deserializer.ts +++ b/packages/seroval/src/core/context/deserializer.ts @@ -1,4 +1,3 @@ -/* eslint-disable prefer-spread */ import { deserializeString } from '../string'; import type { BigIntTypedArrayValue, TypedArrayValue } from '../../types'; import { getReference } from '../reference'; @@ -7,12 +6,14 @@ import type { SerovalArrayBufferNode, SerovalArrayNode, SerovalAsyncIteratorFactoryInstanceNode, + SerovalAsyncIteratorFactoryNode, SerovalBigIntTypedArrayNode, SerovalBoxedNode, SerovalDataViewNode, SerovalDateNode, SerovalErrorNode, SerovalIteratorFactoryInstanceNode, + SerovalIteratorFactoryNode, SerovalMapNode, SerovalNode, SerovalNullConstructorNode, @@ -331,6 +332,7 @@ 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); } @@ -338,6 +340,7 @@ export default abstract class BaseDeserializerContext implements PluginAccessOpt private deserializeAsyncIteratorFactoryInstance( node: SerovalAsyncIteratorFactoryInstanceNode, ): unknown { + this.deserialize(node.a[0]); const source = this.deserialize(node.a[1]); return streamToAsyncIterable(source as Stream); } @@ -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: @@ -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'); }