import type {JsonTokenType} from '../token'; import {JsonToken} from '../token'; import type {JsonNodeDefinition, PartialJsonNodeDefinition} from './node'; import {JsonNode} from './node'; export interface JsonTokenDefinition extends JsonNodeDefinition, JsonToken { } export class JsonTokenNode extends JsonNode implements JsonTokenDefinition { public readonly type: T; public readonly value: string; public constructor(definition: PartialJsonNodeDefinition>) { super(definition); this.type = definition.type; this.value = definition.value; } public isType(type: K): this is JsonTokenNode { return JsonToken.isType(this, type); } public clone(): JsonTokenNode { return new JsonTokenNode({ type: this.type, value: this.value, location: this.location, }); } public isEquivalent(other: JsonNode): boolean { return other instanceof JsonTokenNode && this.type === other.type && this.value === other.value; } public toString(): string { return this.value; } }