UNPKG

ts-fusion-parser

Version:

Parser for Neos Fusion Files

55 lines (54 loc) 1.65 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AbstractNode = void 0; class AbstractNode { constructor(position, parent = undefined) { this.position = position; this.parent = parent; this.position = position; this.parent = parent; } debugPrint(name = '', withGroup = true) { if (withGroup) console.group(this.constructor.name + (name !== '' ? `[${name}]` : '') + (this.position ? this.debugPositionToString() : '')); this.debugPrintInner(); if (withGroup) console.groupEnd(); } static setParentOfNode(node, parent) { node.parent = parent; } toString(intend = 0) { return ' '.repeat(intend) + `<${this.constructor.name}>`; } debugPositionToString() { return `Pos: begin ${this.position.begin} end ${this.position.end}`; } debugPrintInner() { for (const [name, value] of Object.entries(this)) { if (value === undefined) { continue; } if (Array.isArray(value)) { for (const entry of value) { this.debugPrintValue(entry, name); } } else { this.debugPrintValue(value, name); } } } debugPrintValue(value, name) { if (name === "position") { return; } if (value instanceof AbstractNode) { value.debugPrint(name); } else { console.log(`|-${name}`, value); } } } exports.AbstractNode = AbstractNode;