1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
// Block-comment extent — the single definition of how far a CSS comment reaches.
//
// The comment twin of [`crate::escapes::escape_len`], and it exists for the same reason:
// that answers "how far does this escape reach", this answers it for `/* … */`, and a
// scanner that gets either wrong reads the enclosed text as structure. CSS Syntax 3
// §4.3.2 (*consume comments*) is the rule, and two clauses of it are load-bearing here —
// it **returns nothing** (a comment produces no token, so its interior can never
// contribute a separator or a nesting change), and it runs "up to and including the first
// U+002A ASTERISK (*) followed by a U+002F SOLIDUS (/), **or up to an EOF code point**"
// (so an unterminated comment reaches end-of-input rather than erroring here).
//
// Every scanner that walks a value, prelude, or declaration for *structure* steps over a
// comment through this module rather than re-spelling the rule. It had been re-spelled
// eight times across the crate — as `find("*/")`, as a `skip_block_comment` byte loop, and
// as three separate `in_comment` state machines — which is how the value scanners came to
// disagree with the printer about where a comment ended.
/// Whether a block comment opens at `i`.
///
/// Bounds-checked on both bytes, so a caller may probe the final byte of a slice.
pub
/// The end of the block comment opening at `i` — the byte just after its `*/` — or `None`
/// when it is **unterminated**.
///
/// Take this one only when the unterminated case needs its own handling: a caller that
/// preserves a malformed comment verbatim (`ast::convert::strip_css_comments`) or abandons
/// a reconstruction (`value_normalization::extract_property_name`) cannot use
/// [`comment_end`], whose `bytes.len()` answer is the same for "ran off the end" and for a
/// comment whose `*/` legitimately ends at the last byte.
pub
/// The end of the block comment opening at `i` — the byte just after its `*/`, or
/// `bytes.len()` when it is unterminated (§4.3.2's "or up to an EOF code point").
///
/// The right choice for a *structure* scanner, which only needs to not read the interior
/// as structure and has no error to report. [`comment_end_checked`] is for the callers
/// that must tell the two cases apart.
///
/// A byte loop rather than `find("*/")` so no scanner grows a raw substring scan over
/// source (`deno task scan:audit`).
pub
/// The end of the block comment opening at the **start** of `s`, or `None` when none
/// does — the `&str` face of [`comment_end`], for a scanner that steps over a comment by
/// slicing rather than by byte index.
///
/// The end is a `*/` (or end-of-input) boundary and so always a char boundary, which is
/// what makes it safe to slice with.
pub
/// The end of the block-comment **run** opening at `i`, or `None` when no comment opens
/// there.
///
/// Consecutive comments are one run: §4.3.2 loops ("Return to the start of this step"), so
/// `/* c *//* d */` is a single stretch of no-token material.
pub
/// The first offset in `[from, to)` that is neither whitespace nor inside a comment — where
/// the region's next real token begins — or `to` when the region is nothing but trivia.
///
/// The composition of this module's rule with the lexer's whitespace set, and the single
/// definition of it: every scanner that walks a *parsed* region looking for a token it has
/// no span for (the declaration scanner's value bounds, the printer's attribute-selector
/// rebuild) asks this rather than re-spelling the pair.
///
/// ⚠️ The whitespace set is the **lexer's** ([`crate::lexer::is_ascii_css_whitespace`], which carries the
/// vertical tab to match `parseCss`), not [`crate::escapes`]'s §4.2 five. That is forced:
/// the region was already tokenized, so a scanner stepping over "the whitespace the parser
/// skipped" must use the set the parser skipped. Narrowing it stops the scan ON a vertical
/// tab and mislocates the token behind it — which, in the attribute-selector rebuild, moved
/// a comment across the matcher (`[attr\u{b}/* c */='value']` → `[attr= /* c */ 'value']`).
///
/// An unterminated comment yields `to`, so the caller stops at the bound rather than reading
/// past it.
pub
/// Where a pseudo selector's NAME begins, given the span that starts at its first `:` —
/// past the colons and past any comment run glued to either of them.
///
/// selectors-4 forbids white space between a `<pseudo-class-selector>`'s / a
/// `<pseudo-element-selector>`'s components, but a comment is no token at all
/// (§4.3.2), so `:/* c */hover`, `::/* c */before` and `:/* c */:before` are all one
/// selector. Every consumer of the name — the printer's case fold, the wire's
/// half-decode, the scoping compiler's `:global` test — takes its start from here
/// rather than assuming the sigil is one or two bytes wide.
///
/// Each step is ANCHORED at a known position rather than searching, which is what keeps
/// it escape-proof: an escape can only begin where the name does, and `comment_run_end`
/// answers `None` on a `\` (`.\/*x*/y` is an ident, not a comment).
pub
/// Where a class selector's NAME begins — past the `.` and any comment run glued to it.
///
/// The one-juncture sibling of [`pseudo_name_start`], for the same selectors-4 rule
/// ("between **any** of the components of a `<class-selector>`").
///
/// Only the wire writer needs it — the printer reaches the same juncture through
/// [`pseudo_name_start`] — so it is `json`-gated: `@fuzdev/tsv-format-wasm` builds
/// without that feature, and an ungated item there is dead code in a size-bound artifact.
pub
/// Advance past a declaration's post-value TAIL — whitespace, block comments, `!important` —
/// to its `;`/`}` terminator, returning that index (or `bytes.len()`).
///
/// Mirrors Svelte's `read_declaration`: `read_value` returns with the scan index AT the
/// terminator and the declaration's `end` is taken there — so trailing whitespace and
/// comments after the value (and after `!important`) sit inside the declaration extent.
/// Only whitespace, comments, and the `!important` tail can occur between the parsed
/// value's end and the terminator, so a flat byte walk is safe (no string/url content).
///
/// ⚠️ **That safety argument is the whole contract — do not point this at a region
/// that can hold content.** It is blind to strings and `url()`, unlike Svelte's own
/// `read_value`, so over an at-rule PRELUDE it stops at the first `;`/`}` inside one
/// (`@import url("a;b.css") /* c */;`) and silently truncates. The prelude's ends come from
/// the parser instead (`write.rs`'s `collect_prelude_comments`).
///
/// Its two callers are the same question from the two sides of the crate — the wire writer's
/// declaration extent and the printer's `end_after_semicolon`, which needs the gap AFTER a
/// declaration to start where the declaration's text really stops. That is why it lives here
/// rather than in `ast::convert`: the printer cannot see that module (it is behind the
/// `json` feature, off in the format-only WASM build), and the alternative was a second
/// spelling of a scan whose whole value is that there is one. ⚠️ The printer's INTERNAL
/// declaration span can end before `!important` where the wire's does not, so a caller that
/// assumes the span already reaches the `;` is right for every shape but that one — which is
/// how a positional blank-line rule came to read `!important;` as the start of its gap and
/// drop the author's blank line.
pub