(node, indent = 0)
| 1417 | } |
| 1418 | |
| 1419 | static nodeToString(node, indent = 0) { |
| 1420 | const indentStr = '\t'.repeat(indent); |
| 1421 | |
| 1422 | let nodeDeclaration; |
| 1423 | if (node.label) { |
| 1424 | nodeDeclaration = `${indentStr}${node.label}: ${node.name} {\n`; |
| 1425 | } else { |
| 1426 | nodeDeclaration = `${indentStr}${node.name} {\n`; |
| 1427 | } |
| 1428 | |
| 1429 | let output = nodeDeclaration; |
| 1430 | |
| 1431 | // Properties |
| 1432 | for (const [propName, prop] of Object.entries(node.properties)) { |
| 1433 | output += `${indentStr}\t${propName}`; |
| 1434 | if (prop.value) { |
| 1435 | output += ` = ${DTSParser.valueToString(prop.value)}`; |
| 1436 | } |
| 1437 | output += ';\n'; |
| 1438 | } |
| 1439 | |
| 1440 | // Child nodes |
| 1441 | const childEntries = Object.entries(node.children); |
| 1442 | for (let i = 0; i < childEntries.length; i++) { |
| 1443 | const [, child] = childEntries[i]; |
| 1444 | if (i === 0 && Object.keys(node.properties).length > 0) { |
| 1445 | output += '\n'; |
| 1446 | } |
| 1447 | output += DTSParser.nodeToString(child, indent + 1); |
| 1448 | if (i < childEntries.length - 1) { |
| 1449 | output += '\n'; |
| 1450 | } |
| 1451 | } |
| 1452 | |
| 1453 | output += `${indentStr}};\n`; |
| 1454 | return output; |
| 1455 | } |
| 1456 | |
| 1457 | static valueToString(value) { |
| 1458 | if (!value) return ''; |
no test coverage detected