Repository navigation
Commit 8f10b8d
authored
fix: lossless mode drops whitespace when a selector ends empty (#337)
`space()` parks leading whitespace on `this.spaces` for the next node to claim,
and `newNode` is its only consumer. A selector that ends before any node is
created therefore loses it:
:not(a, ) -> :not(a,)
:not( ) -> :not()
a, -> a,
Two conditions route whitespace there: the previous token is a comma or an
opening parenthesis, or the selector so far holds nothing but comments. The
second is why `:not( /*c*/ )` also loses its trailing space.
Pending whitespace is now flushed wherever a selector can close: at a comma, at
a pseudo's closing parenthesis, and at end of input. It attaches to the last
node's `spaces.after` when there is one, otherwise to an empty string node,
matching what `parseWhitespaceEquivalentTokens` already does.
Lossy output is unchanged. Across 480 generated selectors: 240 newly
round-trip, no regressions, and `lossless: false` is byte-identical to before.
Fixes #2981 parent 15c2b45 commit 8f10b8d
2 files changed
Lines changed: 49 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
184 | 184 | | |
185 | 185 | | |
186 | 186 | | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
641 | 641 | | |
642 | 642 | | |
643 | 643 | | |
| 644 | + | |
| 645 | + | |
| 646 | + | |
| 647 | + | |
| 648 | + | |
| 649 | + | |
| 650 | + | |
| 651 | + | |
| 652 | + | |
| 653 | + | |
| 654 | + | |
| 655 | + | |
| 656 | + | |
| 657 | + | |
| 658 | + | |
| 659 | + | |
| 660 | + | |
| 661 | + | |
| 662 | + | |
| 663 | + | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
| 668 | + | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
| 672 | + | |
644 | 673 | | |
| 674 | + | |
645 | 675 | | |
646 | 676 | | |
647 | 677 | | |
| |||
782 | 812 | | |
783 | 813 | | |
784 | 814 | | |
| 815 | + | |
785 | 816 | | |
786 | 817 | | |
787 | 818 | | |
| |||
1011 | 1042 | | |
1012 | 1043 | | |
1013 | 1044 | | |
| 1045 | + | |
1014 | 1046 | | |
1015 | 1047 | | |
1016 | 1048 | | |
| |||
0 commit comments