Repository navigation
Commit f91f72d
authored
feat(syntax): read structure through Field and Flag on the node path (#22579)
* feat(syntax): read structure through Field and Flag on the node path
CSS and HTML paths gain field, fieldCount, fieldAt, fieldNamed and flag,
read with the Field and Flag enums each language exports beside NodeType.
They replace declarations, rules and important on CSS and attributeCount,
attribute, findAttribute, templateContent and selfClosing on HTML; the CSS
minifier keeps reading a block as an array through internal readers.
* fix(syntax): answer fields and flags only for the node that owns them
A CSS leaf's id can be a reused declaration's, whose important bit stays
set, so flag now answers for containers only. HTML reads the attribute run
of an element only, and both fieldAt reject a negative index.
* feat(syntax): type each visitor's path by the node types it visits
SourceProcessor takes a language's parts table, and a visitor registered
for some node types gets a path whose field, fieldCount, fieldAt,
fieldNamed and flag accept only the parts those types have. Reading
attributes in a Comment visitor, or off an attribute, fails to type-check;
a node of unknown type still takes any part.
* refactor(syntax): read fields with field(i, F) and part positions with rangeOf(Part)
A single-node field reads as a list of at most one, so `field(i, F, n)`
replaces `field` and `fieldAt`, matching `child(i, n)`. `rangeOf(Part, n)`
replaces `nameRange`, `valueRange`, `contentRange` and `blockRange`, typed by
node type like fields and flags.
* test(css): cover folding an !important longhand into its shorthand
* refactor(syntax): read every grammar-specific detail through generic members
A node path has no member of its own per language: an element's namespace
and CSS's type flags are flags, an element's tags and a doctype's
identifiers are parts read with rangeOf and textOf, a dimension's unit is
its name and a simple block's bracket its value, and within(type) replaces
inValue for any ancestor type.
* test(syntax): cover the parts a node lacks and a spaced ICSS import
* feat(syntax): hand every visitor the run's state as path.state, typed by the processor
process(src, { state }) sets path.state for the length of the run and puts
the caller's back after. The processor's TState types it in every visitor,
array, literal map and node printer alike, and process takes only that
shape; each language's visitor map is generic in it.
* refactor(syntax): read nodes in CssParser and HtmlParser through the public path only
Both parsers now use the members a plugin has, nothing from the parser's
internals. Positions stay allocation-free through start/end and
startOf/endOf(Part), beside acorn's range; children(n) returns a node's
children as an array. A streamed rule records its block start before its
enter runs, and under skip.text a raw-text body ends at its end tag even
when that tag has attributes.1 parent 6ee97b8 commit f91f72d
27 files changed
Lines changed: 3874 additions & 1308 deletions
File tree
- docs
- lib
- css
- html
- util
- test
- configCases
- css/pseudo-import-spaced
- html/minimize-round-trip
- process-assets/html-plugin
- helpers
- specCases
- unitCases
- tooling
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
171 | 171 | | |
172 | 172 | | |
173 | 173 | | |
| 174 | + | |
174 | 175 | | |
175 | | - | |
176 | 176 | | |
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
180 | 180 | | |
181 | 181 | | |
| 182 | + | |
182 | 183 | | |
183 | 184 | | |
184 | 185 | | |
| |||
193 | 194 | | |
194 | 195 | | |
195 | 196 | | |
| 197 | + | |
196 | 198 | | |
197 | 199 | | |
198 | 200 | | |
| |||
217 | 219 | | |
218 | 220 | | |
219 | 221 | | |
| 222 | + | |
220 | 223 | | |
221 | 224 | | |
222 | 225 | | |
| |||
2248 | 2251 | | |
2249 | 2252 | | |
2250 | 2253 | | |
2251 | | - | |
| 2254 | + | |
2252 | 2255 | | |
2253 | 2256 | | |
2254 | | - | |
| 2257 | + | |
2255 | 2258 | | |
2256 | 2259 | | |
2257 | 2260 | | |
| |||
4762 | 4765 | | |
4763 | 4766 | | |
4764 | 4767 | | |
4765 | | - | |
| 4768 | + | |
4766 | 4769 | | |
4767 | 4770 | | |
4768 | 4771 | | |
| |||
4780 | 4783 | | |
4781 | 4784 | | |
4782 | 4785 | | |
4783 | | - | |
| 4786 | + | |
4784 | 4787 | | |
4785 | 4788 | | |
4786 | 4789 | | |
| |||
4809 | 4812 | | |
4810 | 4813 | | |
4811 | 4814 | | |
4812 | | - | |
| 4815 | + | |
4813 | 4816 | | |
4814 | 4817 | | |
4815 | 4818 | | |
| |||
4862 | 4865 | | |
4863 | 4866 | | |
4864 | 4867 | | |
4865 | | - | |
| 4868 | + | |
4866 | 4869 | | |
4867 | 4870 | | |
4868 | 4871 | | |
4869 | 4872 | | |
4870 | 4873 | | |
4871 | 4874 | | |
4872 | 4875 | | |
4873 | | - | |
| 4876 | + | |
4874 | 4877 | | |
4875 | 4878 | | |
4876 | 4879 | | |
| |||
4910 | 4913 | | |
4911 | 4914 | | |
4912 | 4915 | | |
4913 | | - | |
| 4916 | + | |
4914 | 4917 | | |
4915 | 4918 | | |
4916 | 4919 | | |
| |||
4965 | 4968 | | |
4966 | 4969 | | |
4967 | 4970 | | |
4968 | | - | |
| 4971 | + | |
4969 | 4972 | | |
4970 | 4973 | | |
4971 | 4974 | | |
| |||
4975 | 4978 | | |
4976 | 4979 | | |
4977 | 4980 | | |
4978 | | - | |
| 4981 | + | |
4979 | 4982 | | |
4980 | 4983 | | |
4981 | 4984 | | |
4982 | 4985 | | |
4983 | 4986 | | |
4984 | 4987 | | |
4985 | 4988 | | |
4986 | | - | |
| 4989 | + | |
4987 | 4990 | | |
4988 | 4991 | | |
4989 | 4992 | | |
| |||
5013 | 5016 | | |
5014 | 5017 | | |
5015 | 5018 | | |
5016 | | - | |
| 5019 | + | |
5017 | 5020 | | |
5018 | 5021 | | |
5019 | 5022 | | |
5020 | 5023 | | |
5021 | 5024 | | |
5022 | 5025 | | |
5023 | | - | |
| 5026 | + | |
5024 | 5027 | | |
5025 | 5028 | | |
5026 | 5029 | | |
| |||
5064 | 5067 | | |
5065 | 5068 | | |
5066 | 5069 | | |
5067 | | - | |
| 5070 | + | |
5068 | 5071 | | |
5069 | 5072 | | |
5070 | 5073 | | |
| |||
5184 | 5187 | | |
5185 | 5188 | | |
5186 | 5189 | | |
5187 | | - | |
| 5190 | + | |
5188 | 5191 | | |
5189 | 5192 | | |
5190 | 5193 | | |
| |||
5198 | 5201 | | |
5199 | 5202 | | |
5200 | 5203 | | |
5201 | | - | |
| 5204 | + | |
5202 | 5205 | | |
5203 | 5206 | | |
5204 | 5207 | | |
| |||
5207 | 5210 | | |
5208 | 5211 | | |
5209 | 5212 | | |
5210 | | - | |
| 5213 | + | |
5211 | 5214 | | |
5212 | 5215 | | |
5213 | 5216 | | |
| |||
5249 | 5252 | | |
5250 | 5253 | | |
5251 | 5254 | | |
5252 | | - | |
| 5255 | + | |
5253 | 5256 | | |
5254 | 5257 | | |
5255 | 5258 | | |
5256 | 5259 | | |
5257 | | - | |
| 5260 | + | |
5258 | 5261 | | |
5259 | 5262 | | |
5260 | 5263 | | |
5261 | | - | |
| 5264 | + | |
5262 | 5265 | | |
5263 | 5266 | | |
5264 | 5267 | | |
| |||
5312 | 5315 | | |
5313 | 5316 | | |
5314 | 5317 | | |
5315 | | - | |
| 5318 | + | |
5316 | 5319 | | |
5317 | 5320 | | |
5318 | 5321 | | |
| |||
5418 | 5421 | | |
5419 | 5422 | | |
5420 | 5423 | | |
5421 | | - | |
| 5424 | + | |
5422 | 5425 | | |
5423 | 5426 | | |
5424 | 5427 | | |
| |||
5445 | 5448 | | |
5446 | 5449 | | |
5447 | 5450 | | |
5448 | | - | |
| 5451 | + | |
5449 | 5452 | | |
5450 | 5453 | | |
5451 | 5454 | | |
| |||
5487 | 5490 | | |
5488 | 5491 | | |
5489 | 5492 | | |
5490 | | - | |
| 5493 | + | |
5491 | 5494 | | |
5492 | 5495 | | |
5493 | 5496 | | |
| |||
5758 | 5761 | | |
5759 | 5762 | | |
5760 | 5763 | | |
5761 | | - | |
| 5764 | + | |
5762 | 5765 | | |
5763 | 5766 | | |
5764 | 5767 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
12 | 17 | | |
13 | 18 | | |
14 | 19 | | |
| |||
41 | 46 | | |
42 | 47 | | |
43 | 48 | | |
44 | | - | |
| 49 | + | |
| 50 | + | |
45 | 51 | | |
46 | 52 | | |
47 | 53 | | |
48 | 54 | | |
49 | 55 | | |
50 | | - | |
| 56 | + | |
51 | 57 | | |
52 | 58 | | |
53 | 59 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
723 | 723 | | |
724 | 724 | | |
725 | 725 | | |
| 726 | + | |
| 727 | + | |
726 | 728 | | |
727 | 729 | | |
728 | 730 | | |
| |||
772 | 774 | | |
773 | 775 | | |
774 | 776 | | |
775 | | - | |
| 777 | + | |
776 | 778 | | |
777 | | - | |
| 779 | + | |
778 | 780 | | |
779 | 781 | | |
780 | 782 | | |
| |||
791 | 793 | | |
792 | 794 | | |
793 | 795 | | |
794 | | - | |
| 796 | + | |
795 | 797 | | |
796 | 798 | | |
797 | 799 | | |
| |||
0 commit comments