| 691 | } |
| 692 | |
| 693 | function stringify(node: AstNode, depth = 0): string { |
| 694 | let css = class="st">'' |
| 695 | let indent = class="st">' '.repeat(depth) |
| 696 | |
| 697 | class="cm">// Declaration |
| 698 | if (node.kind === class="st">'declaration') { |
| 699 | css += `${indent}${node.property}: ${node.value}${node.important ? class="st">' !important' : class="st">''};\n` |
| 700 | |
| 701 | if (track) { |
| 702 | class="cm">// indent |
| 703 | pos += indent.length |
| 704 | |
| 705 | class="cm">// node.property |
| 706 | let start = pos |
| 707 | pos += node.property.length |
| 708 | |
| 709 | class="cm">// `: ` |
| 710 | pos += 2 |
| 711 | |
| 712 | class="cm">// node.value |
| 713 | pos += node.value?.length ?? 0 |
| 714 | |
| 715 | class="cm">// !important |
| 716 | if (node.important) { |
| 717 | pos += 11 |
| 718 | } |
| 719 | |
| 720 | let end = pos |
| 721 | |
| 722 | class="cm">// `;\n` |
| 723 | pos += 2 |
| 724 | |
| 725 | node.dst = [source, start, end] |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | class="cm">// Rule |
| 730 | else if (node.kind === class="st">'rule') { |
| 731 | css += `${indent}${node.selector} {\n` |
| 732 | |
| 733 | if (track) { |
| 734 | class="cm">// indent |
| 735 | pos += indent.length |
| 736 | |
| 737 | class="cm">// node.selector |
| 738 | let start = pos |
| 739 | pos += node.selector.length |
| 740 | |
| 741 | class="cm">// ` ` |
| 742 | pos += 1 |
| 743 | |
| 744 | let end = pos |
| 745 | node.dst = [source, start, end] |
| 746 | |
| 747 | class="cm">// `{\n` |
| 748 | pos += 2 |
| 749 | } |
| 750 | |