Commit 92e2fc1
feat: allow comments in tags (#17671)
Alternative to #17188. I prefer this syntax, it's lighter and feels much
more natural to me. For me it's less about commenting things _out_ than
about just, well... commenting — I frequently want to do this sort of
thing:
```svelte
<button
// when the user clicks the button, the thing should happen
onclick={doTheThing}
>click me</button>
```
One difference between this and #17188 is that this doesn't add a node
to the AST, just like comments in CSS/JS. Haven't decided if that's
desirable or not. I think it's more correct (it's an AST, not a CST;
HTML comments are different insofar as they _can_ represent 'real'
nodes) but it might be less convenient when (for example)
pretty-printing.
### Before submitting the PR, please make sure you do the following
- [x] It's really useful if your PR references an issue where it is
discussed ahead of time. In many cases, features are absent for a
reason. For large changes, please create an RFC:
https://github.com/sveltejs/rfcs
- [x] Prefix your PR title with `feat:`, `fix:`, `chore:`, or `docs:`.
- [x] This message body should clearly illustrate what problems it
solves.
- [x] Ideally, include a test that fails without this PR but passes with
it.
- [x] If this PR changes code within `packages/svelte/src`, add a
changeset (`npx changeset`).
### Tests and linting
- [x] Run the tests with `pnpm test` and lint the project with `pnpm
lint`
---------
Co-authored-by: Simon H <5968653+dummdidumm@users.noreply.github.com>1 parent 2661513 commit 92e2fc1
File tree
9 files changed
+892
-37
lines changed- .changeset
- packages/svelte
- src/compiler
- phases/1-parse/state
- print
- tests
- parser-legacy/samples
- javascript-comments
- script-comment-only
- parser-modern
- samples/comment-in-tag
9 files changed
+892
-37
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
105 | 110 | | |
106 | 111 | | |
107 | 112 | | |
| |||
Lines changed: 53 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
506 | 506 | | |
507 | 507 | | |
508 | 508 | | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
509 | 518 | | |
510 | 519 | | |
511 | 520 | | |
| |||
702 | 711 | | |
703 | 712 | | |
704 | 713 | | |
| 714 | + | |
| 715 | + | |
| 716 | + | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
| 720 | + | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
| 726 | + | |
| 727 | + | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
| 731 | + | |
| 732 | + | |
| 733 | + | |
| 734 | + | |
| 735 | + | |
| 736 | + | |
| 737 | + | |
| 738 | + | |
| 739 | + | |
| 740 | + | |
| 741 | + | |
| 742 | + | |
| 743 | + | |
| 744 | + | |
| 745 | + | |
| 746 | + | |
| 747 | + | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
705 | 758 | | |
706 | 759 | | |
707 | 760 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
21 | 23 | | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | | - | |
| 27 | + | |
26 | 28 | | |
27 | 29 | | |
28 | 30 | | |
29 | | - | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
| 62 | + | |
60 | 63 | | |
61 | 64 | | |
| 65 | + | |
62 | 66 | | |
63 | 67 | | |
64 | | - | |
| 68 | + | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
68 | 72 | | |
69 | | - | |
70 | | - | |
| 73 | + | |
71 | 74 | | |
72 | | - | |
73 | | - | |
74 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
75 | 79 | | |
76 | 80 | | |
77 | | - | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
78 | 112 | | |
79 | 113 | | |
| 114 | + | |
80 | 115 | | |
81 | | - | |
| 116 | + | |
82 | 117 | | |
83 | | - | |
| 118 | + | |
84 | 119 | | |
85 | 120 | | |
86 | 121 | | |
87 | 122 | | |
88 | | - | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
89 | 128 | | |
90 | 129 | | |
91 | 130 | | |
| |||
94 | 133 | | |
95 | 134 | | |
96 | 135 | | |
| 136 | + | |
97 | 137 | | |
98 | | - | |
| 138 | + | |
99 | 139 | | |
100 | 140 | | |
101 | 141 | | |
| |||
111 | 151 | | |
112 | 152 | | |
113 | 153 | | |
114 | | - | |
| 154 | + | |
115 | 155 | | |
116 | 156 | | |
117 | 157 | | |
| |||
284 | 324 | | |
285 | 325 | | |
286 | 326 | | |
287 | | - | |
288 | | - | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
289 | 332 | | |
290 | 333 | | |
291 | 334 | | |
| |||
315 | 358 | | |
316 | 359 | | |
317 | 360 | | |
318 | | - | |
| 361 | + | |
319 | 362 | | |
320 | 363 | | |
321 | 364 | | |
| |||
545 | 588 | | |
546 | 589 | | |
547 | 590 | | |
548 | | - | |
| 591 | + | |
549 | 592 | | |
550 | 593 | | |
551 | 594 | | |
| |||
681 | 724 | | |
682 | 725 | | |
683 | 726 | | |
684 | | - | |
| 727 | + | |
685 | 728 | | |
686 | 729 | | |
687 | 730 | | |
| |||
691 | 734 | | |
692 | 735 | | |
693 | 736 | | |
694 | | - | |
| 737 | + | |
695 | 738 | | |
696 | 739 | | |
697 | 740 | | |
| |||
747 | 790 | | |
748 | 791 | | |
749 | 792 | | |
750 | | - | |
| 793 | + | |
751 | 794 | | |
752 | 795 | | |
753 | 796 | | |
| |||
774 | 817 | | |
775 | 818 | | |
776 | 819 | | |
777 | | - | |
| 820 | + | |
778 | 821 | | |
779 | 822 | | |
780 | 823 | | |
| |||
783 | 826 | | |
784 | 827 | | |
785 | 828 | | |
786 | | - | |
| 829 | + | |
787 | 830 | | |
788 | 831 | | |
789 | 832 | | |
| |||
794 | 837 | | |
795 | 838 | | |
796 | 839 | | |
797 | | - | |
| 840 | + | |
798 | 841 | | |
799 | 842 | | |
800 | 843 | | |
| |||
803 | 846 | | |
804 | 847 | | |
805 | 848 | | |
806 | | - | |
| 849 | + | |
807 | 850 | | |
808 | 851 | | |
809 | 852 | | |
| |||
815 | 858 | | |
816 | 859 | | |
817 | 860 | | |
818 | | - | |
| 861 | + | |
819 | 862 | | |
820 | 863 | | |
821 | 864 | | |
822 | | - | |
| 865 | + | |
823 | 866 | | |
824 | 867 | | |
825 | 868 | | |
826 | | - | |
| 869 | + | |
827 | 870 | | |
828 | 871 | | |
829 | 872 | | |
830 | | - | |
| 873 | + | |
831 | 874 | | |
832 | 875 | | |
833 | 876 | | |
834 | 877 | | |
835 | 878 | | |
836 | 879 | | |
837 | 880 | | |
838 | | - | |
| 881 | + | |
839 | 882 | | |
840 | 883 | | |
841 | 884 | | |
| |||
865 | 908 | | |
866 | 909 | | |
867 | 910 | | |
868 | | - | |
| 911 | + | |
0 commit comments