|
| 1 | +/* eslint-disable @typescript-eslint/no-unused-vars */ |
| 2 | +import type { Parsable } from "./parsable"; |
| 3 | +import type { ParseNode } from "./parseNode"; |
| 4 | +import type { SerializationWriter } from "./serializationWriter"; |
| 5 | + |
| 6 | +/** Defines the base interface for defining an untyped node. */ |
| 7 | +export interface UntypedNode extends Parsable { |
| 8 | + /** |
| 9 | + * Gets the value of the UntypedNode. |
| 10 | + */ |
| 11 | + getValue(): any; |
| 12 | + /** |
| 13 | + * The value represented by the UntypedNode. |
| 14 | + */ |
| 15 | + value?: any; |
| 16 | +} |
| 17 | + |
| 18 | +/** |
| 19 | + * Factory to create an UntypedNode from a string during deserialization. |
| 20 | + */ |
| 21 | +export function createUntypedNodeFromDiscriminatorValue( |
| 22 | + _parseNode: ParseNode | undefined, |
| 23 | +): (instance?: Parsable) => Record<string, (node: ParseNode) => void> { |
| 24 | + return deserializeIntoUntypedNode; |
| 25 | +} |
| 26 | + |
| 27 | +/** |
| 28 | + * Type guard to assert that an object instance is an UntypedNode. |
| 29 | + * @param node The object to check. |
| 30 | + * @return boolean indicating if the node is an UntypedNode. |
| 31 | + */ |
| 32 | +export function isUntypedNode(node: any): node is UntypedNode { |
| 33 | + const potentialNode = node as UntypedNode; |
| 34 | + return potentialNode && potentialNode.getValue !== undefined; |
| 35 | +} |
| 36 | + |
| 37 | +/** |
| 38 | + * The deserialization implementation for UntypedNode. |
| 39 | + */ |
| 40 | +export function deserializeIntoUntypedNode( |
| 41 | + untypedNode: Partial<UntypedNode> | undefined = {}, |
| 42 | +): Record<string, (node: ParseNode) => void> { |
| 43 | + return { |
| 44 | + value: (n) => { |
| 45 | + untypedNode.value = null; |
| 46 | + }, |
| 47 | + getValue: (n) => { |
| 48 | + untypedNode.getValue = () => untypedNode.value; |
| 49 | + }, |
| 50 | + }; |
| 51 | +} |
| 52 | + |
| 53 | +/** |
| 54 | + * The serialization implementation for UntypedNode. |
| 55 | + */ |
| 56 | +export function serializeUntypedNode( |
| 57 | + _writer: SerializationWriter, |
| 58 | + _errorDetails: Partial<UntypedNode> | undefined = {}, |
| 59 | +): void { |
| 60 | + return; |
| 61 | +} |
0 commit comments