UNPKG

ts-fusion-parser

Version:

Parser for Neos Fusion Files

33 lines (32 loc) 1.62 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.TagNode = void 0; const AbstractNode_1 = require("../../../common/AbstractNode"); class TagNode extends AbstractNode_1.AbstractNode { constructor(position, name, begin, attributes, content, end = undefined, selfClosing = false, parent = undefined) { super(position, parent); this.artificiallyClosed = false; this.name = name; this.begin = begin; AbstractNode_1.AbstractNode.setParentOfNode(this.begin, this); this.end = end; if (this.end) AbstractNode_1.AbstractNode.setParentOfNode(this.end, this); this.attributes = attributes; for (const attribute of this.attributes) AbstractNode_1.AbstractNode.setParentOfNode(attribute, this); this.content = content; for (const content of this.content) AbstractNode_1.AbstractNode.setParentOfNode(content, this); this.selfClosing = selfClosing; } toString(intend = 0) { const attributes = this.attributes.length > 0 ? " " + this.attributes.map(a => a.toString()).join(" ") : ""; const strIntend = " ".repeat(intend); const strIntendC = " ".repeat(intend + 1); const content = this.content.map(c => c.toString(intend + 1)).join("\n" + strIntendC); const tagBody = content.length > 0 ? "\n" + strIntendC + content + "\n" + strIntend : ""; return `<${this.name}${attributes}${this.artificiallyClosed ? ">" : this.selfClosing ? " />" : `>${tagBody}</${this.name}>`}`; } } exports.TagNode = TagNode;