bynk_ts/printer.rs
1//! The printer — `TsProgram -> Artefacts` (R7.3: "printing is `TsProgram ->
2//! Artefacts`. The printer owns the buffer, the indentation and the offset
3//! arithmetic. It is the only code in the compiler that writes a
4//! character."). Owns one buffer for the whole [`TsProgram`], so unlike
5//! `bynk-emit`'s own splice-based lowering (`crate::source_map`'s own module
6//! doc), it never needs to rebase a sub-buffer's checkpoints — it records
7//! directly from each statement's own `span` as it writes, which is what
8//! makes R7.4 ("the source map is produced by the printer from
9//! `TsNode.span`. No phase before the printer records an offset") true by
10//! construction for this path, from this slice.
11//!
12//! # Readability policy (R7.5)
13//!
14//! R7.5: "Readable output is a printer policy with a name and a test, not a
15//! property of how carefully strings were typed." P7.7 named the policy's
16//! then-whole surface (statement separation); P7.8 (#1313) extends it now
17//! that the printer has real structured nodes to have an opinion about
18//! (`TsExpr`/`TsType`/`TsDecl`, plus real `TsStmt` variants):
19//!
20//! - **Every statement starts on its own generated line, so two statements
21//! can never share one.** Unchanged from P7.7 — see [`print()`]'s own
22//! loop. Still true for the new node kinds: every one of their own
23//! renderers ends its own output in `\n`.
24//! - **Two-space indentation, one level per nesting depth.** The only
25//! indentation width this printer produces — chosen because it's the one
26//! `events_fanout.rs` (this slice's own grounding file) already uses, not
27//! because of any earlier general readability decision; matches the
28//! depth threaded through [`render_stmt`]/[`render_block_body`](stmt::render_block_body) exactly.
29//! - **One blank line separates top-level declarations, except two
30//! consecutive `import`s or two consecutive `Comment`s.** [`print()`]'s
31//! own loop implements this by peeking at the next statement — matching
32//! `events_fanout.rs`'s own real spacing (its two `import` lines sit
33//! adjacent, and so do its own two header-comment lines; every other pair
34//! of top-level declarations has a blank line between). Added for Arc C's
35//! own first real conversion slice (#1317): every `bynk-emit`-generated
36//! file opens with a multi-line header banner, one [`TsStmtKind::Comment`]
37//! per real line.
38//! - **[`TsStmt::no_blank_before`] suppresses that same blank immediately
39//! before the statement carrying it**, composing with every rule above
40//! rather than replacing any of them — a property of the *statement*, not
41//! of a pair, so it stays correct however many different kinds end up
42//! adjacent to it. Scoped to exactly [`print()`]'s own top-level loop: a
43//! statement carrying it inside a `Block`/`InlineBlock`/function body, or
44//! printed through [`print_stmt`] / `bynk-emit`'s own `extend_printed`
45//! splicing helpers, is silently ignored there today — harmless only
46//! because none of those paths inserts an automatic blank of its own in
47//! the first place. Added for #1486: `emit_agent`'s own already-shipped
48//! registry-`const`-then-zero-factory pairing needs zero blank lines
49//! between two adjacent real top-level statements, a shape no existing
50//! pair rule above can express without a `TsDecl`-pair special case.
51//! - **Inside a `class`, no blank line between fields and the constructor;
52//! one blank line before each method.** [`render_decl_body`](decl::render_decl_body)'s own
53//! `TsDecl::Class` arm — again, this is what `events_fanout.rs` itself
54//! does, not a general rule derived some other way.
55//! - **`if`/`for...of`'s own body prints with braces when it's a
56//! `TsStmtKind::Block`, and inline on the same line otherwise** —
57//! `if (!Array.isArray(subs)) continue;` has no braces in the grounding
58//! file; a `for...of` always does. See [`render_branch`](stmt::render_branch).
59//! - **A statement's own interior is not the printer's concern for
60//! `Verbatim` content — still.** `Verbatim` text renders exactly as
61//! written (P7.7's own boundary, unchanged); everything above applies
62//! only to the new, real node kinds this slice adds.
63//! - **A shorthand async method entry in an object literal
64//! (`TsObjectEntry::Method`) prints exactly like a class method** —
65//! `async name(params) { <body> },` with a trailing comma, body indented
66//! one level deeper than the entry itself, closing `},` back at the
67//! entry's own indent. Added for Arc C's own third slice (#1321,
68//! `workers.rs`): the `compose`-returned surface object's dominant real
69//! shape, one entry per wrapper.
70//! - **`?.`/`?.[...]` print with no surrounding spaces** — `object?.property`/
71//! `object?.[index]`, matching plain `Member`/`Index`'s own spacing
72//! exactly, just with the extra `?`. Added for #1321: `workers.rs`'s own
73//! secret-probe idiom.
74//! - **An optional field in a type-position object literal prints `key?:
75//! ty`** — the direct type-side counterpart to `TsParam.optional`'s
76//! already-established `name?: ty` for parameters. Added for #1321.
77//! - **An arrow function prints `(params) => body` on one line, expression
78//! body only** — no block-body form exists yet (nothing built here needs
79//! one). Added for #1321.
80//! - **A nested `Binary` operand of another `Binary` parenthesizes only
81//! when the inner operator's precedence is not strictly higher than the
82//! outer's, or when the same operator nests in itself and that operator
83//! is `||`/`&&`** (`render_binary_operand`) — every other operand
84//! position (`Member`/`Index`/`Call`/`New`/`Await`/`Unary`,
85//! `render_operand`) still always parenthesizes a nested `Binary`/`As`/
86//! `Arrow`/`Conditional`, unchanged. Added for #1321: `workers.rs`'s own
87//! `__authz === null || !__authz.startsWith(...)` has no parens around
88//! the comparison in the byte-golden fixtures, and `??` mixed with
89//! `||`/`&&` still always parenthesizes (TS forbids that combination
90//! unparenthesized). Extended for #1323: a 3+-term `||`/`&&` chain of the
91//! *same* operator (`typeof args !== "object" || args === null ||
92//! Array.isArray(args)`) prints flat, with no parens around the nested
93//! pair — `??` chained with itself keeps the pre-#1321 conservative
94//! choice (still parenthesized), since nothing real needs it flattened.
95//! - **`switch (<discriminant>) { <cases> }` — a non-`default` `case` is
96//! always `{ }`-blocked; a `default` case never is.** Added for #1323:
97//! `workers_entry.rs`'s four real `switch` statements are the first real
98//! content this tree represents with a genuinely new statement-grouping
99//! construct, not a single expression/type variant.
100//! - **`export default <expr>;` prints the expression through the same
101//! depth-aware multiline-object handling `const`/`let`/`return`/`Assign`
102//! already get.** Added for #1323: `workers_entry.rs`'s own top-level
103//! shape is a default-exported object literal.
104//! - **`export { a, b } from "spec";` — a re-export — prints with no blank
105//! line rule of its own** (it is not classified alongside `import`/
106//! `import * as` for the "no blank line between adjacent imports"
107//! exception, so the ordinary "one blank line between top-level
108//! declarations" default applies both before and after it). Added for
109//! #1323: `workers_entry.rs`'s own agent/fan-out-DO re-exports, each
110//! already separated from its neighbours by a blank line in the
111//! pre-conversion output.
112//! - **`test ? consequent : alternate` prints on one line, with `test`
113//! parenthesized only when it is itself an `Arrow` or a `Conditional`.**
114//! Added for #1323: `workers_entry.rs`'s own two real ternaries.
115//! - **A `readonly`/method-signature/index-signature member of a
116//! type-position object literal prints `readonly name: ty` /
117//! `name(params): ret` / `[key: key_ty]: value_ty`.** Added for #1323:
118//! `workers_entry.rs`'s own `scheduled`/`queue` parameter types and its
119//! multi-param `on call` dispatch's `args as { [k: string]: JsonValue }`.
120//! - **An explicit `Paren` always prints its own literal parentheses,
121//! independent of the wrapped expression's own precedence.** Added for
122//! #1323: `workers_entry.rs`'s CORS-preflight guard condition, which the
123//! pre-conversion code always wrapped in `(...)` even when nothing about
124//! the wrapped expression's own precedence required it.
125//! - **A bare blank line (`Blank`) prints exactly one empty line**, usable
126//! at any nesting depth — distinct from `print()`'s own top-level-only
127//! blank-line policy above. Added for #1323: three specific points inside
128//! `workers_entry.rs`'s `fetch` method body.
129//! - **An `if`'s own `else` prints on its own fresh line, at the `if`'s own
130//! indent, then follows the same block-vs-inline branch rule the `if`
131//! itself does.** Added for #1323: `workers_entry.rs`'s queue-consumer
132//! ack/retry dispatch.
133//! - **`InlineBlock` prints `{ stmt; stmt; ... }` on one generated line**,
134//! distinct from `Block`'s always-multi-line form — reachable only as an
135//! `if`/`else` branch in real content today. Added for #1323:
136//! `workers_entry.rs`'s own two real sites (a deserialise-failure guard,
137//! and the ack/retry dispatch's `else`), both hand-written as compact
138//! one-liners in the pre-conversion text.
139//! - **An array literal supports the same `multiline` shape an object
140//! literal does** — one item per line, each with its own trailing comma,
141//! closing `]` at the statement's own indent, only through
142//! `render_stmt_level_expr`. Added for #1325: `emit_test_main`'s own
143//! `modules` array.
144//! - **A template literal's static parts print verbatim, with no escaping of
145//! their own.** Added for #1325 — see `TsExpr::TemplateLit`'s own doc for
146//! why (a generic escaper would double an already-pre-formed JS unicode
147//! escape's own literal backslash).
148//! - **`declare const name: ty;` prints with no initialiser at all** —
149//! distinct from every other `const` form, which always has one. Added
150//! for #1325: `emit_test_main`'s own ambient `process` declaration.
151//! - **An `async function` prints `async function name(...)`** — the
152//! top-level sibling to `TsObjectEntry::Method`'s own `is_async` handling.
153//! Added for #1325: `emit_test_main`'s own top-level `main`.
154//! - **`<expr>++;` prints a bare postfix increment as a whole statement.**
155//! Added for #1325: `emit_test_main`'s own `passed++;`/`failed++;`
156//! counters.
157//! - **An `if`'s own `else` prints `} else {` on the same physical line when
158//! `same_line_else` is set** (only reachable when `then_branch` is a
159//! `Block` or `InlineBlock`) — a second, real convention alongside the
160//! fresh-line default just above, not a replacement for it. Added for
161//! #1325: all three of `emit_test_main`'s own real `if`/`else` sites use
162//! this spacing, none use the fresh-line form `workers_entry.rs`'s own
163//! real content needs — two already-real files disagreeing on the same
164//! construct, the same tension the `Await`-under-`As` correction
165//! (#1323/#1324) found for parenthesisation.
166//! - **`export * from "spec";` — a wildcard re-export — groups with itself
167//! AND with an immediately-preceding header `Comment`, no blank line
168//! either way.** A different spacing shape from `ReExport`'s own (no
169//! grouping rule, see above): `emit_commons_barrel`'s own real barrel
170//! module is one header comment followed by one `export *` line per
171//! constituent source file, every one of those lines adjacent with no
172//! blank line anywhere. Added for #1329.
173//! - **A `TsStmtKind::DocComment` prints a JSDoc block comment**, one
174//! ` * <line>` per non-blank source line, a blank source line as a bare
175//! ` *`. Distinct from `Comment`'s own `//`-per-line form, and printed
176//! only through [`print_stmt`] (`bynk-emit`'s own `emit_doc_block`, a
177//! shared helper spliced into still-unconverted callers' buffers), never
178//! through [`print()`]'s own `TsProgram` loop — so this shape has no
179//! blank-line grouping rule of its own to name here. Added for #1333.
180//! - **A `TsStmtKind::Raw` prints its own text verbatim** — no leading
181//! indent, no added punctuation, the same rendering `Verbatim` gets
182//! (deliberately a distinct kind, not a reuse of it — see
183//! [`crate::program::TsStmtKind::Raw`]'s own doc for why). Never reached
184//! through [`print()`]'s own `TsProgram` loop — no blank-line grouping
185//! rule of its own to name here either. Added for #1337:
186//! `emit_method`'s own body, delegated wholesale to `emitter/lower.rs`'s
187//! `emit_block_as_function_body_with_return` — a permanent Arc C
188//! exclusion (ADR `arc-c-lower-rs-permanent-exclusion`), not residue.
189//! #1339 added a second, differently-reasoned real use:
190//! `emit_refined_type`'s own `of()` guard body, carrying `emit_refined_
191//! checks`'s already-printed output — not a permanent exclusion, just
192//! scope that function's own conversion didn't reach. Both uses carry
193//! text pre-indented at a fixed absolute depth by their own caller, so
194//! `render_multiline_object_entry`'s own `debug_assert!` guards that this
195//! only renders correctly at `depth == 0` — see its doc and
196//! [`print_object_entry`]'s. **Reached through more than a
197//! `TsObjectEntry::Method`'s own `body` now** (review of #1370 caught
198//! this doc drifting stale): `emit_free_fn` (#1352) and `emit_agent`'s
199//! own rehydrate function (#1369) both hold `Raw` statements inside an
200//! ordinary `TsDecl::Function`'s own `body`, rendered through
201//! `render_block_stmts` at whatever `depth` the enclosing `print_stmt`
202//! call used (always 0 for a top-level declaration in every real site
203//! today, satisfying the same depth-0 assumption named above). Since
204//! #1369 also added `TsDecl::Function.inline`, a `Raw`-bearing function
205//! body reached with `inline: true` would route through
206//! `render_inline_block`/`render_compact_stmts` instead — see
207//! [`render_inline_stmt`](compact::render_inline_stmt)'s own `Raw` arm for why that combination stays
208//! deliberately unbuilt.
209//!
210//! None of the above is claimed as *the* TypeScript style this printer will
211//! use forever — it's what this slice's own grounding file needs, named
212//! rather than left implicit, the same posture the node algebra itself
213//! takes (`program.rs`'s own module doc). A future file with a construct
214//! this policy doesn't cover yet (an `else` branch, a multi-field class with
215//! blank lines between fields, …) extends it the same way `program.rs`'s
216//! own node list grows: file by file, against real content.
217
218mod compact;
219mod decl;
220mod expr;
221mod fragment;
222mod multiline;
223mod precedence;
224mod stmt;
225mod types;
226
227#[cfg(test)]
228mod tests;
229
230use crate::program::{TsDecl, TsProgram, TsStmt, TsStmtKind};
231use crate::source_map::SourceMapBuilder;
232use bynk_syntax::span::Span;
233pub use fragment::{
234 print_class_method, print_class_method_and_merge, print_expr, print_object_entry, print_stmt,
235 print_stmt_and_merge, print_stmt_with_spans, print_type,
236};
237use stmt::render_stmt;
238
239/// The result of printing a [`TsProgram`]: the emitted text, and its source
240/// map — `None` when no checkpoint resolved, either because no statement
241/// carried a span or every span fell outside `source_text`
242/// ([`SourceMapBuilder::to_v3`]'s own "nothing resolves" case).
243#[derive(Debug)]
244pub struct Printed {
245 pub text: String,
246 pub source_map: Option<String>,
247}
248
249/// Print `program` to TypeScript text. `source_name`/`source_text` register
250/// the `.bynk` source every statement's own span is measured against —
251/// today always exactly one, since nothing spans two files yet;
252/// `output_file` names the generated file in the source map's own `file`
253/// field. Every statement's own span is recorded as a checkpoint, at
254/// any depth (1A.15; before that only a top-level statement's was, R7.4's
255/// original scope) — except inside an arrow body, which carries none yet.
256pub fn print(
257 program: &TsProgram,
258 source_name: &str,
259 source_text: &str,
260 output_file: &str,
261) -> Printed {
262 let mut map = SourceMapBuilder::new();
263 map.add_source(source_name, source_text);
264 print_with_map(program, map, output_file)
265}
266
267/// #1486's own multi-source sibling of [`print()`]: a test/integration
268/// module's own aggregate map spans one source per fragment file a case's
269/// body was spliced in from (`emit_test_module`/`emit_integration_module`,
270/// `project/tests_emit.rs`), not the single `.bynk` file `print`'s own
271/// signature assumes — see [`TsStmt::nested_map_source_id`]'s own doc for
272/// why a per-statement source selector needs a caller that can register
273/// more than one source in the first place. Takes the caller's own already-
274/// built `map` directly (rather than a `(name, text)` list built fresh
275/// here) so a caller can keep registering sources incrementally as it
276/// discovers them — `emit_test_module`'s own per-case loop, one `add_source`
277/// call per case, exactly as it already did before this function existed —
278/// and get each call's own returned id back immediately, to set on that
279/// case's own top-level statement's `nested_map_source_id`, instead of
280/// having to pre-compute the full source list up front. Every statement's
281/// own `nested_map_source_id` selects which of `map`'s already-registered
282/// sources (by id) its own `nested_map` merges against; a statement with no
283/// `span` of its own (this whole module's own shape — an aggregate with no
284/// single "primary" source of its own) never records a top-level
285/// checkpoint, so `map`'s own id-`0` source (if any) needs no special
286/// "primary" meaning here the way [`print()`]'s single source does.
287pub fn print_multi_source(
288 program: &TsProgram,
289 map: SourceMapBuilder,
290 output_file: &str,
291) -> Printed {
292 print_with_map(program, map, output_file)
293}
294
295fn print_with_map(program: &TsProgram, mut map: SourceMapBuilder, output_file: &str) -> Printed {
296 let mut out = String::new();
297 for (i, stmt) in program.stmts.iter().enumerate() {
298 // The statement's own span, and every nested statement's, are
299 // recorded by `render_stmt` as it prints (1A.15, Decision B of #3716).
300 // #1477: also merges any nested checkpoints this top-level
301 // statement (or anything nested inside it) itself carries — the
302 // same mechanism `print_stmt_and_merge`/`print_class_method_and_
303 // merge` expose to a caller printing one fragment at a time,
304 // applied here automatically for every top-level statement in a
305 // real `TsProgram`. `source_id` defaults to `stmt.
306 // nested_map_source_id`'s own default of `0`, matching `record`'s
307 // own unconditional targeting of the primary source just above for
308 // every single-source module; #1486's own multi-source case
309 // (`nested_map_source_id`'s own doc comment) sets it per statement.
310 render_stmt(
311 &mut out,
312 stmt,
313 0,
314 Some(MergeTarget {
315 map: &mut map,
316 source_id: stmt.nested_map_source_id,
317 }),
318 );
319 // The printer owns line structure (R7.3), so a statement's own text
320 // not ending in its own newline can't leave two statements sharing
321 // a generated line — review of #1308, finding 2: nothing required
322 // `Verbatim` text to be newline-terminated, and two that weren't
323 // would jam onto one line *and* silently lose the earlier
324 // statement's own checkpoint (`SourceMapBuilder::record`'s
325 // same-offset dedup, and `to_v3`'s one-checkpoint-per-line forward
326 // pass, both keep only the later one). Every real (non-`Verbatim`)
327 // renderer already ends its own output in `\n`, so this is a no-op
328 // for them; kept unconditional so `Verbatim`'s own guarantee stays
329 // exactly as it was.
330 if !out.ends_with('\n') {
331 out.push('\n');
332 }
333 // Readability policy (this module's own doc): one blank line
334 // between top-level declarations, except two consecutive
335 // `import`s, two consecutive `Comment`s, two consecutive
336 // `ReExportAll`s, a `Comment` immediately before a `ReExportAll`,
337 // or the next statement's own `no_blank_before` (#1486's own
338 // escape hatch — a real, already-shipped multi-statement sequence
339 // that genuinely needs no blank between two adjacent real
340 // statements, not expressible as a `TsStmtKind`-pair rule the way
341 // every case above is) — and never after `Verbatim` (P7.7's own
342 // boundary — `Verbatim` content's own spacing is not this
343 // printer's decision).
344 if let Some(next) = program.stmts.get(i + 1) {
345 // #1321: `workers.rs`'s own header has `import { ... } from
346 // "runtime"` (named) adjacent to `import * as handlers from
347 // "./handlers.js"` (namespace) adjacent to one `import * as
348 // {ns} from "..."` per referenced unit — all import-like, all
349 // real-content-adjacent with no blank line, matching the same
350 // "no blank line between two adjacent imports" rule
351 // `events_fanout.rs`'s own two named imports already exercised.
352 fn is_import_decl(kind: &TsStmtKind) -> bool {
353 matches!(
354 kind,
355 TsStmtKind::Decl(TsDecl::Import { .. })
356 | TsStmtKind::Decl(TsDecl::ImportNamespace { .. })
357 | TsStmtKind::Decl(TsDecl::ImportDefault { .. })
358 )
359 }
360 // #1329: `emit_commons_barrel`'s own real barrel module is one
361 // header `Comment` immediately followed by an `export *` line
362 // per constituent source file, every one of those lines
363 // adjacent to the next with no blank line anywhere — a
364 // genuinely different spacing shape from `ReExport`'s own
365 // (#1323's `workers_entry.rs` re-exports, each already
366 // separated from its neighbours by a blank line in the
367 // pre-conversion output, so `ReExport` itself still gets no
368 // grouping rule of its own). Scoped to exactly this new
369 // adjacency — a `Comment` before an ordinary `Import`/other
370 // decl still gets its blank line (see `events_fanout.rs`'s own
371 // header-comment-then-blank-then-import shape), unchanged.
372 fn is_reexport_all(kind: &TsStmtKind) -> bool {
373 matches!(kind, TsStmtKind::Decl(TsDecl::ReExportAll { .. }))
374 }
375 let both_imports = is_import_decl(&stmt.kind) && is_import_decl(&next.kind);
376 let both_comments = matches!(&stmt.kind, TsStmtKind::Comment(_))
377 && matches!(&next.kind, TsStmtKind::Comment(_));
378 let both_reexport_all = is_reexport_all(&stmt.kind) && is_reexport_all(&next.kind);
379 let comment_then_reexport_all =
380 matches!(&stmt.kind, TsStmtKind::Comment(_)) && is_reexport_all(&next.kind);
381 if !both_imports
382 && !both_comments
383 && !both_reexport_all
384 && !comment_then_reexport_all
385 && !next.no_blank_before
386 && !matches!(stmt.kind, TsStmtKind::Verbatim { .. })
387 {
388 out.push('\n');
389 }
390 }
391 }
392 let source_map = map.to_v3(&out, output_file);
393 Printed {
394 text: out,
395 source_map,
396 }
397}
398
399fn indent(depth: usize) -> String {
400 " ".repeat(depth)
401}
402
403/// #1477's own carrier for a nested-checkpoint merge target: which map to
404/// merge a [`crate::program::TsStmt::nested_map`]-bearing statement's own
405/// checkpoints into, and which of that map's own registered sources they
406/// belong to. A bare `&mut SourceMapBuilder` isn't enough on its own
407/// (review of #1488, finding 1): hardcoding source `0` is correct for
408/// `print`'s own single-primary-source map and for every real caller today
409/// (`emit_free_fn`/`emit_class_method_and_merge_source_map` both already
410/// pass `0`), but silently wrong for a multi-source aggregate map — a test
411/// module's own map spans several `.bynk` files, and its real per-body
412/// merges already pass a non-zero id (`bynk-emit/src/project/tests_emit.rs:
413/// 537`/`:1936`) — exactly the shape #1475 found is this arc's own next
414/// conversion target. Threading `source_id` alongside `map` here, not
415/// hardcoded inside `SourceMapBuilder::merge`'s own caller here, keeps that
416/// conversion correct from the start rather than needing a second pass to
417/// discover the same gap.
418struct MergeTarget<'a> {
419 map: &'a mut SourceMapBuilder,
420 source_id: usize,
421}
422
423impl MergeTarget<'_> {
424 /// A fresh, independently-usable borrow of the same target — `Option<
425 /// MergeTarget>` isn't `Copy` (it holds a `&mut`), so a caller handing
426 /// the same target to more than one child (a `Vec<TsStmt>`'s own loop,
427 /// `TsDecl::Class`'s own constructor-then-methods sequence) reborrows
428 /// once per child via this, the same shape `Option::as_deref_mut` gives
429 /// a bare `&mut`.
430 fn reborrow(&mut self) -> MergeTarget<'_> {
431 MergeTarget {
432 map: self.map,
433 source_id: self.source_id,
434 }
435 }
436}
437
438/// Record `stmt`'s span at `offset` in the target's map, if the print has one
439/// and the statement carries a span (1A.15, Decision B of #3716). The same
440/// statement can be reached twice at one offset (an inline branch is noted by
441/// `render_branch` and again by a `render_stmt` fallback); the map keeps the
442/// later span at an offset, which is the same one.
443fn note_span(offset: usize, stmt: &TsStmt, map: Option<&mut MergeTarget<'_>>) {
444 if let Some(span) = stmt.span {
445 note_span_at(offset, span, map);
446 }
447}
448
449/// [`note_span`] for a span that is not a statement's own: a `switch` case's.
450fn note_span_at(offset: usize, span: Span, map: Option<&mut MergeTarget<'_>>) {
451 if let Some(target) = map {
452 target.map.record_in(offset, target.source_id, span);
453 }
454}