| 20 | this.child.push({ [key]: val }); |
| 21 | } |
| 22 | addChild(node, startIndex) { |
| 23 | if (node.tagname === "__proto__") node.tagname = "#__proto__"; |
| 24 | if (node[":@"] && Object.keys(node[":@"]).length > 0) { |
| 25 | this.child.push({ [node.tagname]: node.child, [":@"]: node[":@"] }); |
| 26 | } else { |
| 27 | this.child.push({ [node.tagname]: node.child }); |
| 28 | } |
| 29 | // if requested, add the startIndex |
| 30 | if (startIndex !== undefined) { |
| 31 | // Note: for now we just overwrite the metadata. If we had more complex metadata, |
| 32 | // we might need to do an object append here: metadata = { ...metadata, startIndex } |
| 33 | this.child[this.child.length - 1][METADATA_SYMBOL] = { startIndex }; |
| 34 | } |
| 35 | } |
| 36 | /** symbol used for metadata */ |
| 37 | static getMetaDataSymbol() { |
| 38 | return METADATA_SYMBOL; |