bynk_ts/program/stmt.rs
1use super::{TsDecl, TsExpr, TsType, VerbatimOrigin};
2use crate::source_map::SourceMapBuilder;
3use bynk_syntax::span::Span;
4
5/// One name a statement exports ([`TsStmt::exported_names`]).
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub struct ExportedName<'a> {
8 /// The exported name (an `X as Y` entry's `Y`).
9 pub name: &'a str,
10 /// Whether the statement exports a value under the name, as a `const`,
11 /// `function` or `class` does, or only a type, as an `interface`, a
12 /// `type` alias or a `type X` list entry does.
13 pub has_value: bool,
14}
15
16/// One statement — a `Verbatim`-tagged escape hatch (still constructible
17/// only via [`TsStmt::verbatim`], per #1307's Decision D — the
18/// `verbatim_sites` probe needs exactly one string to line-scan for), or,
19/// from this slice, a real structured kind. The real kinds have no such
20/// sealing: they're normal typed constructors, not a "wrap opaque text"
21/// escape hatch, so the `verbatim_sites` concern that motivates `verbatim`'s
22/// own single-constructor discipline doesn't apply to them.
23#[derive(Debug, Clone, PartialEq)]
24pub struct TsStmt {
25 pub(crate) kind: TsStmtKind,
26 /// Where this statement's content originated in the `.bynk` source, if
27 /// known. Only a *top-level* statement's own span is currently recorded
28 /// as a source-map checkpoint ([`crate::printer::print`], unchanged
29 /// from P7.5/R7.4's own scope) — a nested statement (inside a `Block`,
30 /// `If`, `ForOf`, `TryCatch`) still carries this field structurally, for
31 /// whichever future slice gives sub-statement source maps real value,
32 /// but the printer does not yet record a checkpoint from it. Named here
33 /// explicitly (P7.8's own accepted proposal: "an implementation-time
34 /// call within this same shape") rather than left ambiguous.
35 pub span: Option<Span>,
36 /// #1477's own real gap: a body-bearing statement — in practice always
37 /// a `TsStmtKind::Raw`/`TsStmtKind::Verbatim` opaque blob standing in
38 /// for a lowered function/method body (ADR 0391's own permanent
39 /// exclusion) — carries its *own* per-statement source-map checkpoints,
40 /// collected by the caller's own body-local `SourceMapBuilder` before
41 /// this node existed. Before this field, every real `bynk-emit` caller
42 /// that needed to merge those checkpoints into its own module map had to
43 /// reverse-engineer this node's own print-time byte offset from the
44 /// *outside* — `bynk-emit`'s own `emit_class_method_and_merge_source_map`
45 /// (`emitter/emit.rs`) recovers it by subtracting known lengths and
46 /// string-matching the printed text's own tail, degrading to a silent
47 /// skip if that search fails; still live for `emit_service`/`emit_agent`'s
48 /// own not-yet-converted call sites (#1481/#1482). `emit_free_fn` used to
49 /// recover it by separate, independent exact arithmetic, guarded by a
50 /// `debug_assert!` — #1480 converted it to set this field directly
51 /// instead, the first real `bynk-emit` caller to do so. Both existed
52 /// only because nothing reported *this* node's own real print-time
53 /// offset directly. Setting this field lets the printer itself do the
54 /// merge, at the exact offset it is about to write this node's text to
55 /// — no reverse-engineering, no silent-skip fallback (see this crate's
56 /// own private `printer::render_block_stmts` for the handling). `None`
57 /// for every real site that predates this field and every node whose own
58 /// text carries no nested checkpoints of its own — the overwhelmingly
59 /// common case, and the reason this is an `Option`, not a required
60 /// field.
61 pub nested_map: Option<SourceMapBuilder>,
62 /// #1486's own second real gap, found converting `emit_test_module`/
63 /// `emit_integration_module`: [`crate::printer::print`]'s own top-level
64 /// loop always merges a statement's [`nested_map`](Self::nested_map)
65 /// against parent source id `0` (`crate::printer::MergeTarget`'s own
66 /// review-of-#1488 fix threads a `source_id` through every *manual*
67 /// merge entry point, but `print`'s own automatic top-level case never
68 /// had a per-statement way to say "not 0") — correct for every
69 /// single-source module (`emit_project`, every other real caller so
70 /// far), but wrong for a test/integration module's own aggregate map,
71 /// which registers one source per fragment file a case's body came from
72 /// (`SourceMapBuilder::add_source`) and needs each such case's own
73 /// top-level statement merged against *that* source's id, not the
74 /// module's primary one. `0` (every site predating this field, and
75 /// every single-source module after it) keeps the automatic policy
76 /// exactly as it already was; a case/property/attack wrapper statement
77 /// sets this to its own registered source id before `print` sees it.
78 pub nested_map_source_id: usize,
79 /// #1486's own real gap, found converting `emit_project`/`emit_test_
80 /// module`/`emit_integration_module` off a single opaque top-level
81 /// `Verbatim` wrap: [`crate::printer::print`]'s own top-level loop
82 /// inserts exactly one blank line between every pair of adjacent
83 /// top-level statements (its own "readability policy" doc, right below
84 /// this field's own use site) — correct for content that was always
85 /// designed against that policy (`emit_composition_root`/`emit_test_
86 /// main`/`workers.rs`/`workers_entry.rs`, every one of them zero-diff
87 /// from day one), but `emit_agent`'s own already-shipped `Vec<TsStmt>`
88 /// (#1482, predating this field) was built against the *previous*
89 /// regime — where every real caller printed via `bynk-emit`'s own
90 /// `extend_printed`/`extend_printed_and_merged` (a flat per-stmt loop
91 /// with no automatic spacing of its own) — and genuinely needs a
92 /// same-registry-then-zero-factory pairing with **no** blank line
93 /// between them, matching the pre-conversion hand-written text this
94 /// crate's own zero-diff discipline requires preserving exactly.
95 /// `true` on a statement suppresses the automatic blank line
96 /// [`crate::printer::print`] would otherwise insert immediately before
97 /// it — the narrow, general escape hatch this real, already-shipped
98 /// content needs, not a special case hard-coded into the printer for
99 /// one specific pair of `TsDecl` variants. `false` (every site
100 /// predating this field, and the overwhelming majority after it) keeps
101 /// the automatic policy exactly as it already is.
102 pub no_blank_before: bool,
103}
104
105#[derive(Debug, Clone, PartialEq)]
106pub(crate) enum TsStmtKind {
107 Verbatim {
108 // Read by `TsProgram::verbatim_content` (#1538) to attribute each
109 // opaque leaf's text to its origin file.
110 origin: VerbatimOrigin,
111 text: String,
112 },
113 /// A top-level declaration ([`TsDecl`]) printed as a statement — the
114 /// bridge between `TsProgram`'s flat `Vec<TsStmt>` and the reference
115 /// sketch's separate `TsDecl` enum (an `import`/`interface`/top-level
116 /// `const`/`class` *is* one kind of top-level statement in this tree,
117 /// not a different container).
118 Decl(TsDecl),
119 /// A local `const` binding, e.g. `const { events } = ...;` or
120 /// `const subs = ...;` — distinct from [`TsDecl::ConstDecl`], which is
121 /// the top-level form. Carries a real destructuring [`TsBindingName`]
122 /// because `events_fanout.rs`'s own `const { events } = ...` needs one
123 /// (a gap beyond the accepted proposal's own variant list — a bare
124 /// `String` name cannot represent it; named explicitly as a deviation,
125 /// not invented silently).
126 Const {
127 name: TsBindingName,
128 ty: Option<TsType>,
129 init: TsExpr,
130 },
131 /// `let`'s sibling to `Const` — unused by `events_fanout.rs` itself, but
132 /// the `const`/`let` distinction is real TypeScript semantics the
133 /// printer must preserve once one of the pair exists (the accepted
134 /// proposal's own reasoning for keeping it).
135 Let {
136 name: TsBindingName,
137 ty: Option<TsType>,
138 init: Option<TsExpr>,
139 /// #2617: printed `var` rather than `let`. A module-level `var` is
140 /// hoisted and reads as `undefined` before its statement runs, where
141 /// a `let` would throw (its temporal dead zone), so a hoisted
142 /// function may read it while another module of an import cycle is
143 /// still evaluating. Set only by [`TsStmt::var_stmt`].
144 hoisted: bool,
145 },
146 /// An expression used as a whole statement (a bare call, e.g.).
147 ExprStmt(TsExpr),
148 Return(Option<TsExpr>),
149 /// `throw <expr>;` — #1353's own real gap: `emit_contract_guarded_body`'s
150 /// own precondition/postcondition guards (`bynk-emit/src/emitter/
151 /// emit.rs`) each throw a constructed `Error` on violation — no prior
152 /// slice needed a bare `throw` (every other error-signalling site in
153 /// this tree so far has been a `Return`). Mirrors `Return`'s own shape
154 /// exactly, minus the `Option` (a `throw` always carries a value; there
155 /// is no bare `throw;` in JS/TS).
156 Throw(TsExpr),
157 /// `if (cond) <then_branch>` (optionally `else <else_branch>`).
158 /// `then_branch`/`else_branch` may each be a [`TsStmtKind::Block`]
159 /// (printed with braces) or any other single statement (printed inline
160 /// on the same line, matching `if (!Array.isArray(subs)) continue;`'s
161 /// own real, brace-free shape). `else_branch` is #1323's own real gap:
162 /// `workers_entry.rs`'s queue-consumer ack/retry dispatch (`if
163 /// (result.tag === "Ack") msg.ack(); else { ...; msg.retry(); }`) —
164 /// `events_fanout.rs`'s own grounding never used one, so P7.8 named
165 /// omitting it a deliberate choice, not an oversight; this slice's own
166 /// real content needs it for real.
167 ///
168 /// `same_line_else` is #1325's own real gap: `workers_entry.rs`'s own
169 /// real `else` sits on its own fresh line (`}\nelse {`), but
170 /// `emit_test_main`'s own real content wants the conventional `} else
171 /// {` — two already-real files disagreeing on the same construct, the
172 /// same class of tension the `Await`-under-`As` correction (#1323/
173 /// #1324) found for parenthesisation. `false` (fresh line) is the
174 /// existing, already-tested default via [`TsStmt::if_else_stmt`]; `true`
175 /// (same line) is reached only through
176 /// [`TsStmt::if_else_same_line_stmt`].
177 If {
178 cond: TsExpr,
179 then_branch: Box<TsStmt>,
180 else_branch: Option<Box<TsStmt>>,
181 same_line_else: bool,
182 },
183 /// `for (const <binding> of <iter>) <body>`.
184 ForOf {
185 binding: String,
186 iter: TsExpr,
187 body: Box<TsStmt>,
188 /// `for await (const <binding> of <iter>)` (1A.35a part B: the `Stream`
189 /// generators drain an async iterable).
190 is_await: bool,
191 },
192 /// `while (<cond>) <body>` (1A.35a part B). `body` renders as `If`'s and
193 /// `ForOf`'s do: braced when it is a [`TsStmtKind::Block`], inline otherwise.
194 While {
195 cond: TsExpr,
196 body: Box<TsStmt>,
197 },
198 /// `<label>: <body>` (1A.35a part B): a labelled statement, the target of a
199 /// labelled [`TsStmtKind::Continue`] or [`TsStmtKind::Break`]. `body` is
200 /// usually a loop or a [`TsStmtKind::Block`]; any statement is valid.
201 Labelled {
202 label: String,
203 body: Box<TsStmt>,
204 },
205 /// `let a, b: T, c = e;` (1A.35a part B): one `let` with several
206 /// declarators, each optionally typed, definitely assigned or initialised.
207 /// [`TsStmtKind::Let`] stays the form for a destructuring pattern.
208 LetList(Vec<TsDeclarator>),
209 /// `for (let <name> = <init>; <test>; <name>++) <body>` — a C-style
210 /// indexed loop, `ForOf`'s counterpart for index-based iteration (as
211 /// opposed to `for...of`'s element-based iteration over an existing
212 /// collection). Arc E slice 7 (#1447)'s own real, narrow gap:
213 /// `bynk-emit`'s `serialisation.rs` has two real sites — `ListInst`'s
214 /// and `MapInst`'s own deserialise-side element loops, both `for (let i
215 /// = 0; i < json.length; i++) { ... }` — that walk a JSON array by
216 /// index, a shape `ForOf` cannot represent (its own `binding` names a
217 /// per-element destructuring target bound fresh each iteration, not a
218 /// counter carrying its own init/test/update clauses across
219 /// iterations). Deliberately grounded in only what those two real call
220 /// sites need, not the general C-style-for grammar — the same "extend
221 /// narrowly" posture this file's own `TsBinaryOp::In`/`LessThan`
222 /// additions already took:
223 /// - `name`/`init` are always a plain `let <name> = <init>;`
224 /// declaration — no destructuring, no multi-declarator list, no
225 /// explicit type annotation (neither real site needs one).
226 /// - The update clause always renders as the postfix increment
227 /// `<name>++`, over `name` itself rather than a separate field —
228 /// review of #1448 found an independent `update: TsExpr` field
229 /// structurally redundant with `name` (both real construction sites
230 /// could only ever pass `ident(name)`) with a genuinely dangerous
231 /// failure mode if the two ever disagreed: unlike a wrong `test`
232 /// (which `tsc --strict` or a non-running loop tends to surface), a
233 /// mismatched update clause (`for (let i = 0; i < json.length;
234 /// j++)`) compiles cleanly whenever `j` is merely in scope and hangs
235 /// the generated worker at runtime, with nothing in the type, the
236 /// printer, or a test to catch it. Removing the field removes the
237 /// failure mode entirely rather than merely asserting against it —
238 /// the same "postfix increment has no expression-position
239 /// representation, only a dedicated statement/clause shape"
240 /// restriction `Increment`'s own doc above already states for a
241 /// bare `<expr>++;` statement (#1325), applied here too.
242 /// - `body` is the loop body; both real sites pass a `Block`, though
243 /// the same brace-vs-inline rendering `If`/`ForOf` already share
244 /// applies to any other shape too.
245 For {
246 name: String,
247 init: TsExpr,
248 test: TsExpr,
249 body: Box<TsStmt>,
250 },
251 /// `try <try_block> catch (<catch_param>) <catch_block>` — a real gap
252 /// beyond the reference sketch (`design/bynk-greenfield-compiler.md`'s
253 /// §7.1 has no `TryCatch` at all), found and named by P7.8's own
254 /// accepted proposal: `events_fanout.rs`'s subscriber-failure-isolation
255 /// `try`/`catch` (ADR 0284) is load-bearing control flow, not
256 /// decorative. `catch_param: None` prints the bare `catch { ... }`
257 /// form (ES2019's optional catch binding) — #1321's own real gap:
258 /// `workers.rs`'s `emit_http_sum_wrapper` reads the raw request body in
259 /// a `try`/`catch` that never uses the caught error (`} catch {`, no
260 /// `(e)` at all).
261 ///
262 /// 1A.21 (#3722, Decision C): `catch_block` is optional and a `finally_block` joins
263 /// it, so `try { … } finally { … }` (no `catch`) and `try { … } catch (e) { … }
264 /// finally { … }` are expressible. At least one of the two must be present (a bare
265 /// `try` is a syntax error); the printer asserts it. `catch_param` is meaningful only
266 /// with a `catch_block`.
267 TryCatch {
268 try_block: Box<TsStmt>,
269 catch_param: Option<String>,
270 catch_block: Option<Box<TsStmt>>,
271 finally_block: Option<Box<TsStmt>>,
272 },
273 /// `{ <stmts> }` — the body container for `If`/`ForOf`/`TryCatch`/
274 /// constructor and method bodies.
275 Block(Vec<TsStmt>),
276 /// A bare `continue;` — a second real gap beyond the accepted
277 /// proposal's own variant list: `events_fanout.rs` uses it twice
278 /// (`if (!Array.isArray(subs)) continue;` / `if (!binding) continue;`),
279 /// load-bearing loop control the accepted proposal's `TsStmt` list
280 /// doesn't name. No label — nothing in the grounding file needs one.
281 ///
282 /// 1A.35a part B: `continue <label>;` when it carries a label, which must
283 /// name an enclosing [`TsStmtKind::Labelled`] loop.
284 Continue(Option<String>),
285 /// A `break;`, ending a `switch` case (1A.32b: the history driver's
286 /// `case 0: …; break;`), or `break <label>;` out of a
287 /// [`TsStmtKind::Labelled`] statement (1A.35a part B).
288 Break(Option<String>),
289 /// `target = value;` — a third real gap, found in review of the
290 /// implementing PR (#1313): `events_fanout.rs`'s own constructor body is
291 /// exactly one statement, `this.env = (env ?? {}) as
292 /// Record<string, ServiceBinding>;` (a field assignment, not a `const`/
293 /// `let` binding), which the accepted proposal's own grounding
294 /// catalogue missed — it catalogued the `fetch` method's body in detail
295 /// but not the constructor's. `target` is deliberately a full `TsExpr`
296 /// (not a narrower "assignable" type) so it can hold `this.env` (a
297 /// `Member` expression) without a second binding-target type; nothing
298 /// about `Assign` validates that `target` is actually assignable
299 /// (`bynk-check` already does that on the `.bynk` side before emission
300 /// ever runs).
301 Assign {
302 target: TsExpr,
303 value: TsExpr,
304 },
305 /// `// <text>` — a bare line comment. Added for Arc C's own first real
306 /// conversion slice (#1317): every `bynk-emit`-generated `.ts` file
307 /// opens with the same two-line header banner
308 /// (`// Generated by bynk — do not edit by hand.` / a file-specific
309 /// second line), and nothing before this slice could represent one.
310 /// Not speculative — a universal need every later Arc C slice hits on
311 /// its own first line, closed once here rather than left as a residual
312 /// `Verbatim` wrap that would make `verbatim_sites` show zero
313 /// improvement for real, substantial conversion work.
314 ///
315 /// Carries no semantic content the printer or checker ever reads back —
316 /// pure, inert text. Printed one `// `-prefixed line per `\n` in `text`
317 /// (`bynk-ts/src/printer/stmt.rs`'s own `render_stmt`), so a multi-line
318 /// comment is representable as one statement, though
319 /// `events_fanout.rs`'s own two-line header is built as two separate
320 /// `Comment` statements instead — matching how its two adjacent
321 /// `import` lines are two separate `TsDecl::Import` statements, not one
322 /// with an embedded line break, and exercising the printer's own new
323 /// "no blank line between adjacent `Comment`s" rule (the same
324 /// exception already established for adjacent `import`s).
325 Comment(String),
326 /// `/** ... */` — a JSDoc block comment, distinct from
327 /// [`TsStmtKind::Comment`]'s own `//`-per-line form. #1333's own real
328 /// need: `emit_doc_block` (`bynk-emit/src/emitter/emit.rs`) renders a
329 /// Bynk `///` doc comment as a real JSDoc block — printed via
330 /// [`crate::printer::print_stmt`], not [`crate::printer::print`], since
331 /// every real call site today is a shared helper spliced into a
332 /// still-unconverted caller's own buffer, the same P7.9 pattern
333 /// `ts_type_ref`/`ts_ty` already used (keep the caller's own signature,
334 /// build a real node internally, print just that fragment). Escaping
335 /// (a literal `*/` inside the text becomes `*\/`, so it can't
336 /// prematurely close the comment and let trailing text land as
337 /// executable top-level TypeScript — issue #720) and the blank-line
338 /// convention (a blank source line prints as a bare ` *`, no trailing
339 /// space) live in the printer (`render_stmt`'s own `DocComment` arm,
340 /// `crate::printer`'s own private renderer), matching
341 /// where every other statement kind's rendering rules live.
342 DocComment(String),
343 /// A bare blank line — no statement content. #1323's own real, narrow
344 /// need: `workers_entry.rs`'s `fetch` method body has an unconditional
345 /// blank line after its internal Service-Binding dispatch block, and a
346 /// conditional one after the WebSocket-upgrade dispatch (when present)
347 /// and the Events dispatch (when present) — three specific points the
348 /// pre-conversion `writeln!(out).unwrap()` wrote directly, nested
349 /// *inside* the `try` block's own statement list. Distinct from
350 /// [`crate::printer::print`]'s own top-level blank-line policy (this
351 /// module's own printer doc), which only separates `TsProgram`'s own
352 /// top-level statements — nothing before this slice needed a blank line
353 /// anywhere inside a nested block, so that policy was never generalized
354 /// to every nesting depth. A single, narrow statement kind represents
355 /// exactly this, rather than widening the top-level-only policy to a
356 /// depth it has no other real content to justify.
357 Blank,
358 /// `switch (<discriminant>) { <cases> }` — #1323's own largest gap: the
359 /// first genuinely new statement-*grouping* construct in this tree
360 /// (every prior addition was a single expression/type variant or a
361 /// straightforward one-block wrapper). `workers_entry.rs` has four real
362 /// `switch` statements (the internal `/_bynk/call/` and `/_bynk/event/`
363 /// dispatches, the `scheduled` handler's `event.cron` dispatch, the
364 /// `queue` handler's `batch.queue` dispatch); every real `case` there is
365 /// a `{ ... }`-blocked body ending in a terminal statement (`return`/
366 /// `continue`), so no fallthrough/shared-body grouping is represented —
367 /// extend narrowly, the same posture every other addition here takes.
368 /// Arc E slice 6 (#1445) widens this one further, narrowly: a
369 /// non-`default` case's own bracing is now per-case
370 /// ([`TsSwitchCase::case_braced`]) rather than unconditional —
371 /// `emit_sum_codec`'s own payload-free-variant case is real, unbraced
372 /// content, not a hypothetical.
373 Switch {
374 discriminant: TsExpr,
375 cases: Vec<TsSwitchCase>,
376 },
377 /// `{ stmt; stmt; ... }` — a braced, multi-statement block printed on
378 /// ONE generated line, distinct from [`TsStmtKind::Block`] (always
379 /// multi-line). #1323's own real gap: `workers_entry.rs`'s queue
380 /// consumer has two real sites (`if (__r.tag === "Err") { console.
381 /// error(...); msg.retry(); continue; }`; the `else` branch of the
382 /// ack/retry dispatch) where the pre-conversion `writeln!` code
383 /// deliberately packed several short statements onto one physical
384 /// line — a real, distinct formatting choice from every other
385 /// multi-statement body in this tree, which always prints one
386 /// statement per line. Only reachable through [`TsStmt::if_stmt`]/
387 /// [`TsStmt::if_else_stmt`]'s own branches in real content today.
388 InlineBlock(Vec<TsStmt>),
389 /// `<expr>++;` — a postfix increment used as a whole statement. #1325's
390 /// own real, narrow gap: `emit_test_main`'s own `passed++;`/`failed++;`
391 /// counters. No prefix form, no decrement, no expression-position use
392 /// (every real site increments a bare counter as its own statement) —
393 /// [`TsExpr::Unary`] stays prefix-only (`!`/`typeof`), since a postfix
394 /// operator used as a *statement* is a different grammatical position
395 /// from a prefix operator used as an *operand*, not a shape `Unary`
396 /// could represent by adding a variant.
397 Increment(TsExpr),
398 /// A pre-rendered, unconditional-passthrough statement blob — printed
399 /// exactly as given, with no leading indent, no added semicolon, no
400 /// added braces (matching [`TsStmtKind::Verbatim`]'s own `out.push_str(
401 /// text)` rendering, not the ordinary per-kind `indent(depth)`-prefixed
402 /// shape every other variant gets). #1337's own real need:
403 /// `emit_method`'s own body is delegated wholesale to
404 /// `emit_block_as_function_body_with_return` (`bynk-emit`'s
405 /// `emitter/lower.rs:201`) — the one splice boundary ADR
406 /// `arc-c-lower-rs-permanent-exclusion` names as a *permanent*,
407 /// deliberate exclusion from this tree (`lower.rs` is the compiler's
408 /// own second code-generation pass, comprehensive language-surface
409 /// work Arc C was never scoped to cover), not a not-yet-converted
410 /// residue [`TsStmtKind::Verbatim`] would misrepresent it as.
411 ///
412 /// Deliberately a SEPARATE variant from `Verbatim`, not a reuse of it,
413 /// even though both render identically (`out.push_str(text)`): the
414 /// `verbatim_sites`/`verbatim_origins` probes exist specifically to
415 /// track Arc C's own *temporary* conversion residue trending toward
416 /// zero — a `Raw` site is never counted there (it has no
417 /// `VerbatimOrigin` at all), because using `Verbatim` here would make
418 /// this permanent exclusion look like unfinished Arc C work a future
419 /// slice is expected to close, which it structurally cannot.
420 ///
421 /// #1339's own second real use, broadening (not narrowing) the
422 /// above: `emit_refined_type`'s own `of()` guard block splices
423 /// `emit_refined_checks`'s own output this same way — that function
424 /// keeps its exact `out: &mut String` signature (the P7.9/step-1
425 /// pattern applied one level down, not a `lower.rs`-style permanent
426 /// exclusion), but its real content is ALREADY built and printed from
427 /// real `bynk_ts::TsStmt`/`print_stmt` calls internally — genuinely
428 /// statement-shaped pre-rendered text, the same mechanical fit `Raw`
429 /// already provides, just for a different underlying reason than
430 /// `lower.rs`'s own permanent exclusion.
431 ///
432 /// #1445's own third real use (Arc E slice 6, `serialisation.rs`'s
433 /// `emit_sum_codec`, via that file's own `raw_stmts_at_depth_one`
434 /// helper): a real, currently-shipped BYTE-LEVEL quirk, not a scope
435 /// boundary. `emit_field_deserialise_wire`'s own field guards, spliced
436 /// into a sum's deserialise-side payload case, have always printed at
437 /// depth 1 (`splice_stmts`'s own fixed indent) even though they sit
438 /// structurally inside a `TsStmtKind::Switch` case's own body (which
439 /// this printer would otherwise render two levels deeper, at depth 3) —
440 /// confirmed byte-for-byte against `212_json_codec`/
441 /// `407_workers_generic_sum_boundary`'s own real fixtures. Letting the
442 /// switch case render these at their structurally-correct depth instead
443 /// would be a real, deliberate formatting change with no fixture-corpus
444 /// backing either way, which that slice's own zero-diff mandate ruled
445 /// out choosing unprompted.
446 ///
447 /// All three real uses share the one property that actually matters for
448 /// this variant's own existence: *real, already-correctly-indented (or,
449 /// for the third, real-but-deliberately-NOT-restructured) statement text
450 /// this call site cannot turn into a properly-nested `Vec<TsStmt>`
451 /// without changing scope or bytes it isn't the one authorised to
452 /// change* — not whether the reason is permanent, temporary, or a
453 /// preserved historical quirk.
454 ///
455 /// The second field (1A.36a, Decision D) lists the names the fixed text
456 /// uses, declared where the text is written; empty for a plain
457 /// [`TsStmt::raw`]. `name_closure` counts them as uses.
458 Raw(String, Vec<String>),
459}
460
461/// One declarator of a `TsStmtKind::LetList`: `name`, `name!: T`, `name: T` or
462/// `name: T = init` (1A.35a part B). `definite` prints the `!` assertion, which
463/// TypeScript allows only with a type and no initialiser.
464#[derive(Debug, Clone, PartialEq)]
465pub struct TsDeclarator {
466 pub name: String,
467 pub definite: bool,
468 pub ty: Option<TsType>,
469 pub init: Option<TsExpr>,
470}
471
472impl TsDeclarator {
473 /// `name`, declared and not yet assigned.
474 pub fn new(name: impl Into<String>) -> Self {
475 Self {
476 name: name.into(),
477 definite: false,
478 ty: None,
479 init: None,
480 }
481 }
482
483 /// `name: ty`.
484 #[must_use]
485 pub fn typed(mut self, ty: TsType) -> Self {
486 self.ty = Some(ty);
487 self
488 }
489
490 /// `name!: ty`: a definite-assignment assertion, for a variable assigned
491 /// where the compiler cannot see it.
492 #[must_use]
493 pub fn definite(mut self, ty: TsType) -> Self {
494 self.definite = true;
495 self.ty = Some(ty);
496 self
497 }
498
499 /// `name = init`.
500 #[must_use]
501 pub fn init(mut self, init: TsExpr) -> Self {
502 self.init = Some(init);
503 self
504 }
505}
506
507/// One `case`/`default` arm of a `TsStmtKind::Switch`. empty `labels` is the
508/// `default:` case — every real `default` in `workers_entry.rs` prints its
509/// body directly under `default:` with no `{ }` block, while every real
510/// non-`default` `case` (regardless of `test`) always prints a `{ }`-blocked
511/// body.
512///
513/// `default_braced` (Arc C slice 33, `tests_emit.rs` slice C, #1401) —
514/// `emit_stub_class`'s own `ReturnsEach` dispatch is the first real site
515/// with a BRACED `default: { ... }`, a genuinely different convention from
516/// `workers_entry.rs`'s own unbraced one; only meaningful when `test` is
517/// `None` (a non-`default` case was unconditionally braced before
518/// `case_braced` existed, below). Kept a per-case flag rather than changing
519/// the existing unbraced-default rendering, since that would risk
520/// `workers_entry.rs`'s own real, already-zero-diff content for no benefit —
521/// the same "don't touch working, unrelated content" judgment this track
522/// makes repeatedly.
523///
524/// `case_braced` (Arc E slice 6, #1445) — the mirror-image gap `default_braced`
525/// left open: `serialisation.rs`'s `emit_sum_codec` (this tree's first real
526/// non-`default` case that is NOT `{ }`-blocked) needs `case "Pending":
527/// return { kind: "Pending" };` — unbraced — right beside a sibling
528/// payload-carrying `case "Shipped": { ... }` — braced — in the *same*
529/// switch (`212_json_codec`'s own mixed `Status` fixture, confirmed by
530/// direct grep before this field was added: a payload-free variant's case
531/// is always unbraced, a payload-carrying variant's is always braced, and a
532/// real fixture exercises both side by side). Every prior real non-`default`
533/// case (`workers_entry.rs`'s dispatches, `tests_emit.rs`'s own sequential-
534/// outcome cases) already wants braces, so those call sites all set this
535/// `true` — the same "narrow, argued, backward-compatible extension"
536/// shape `default_braced` itself set as precedent. Only meaningful when
537/// it has a label (a `default` case's bracing is `default_braced`'s
538/// business, not this field's — the inverse of that field's own scoping).
539#[derive(Debug, Clone, PartialEq)]
540pub struct TsSwitchCase {
541 /// The `case` labels: empty is `default`; more than one prints stacked,
542 /// `case a:` / `case b: {`, sharing the one body (1A.13, #3714: the
543 /// or-pattern's shape, widened from the single `test` it replaced).
544 pub labels: Vec<TsExpr>,
545 pub body: Vec<TsStmt>,
546 pub default_braced: bool,
547 pub case_braced: bool,
548 /// The source span recorded by `print_stmt_with_spans` at the start of the
549 /// case's first label line (1A.13, #3714). Plain printing ignores it.
550 pub span: Option<Span>,
551}
552
553impl TsStmt {
554 /// The one constructor for a `Verbatim`-kinded statement.
555 pub fn verbatim(origin: VerbatimOrigin, text: impl Into<String>, span: Option<Span>) -> Self {
556 Self {
557 kind: TsStmtKind::Verbatim {
558 origin,
559 text: text.into(),
560 },
561 span,
562 nested_map: None,
563 no_blank_before: false,
564 nested_map_source_id: 0,
565 }
566 }
567
568 /// Whether this is a named `import { … } from "…"` declaration (#1817): a
569 /// module assembler hoists those into its import block.
570 pub fn is_named_import(&self) -> bool {
571 matches!(self.kind, TsStmtKind::Decl(TsDecl::Import { .. }))
572 }
573
574 /// The names this statement exports (#1820): an `export` of a named
575 /// declaration, or an `export { … }` list, with or without `from`. A
576 /// module assembler re-exporting another module's names reads them here.
577 /// A `Raw` or `Verbatim` statement's text is not parsed, so an export
578 /// written that way is not reported.
579 ///
580 /// Each name says whether this statement exports a value under it (#1862
581 /// review): an `interface` or `type` alias exports only a type, and under
582 /// `isolatedModules` a type-only name is re-exported only as `type X`
583 /// (TS1205). A list entry follows [`TsDecl::Import`]'s spelling: `type X`
584 /// is type-only, and `X as Y` exports `Y`. Every other entry is taken to
585 /// carry a value, the form that re-exports both meanings.
586 pub fn exported_names(&self) -> Vec<ExportedName<'_>> {
587 let TsStmtKind::Decl(decl) = &self.kind else {
588 return Vec::new();
589 };
590 match decl {
591 TsDecl::ReExport { names, .. } | TsDecl::ExportNames { names } => names
592 .iter()
593 .map(|spec| {
594 let (spec, has_value) = match spec.trim().strip_prefix("type ") {
595 Some(rest) => (rest, false),
596 None => (spec.trim(), true),
597 };
598 let name = spec.rsplit(" as ").next().unwrap_or(spec).trim();
599 ExportedName { name, has_value }
600 })
601 .collect(),
602 TsDecl::Export(inner) => match inner.as_ref() {
603 TsDecl::Interface { name, .. } | TsDecl::TypeAlias { name, .. } => {
604 vec![ExportedName {
605 name,
606 has_value: false,
607 }]
608 }
609 TsDecl::ConstDecl { name, .. }
610 | TsDecl::Class { name, .. }
611 | TsDecl::Function { name, .. } => vec![ExportedName {
612 name,
613 has_value: true,
614 }],
615 TsDecl::Import { .. }
616 | TsDecl::ImportNamespace { .. }
617 | TsDecl::ImportDefault { .. }
618 | TsDecl::ReExport { .. }
619 | TsDecl::ExportNames { .. }
620 | TsDecl::ReExportAll { .. }
621 | TsDecl::Export(_)
622 | TsDecl::ExportDefault(_)
623 | TsDecl::DeclareConst { .. } => Vec::new(),
624 },
625 TsDecl::Import { .. }
626 | TsDecl::ImportNamespace { .. }
627 | TsDecl::ImportDefault { .. }
628 | TsDecl::ReExportAll { .. }
629 | TsDecl::Interface { .. }
630 | TsDecl::ConstDecl { .. }
631 | TsDecl::Class { .. }
632 | TsDecl::Function { .. }
633 | TsDecl::TypeAlias { .. }
634 | TsDecl::ExportDefault(_)
635 | TsDecl::DeclareConst { .. } => Vec::new(),
636 }
637 }
638
639 /// This statement with its `export` modifier dropped, when it is an exported declaration
640 /// ([`TsDecl::Export`]); any other statement is returned as it was. For a declaration that
641 /// moves into a function body, where `export` is not legal.
642 #[must_use]
643 pub fn without_export(mut self) -> Self {
644 if let TsStmtKind::Decl(TsDecl::Export(inner)) = self.kind {
645 self.kind = TsStmtKind::Decl(*inner);
646 }
647 self
648 }
649
650 pub fn decl(decl: TsDecl, span: Option<Span>) -> Self {
651 Self {
652 kind: TsStmtKind::Decl(decl),
653 span,
654 nested_map: None,
655 no_blank_before: false,
656 nested_map_source_id: 0,
657 }
658 }
659
660 pub fn const_stmt(
661 name: TsBindingName,
662 ty: Option<TsType>,
663 init: TsExpr,
664 span: Option<Span>,
665 ) -> Self {
666 Self {
667 kind: TsStmtKind::Const { name, ty, init },
668 span,
669 nested_map: None,
670 no_blank_before: false,
671 nested_map_source_id: 0,
672 }
673 }
674
675 pub fn let_stmt(
676 name: TsBindingName,
677 ty: Option<TsType>,
678 init: Option<TsExpr>,
679 span: Option<Span>,
680 ) -> Self {
681 Self {
682 kind: TsStmtKind::Let {
683 name,
684 ty,
685 init,
686 hoisted: false,
687 },
688 span,
689 nested_map: None,
690 no_blank_before: false,
691 nested_map_source_id: 0,
692 }
693 }
694
695 /// #2617: `var name: ty;` — a hoisted binding with no initialiser, which
696 /// reads as `undefined` (rather than throwing) before its statement runs.
697 /// The cache behind each constant's function (`bynk-emit`'s
698 /// `emit_consts`), which an import cycle may call before the declaring
699 /// module has evaluated.
700 pub fn var_stmt(name: impl Into<String>, ty: TsType, span: Option<Span>) -> Self {
701 Self {
702 kind: TsStmtKind::Let {
703 name: TsBindingName::Ident(name.into()),
704 ty: Some(ty),
705 init: None,
706 hoisted: true,
707 },
708 span,
709 nested_map: None,
710 no_blank_before: false,
711 nested_map_source_id: 0,
712 }
713 }
714
715 pub fn expr_stmt(expr: TsExpr, span: Option<Span>) -> Self {
716 Self {
717 kind: TsStmtKind::ExprStmt(expr),
718 span,
719 nested_map: None,
720 no_blank_before: false,
721 nested_map_source_id: 0,
722 }
723 }
724
725 pub fn return_stmt(expr: Option<TsExpr>, span: Option<Span>) -> Self {
726 Self {
727 kind: TsStmtKind::Return(expr),
728 span,
729 nested_map: None,
730 no_blank_before: false,
731 nested_map_source_id: 0,
732 }
733 }
734
735 pub fn throw_stmt(expr: TsExpr, span: Option<Span>) -> Self {
736 Self {
737 kind: TsStmtKind::Throw(expr),
738 span,
739 nested_map: None,
740 no_blank_before: false,
741 nested_map_source_id: 0,
742 }
743 }
744
745 pub fn if_stmt(cond: TsExpr, then_branch: TsStmt, span: Option<Span>) -> Self {
746 Self {
747 kind: TsStmtKind::If {
748 cond,
749 then_branch: Box::new(then_branch),
750 else_branch: None,
751 same_line_else: false,
752 },
753 span,
754 nested_map: None,
755 no_blank_before: false,
756 nested_map_source_id: 0,
757 }
758 }
759
760 pub fn if_else_stmt(
761 cond: TsExpr,
762 then_branch: TsStmt,
763 else_branch: TsStmt,
764 span: Option<Span>,
765 ) -> Self {
766 Self {
767 kind: TsStmtKind::If {
768 cond,
769 then_branch: Box::new(then_branch),
770 else_branch: Some(Box::new(else_branch)),
771 same_line_else: false,
772 },
773 span,
774 nested_map: None,
775 no_blank_before: false,
776 nested_map_source_id: 0,
777 }
778 }
779
780 /// [`TsStmt::if_else_stmt`]'s own sibling with `} else {` on one line —
781 /// #1325's own real gap, `emit_test_main`'s own real `else` spacing. See
782 /// `TsStmtKind::If`'s own doc for why this needs to be a distinct
783 /// constructor rather than a change to the existing default.
784 pub fn if_else_same_line_stmt(
785 cond: TsExpr,
786 then_branch: TsStmt,
787 else_branch: TsStmt,
788 span: Option<Span>,
789 ) -> Self {
790 Self {
791 kind: TsStmtKind::If {
792 cond,
793 then_branch: Box::new(then_branch),
794 else_branch: Some(Box::new(else_branch)),
795 same_line_else: true,
796 },
797 span,
798 nested_map: None,
799 no_blank_before: false,
800 nested_map_source_id: 0,
801 }
802 }
803
804 pub fn for_of(
805 binding: impl Into<String>,
806 iter: TsExpr,
807 body: TsStmt,
808 span: Option<Span>,
809 ) -> Self {
810 Self {
811 kind: TsStmtKind::ForOf {
812 binding: binding.into(),
813 iter,
814 body: Box::new(body),
815 is_await: false,
816 },
817 span,
818 nested_map: None,
819 no_blank_before: false,
820 nested_map_source_id: 0,
821 }
822 }
823
824 /// `for (let <name> = <init>; <test>; <update>++) <body>` — see
825 /// `TsStmtKind::For`'s own doc for exactly what this construct does
826 /// and does not represent.
827 pub fn for_stmt(
828 name: impl Into<String>,
829 init: TsExpr,
830 test: TsExpr,
831 body: TsStmt,
832 span: Option<Span>,
833 ) -> Self {
834 Self {
835 kind: TsStmtKind::For {
836 name: name.into(),
837 init,
838 test,
839 body: Box::new(body),
840 },
841 span,
842 nested_map: None,
843 no_blank_before: false,
844 nested_map_source_id: 0,
845 }
846 }
847
848 pub fn try_catch(
849 try_block: TsStmt,
850 catch_param: Option<impl Into<String>>,
851 catch_block: TsStmt,
852 span: Option<Span>,
853 ) -> Self {
854 Self {
855 kind: TsStmtKind::TryCatch {
856 try_block: Box::new(try_block),
857 catch_param: catch_param.map(Into::into),
858 catch_block: Some(Box::new(catch_block)),
859 finally_block: None,
860 },
861 span,
862 nested_map: None,
863 no_blank_before: false,
864 nested_map_source_id: 0,
865 }
866 }
867
868 /// `try <try_block> finally <finally_block>`, with no `catch` (1A.21, #3722).
869 pub fn try_finally(try_block: TsStmt, finally_block: TsStmt, span: Option<Span>) -> Self {
870 Self {
871 kind: TsStmtKind::TryCatch {
872 try_block: Box::new(try_block),
873 catch_param: None,
874 catch_block: None,
875 finally_block: Some(Box::new(finally_block)),
876 },
877 span,
878 nested_map: None,
879 no_blank_before: false,
880 nested_map_source_id: 0,
881 }
882 }
883
884 /// `try <try_block> catch (<catch_param>) <catch_block> finally <finally_block>`
885 /// (1A.21, #3722).
886 pub fn try_catch_finally(
887 try_block: TsStmt,
888 catch_param: Option<impl Into<String>>,
889 catch_block: TsStmt,
890 finally_block: TsStmt,
891 span: Option<Span>,
892 ) -> Self {
893 Self {
894 kind: TsStmtKind::TryCatch {
895 try_block: Box::new(try_block),
896 catch_param: catch_param.map(Into::into),
897 catch_block: Some(Box::new(catch_block)),
898 finally_block: Some(Box::new(finally_block)),
899 },
900 span,
901 nested_map: None,
902 no_blank_before: false,
903 nested_map_source_id: 0,
904 }
905 }
906
907 pub fn block(stmts: Vec<TsStmt>, span: Option<Span>) -> Self {
908 Self {
909 kind: TsStmtKind::Block(stmts),
910 span,
911 nested_map: None,
912 no_blank_before: false,
913 nested_map_source_id: 0,
914 }
915 }
916
917 pub fn break_stmt(span: Option<Span>) -> Self {
918 Self {
919 kind: TsStmtKind::Break(None),
920 span,
921 nested_map: None,
922 no_blank_before: false,
923 nested_map_source_id: 0,
924 }
925 }
926
927 pub fn continue_stmt(span: Option<Span>) -> Self {
928 Self {
929 kind: TsStmtKind::Continue(None),
930 span,
931 nested_map: None,
932 no_blank_before: false,
933 nested_map_source_id: 0,
934 }
935 }
936
937 /// `break <label>;`.
938 pub fn break_label_stmt(label: impl Into<String>, span: Option<Span>) -> Self {
939 Self::plain(TsStmtKind::Break(Some(label.into())), span)
940 }
941
942 /// `continue <label>;`.
943 pub fn continue_label_stmt(label: impl Into<String>, span: Option<Span>) -> Self {
944 Self::plain(TsStmtKind::Continue(Some(label.into())), span)
945 }
946
947 /// `while (<cond>) <body>`.
948 pub fn while_stmt(cond: TsExpr, body: TsStmt, span: Option<Span>) -> Self {
949 Self::plain(
950 TsStmtKind::While {
951 cond,
952 body: Box::new(body),
953 },
954 span,
955 )
956 }
957
958 /// `<label>: <body>`.
959 pub fn labelled(label: impl Into<String>, body: TsStmt, span: Option<Span>) -> Self {
960 Self::plain(
961 TsStmtKind::Labelled {
962 label: label.into(),
963 body: Box::new(body),
964 },
965 span,
966 )
967 }
968
969 /// `let a, b: T, c = e;`.
970 pub fn let_list(decls: Vec<TsDeclarator>, span: Option<Span>) -> Self {
971 debug_assert!(!decls.is_empty(), "TsStmt::let_list needs a declarator");
972 Self::plain(TsStmtKind::LetList(decls), span)
973 }
974
975 /// `for await (const <binding> of <iter>) <body>`.
976 pub fn for_await_of(
977 binding: impl Into<String>,
978 iter: TsExpr,
979 body: TsStmt,
980 span: Option<Span>,
981 ) -> Self {
982 Self::plain(
983 TsStmtKind::ForOf {
984 binding: binding.into(),
985 iter,
986 body: Box::new(body),
987 is_await: true,
988 },
989 span,
990 )
991 }
992
993 /// A statement of `kind` with no source-map extras.
994 fn plain(kind: TsStmtKind, span: Option<Span>) -> Self {
995 Self {
996 kind,
997 span,
998 nested_map: None,
999 no_blank_before: false,
1000 nested_map_source_id: 0,
1001 }
1002 }
1003
1004 pub fn assign(target: TsExpr, value: TsExpr, span: Option<Span>) -> Self {
1005 Self {
1006 kind: TsStmtKind::Assign { target, value },
1007 span,
1008 nested_map: None,
1009 no_blank_before: false,
1010 nested_map_source_id: 0,
1011 }
1012 }
1013
1014 pub fn comment(text: impl Into<String>, span: Option<Span>) -> Self {
1015 Self {
1016 kind: TsStmtKind::Comment(text.into()),
1017 span,
1018 nested_map: None,
1019 no_blank_before: false,
1020 nested_map_source_id: 0,
1021 }
1022 }
1023
1024 pub fn doc_comment(text: impl Into<String>, span: Option<Span>) -> Self {
1025 Self {
1026 kind: TsStmtKind::DocComment(text.into()),
1027 span,
1028 nested_map: None,
1029 no_blank_before: false,
1030 nested_map_source_id: 0,
1031 }
1032 }
1033
1034 pub fn blank(span: Option<Span>) -> Self {
1035 Self {
1036 kind: TsStmtKind::Blank,
1037 span,
1038 nested_map: None,
1039 no_blank_before: false,
1040 nested_map_source_id: 0,
1041 }
1042 }
1043
1044 pub fn switch_stmt(discriminant: TsExpr, cases: Vec<TsSwitchCase>, span: Option<Span>) -> Self {
1045 Self {
1046 kind: TsStmtKind::Switch {
1047 discriminant,
1048 cases,
1049 },
1050 span,
1051 nested_map: None,
1052 no_blank_before: false,
1053 nested_map_source_id: 0,
1054 }
1055 }
1056
1057 pub fn inline_block(stmts: Vec<TsStmt>, span: Option<Span>) -> Self {
1058 Self {
1059 kind: TsStmtKind::InlineBlock(stmts),
1060 span,
1061 nested_map: None,
1062 no_blank_before: false,
1063 nested_map_source_id: 0,
1064 }
1065 }
1066
1067 pub fn increment(expr: TsExpr, span: Option<Span>) -> Self {
1068 Self {
1069 kind: TsStmtKind::Increment(expr),
1070 span,
1071 nested_map: None,
1072 no_blank_before: false,
1073 nested_map_source_id: 0,
1074 }
1075 }
1076
1077 /// The text of a `Raw` statement, `None` for every other kind.
1078 pub fn raw_text(&self) -> Option<&str> {
1079 if let TsStmtKind::Raw(text, _) = &self.kind {
1080 Some(text)
1081 } else {
1082 None
1083 }
1084 }
1085
1086 /// The one constructor for a `Raw`-kinded statement — `text` is printed
1087 /// verbatim, exactly as given (see `TsStmtKind::Raw`'s own doc for
1088 /// why this is a distinct kind from `Verbatim`, not a reuse of it).
1089 pub fn raw(text: impl Into<String>, span: Option<Span>) -> Self {
1090 Self {
1091 kind: TsStmtKind::Raw(text.into(), Vec::new()),
1092 span,
1093 nested_map: None,
1094 no_blank_before: false,
1095 nested_map_source_id: 0,
1096 }
1097 }
1098
1099 /// 1A.36a (Decision D): a `Raw` statement that also declares the names its
1100 /// fixed text uses. `text` prints exactly as [`TsStmt::raw`]'s does; `names`
1101 /// are the identifiers (types or values) the text refers to without
1102 /// declaring, which `name_closure` counts as uses. The names are written
1103 /// where the text is, never scanned out of it: a scan over-matches on
1104 /// string literals and comments and under-matches on formatting.
1105 pub fn raw_using(text: impl Into<String>, names: &[&str]) -> Self {
1106 Self {
1107 kind: TsStmtKind::Raw(
1108 text.into(),
1109 names.iter().map(|n| (*n).to_string()).collect(),
1110 ),
1111 span: None,
1112 nested_map: None,
1113 no_blank_before: false,
1114 nested_map_source_id: 0,
1115 }
1116 }
1117}
1118
1119/// A binding's own name, in either of the two shapes `events_fanout.rs`
1120/// itself uses: a plain identifier (`const subs = ...`), or an
1121/// object-destructuring pattern (`const { events } = ...`) — naming only
1122/// the destructured properties themselves (`{ a, b }`), not the renamed
1123/// (`{ a: renamed }`) or nested (`{ a: { b } }`) forms, since nothing in
1124/// the grounding file needs either.
1125#[derive(Debug, Clone, PartialEq)]
1126pub enum TsBindingName {
1127 Ident(String),
1128 ObjectPattern(Vec<String>),
1129 /// An array-destructuring pattern (`const [a, b] = …`, back-half paydown
1130 /// 1A.14, for `par`'s join). An empty name is a hole (`[, b]`), which is how
1131 /// a `do` part binds nothing.
1132 ArrayPattern(Vec<String>),
1133}