Skip to main content

bynk_ts/
lib.rs

1//! The TypeScript tree and printer (phase 7 of the compiler trajectory,
2//! `design/bynk-compiler-trajectory.md`). Emission produces nodes
3//! ([`TsProgram`]/[`TsStmt`]); [`printer::print`] is the only code in the
4//! compiler that writes a character (R7.3). The crate also holds the
5//! `PredKind` → check-condition mapping ([`pred_condition_and_message`]) and the one
6//! TypeScript string escaper ([`escape_ts_literal`]), shared by the emitter, the
7//! checker's wire defaults and the language server (crate-hygiene A2).
8//!
9//! **Invariant:** this crate depends on `bynk-syntax` **only** (for
10//! [`bynk_syntax::span::Span`], reused unchanged rather than redefined —
11//! `bynk-emit`'s own `TypeRef`/`Ir`
12//! machinery is not visible here, and never will be: a function taking one
13//! would not compile, the dependency isn't present, by design). `cargo tree
14//! -p bynk-ts` shows `bynk-syntax` and nothing else. Matches the same
15//! load-bearing shape `bynk_driver::render`'s own module doc states for itself
16//! (`bynk-driver/src/render.rs`).
17//!
18//! **What exists here today (P7.5, #1307 → P7.8, #1313).** The reference's
19//! own §7.1 sketch names four tree enums (`TsStmt`/`TsExpr`/`TsType`/
20//! `TsDecl`) with real variants (`Const`, `Let`, `Binary`, `Named`, `Class`,
21//! …), but only as a variant-name list, not a field-level design. P7.5
22//! built only [`TsStmt`]'s `Verbatim` escape hatch ([`VerbatimOrigin`]-
23//! tagged text, Q2, `design/tracks/the-typescript-tree.md` §3.2). P7.8
24//! (#1313) adds the rest — [`TsExpr`]/[`TsType`]/[`TsDecl`], plus real
25//! `TsStmt` kinds — but not the sketch's full variant list: only what
26//! `bynk-emit/src/emitter/events_fanout.rs` (Arc C's real next file —
27//! P7.8's own accepted proposal corrected the track doc's stale schedule,
28//! `design/tracks/the-typescript-tree.md` §6/§9) concretely needs, grounded
29//! against that file's own real shape. `bynk-emit` still builds no
30//! [`TsProgram`] beyond `Verbatim` — Arc C's own first slice is what starts
31//! converting real emission into real nodes, file by file; this crate
32//! exists so that conversion has somewhere to land, following R10.3's own
33//! "carve prospectively, at the moment the dependency appears" precedent
34//! (`bynk-strip`'s own carve is the control case cited for this).
35
36// The README's `rust` examples are compiled (and, unless marked `no_run`, run)
37// as doctests, so they cannot rot (#1645). `cfg(doctest)` keeps this item out of
38// every build and out of the docs.rs front page, which the `//!` docs above own.
39#[cfg(doctest)]
40#[doc = include_str!("../README.md")]
41struct ReadmeDoctests;
42
43mod await_scan;
44mod lint;
45mod name_closure;
46mod predicate;
47mod printer;
48mod program;
49mod source_map;
50
51pub use await_scan::expr_contains_await;
52pub use lint::{Violation, verbatim_violations};
53pub use name_closure::{
54    ModuleExports, NamespaceMemberUse, module_exports, namespace_member_uses, raw_statement_texts,
55    text_idents, type_only_value_uses, unbound_names, unbound_names_in, unbound_names_providing,
56    value_imports,
57};
58pub use predicate::{
59    decimal_range_condition, decimal_signed_coef, escape_ts_literal, pred_condition_and_message,
60    pred_condition_and_message_for, pred_condition_and_message_over,
61};
62pub use printer::{
63    Printed, print, print_class_method, print_class_method_and_merge, print_expr,
64    print_multi_source, print_object_entry, print_stmt, print_stmt_and_merge,
65    print_stmt_with_spans, print_type,
66};
67pub use program::{
68    ExportedName, TsArrowBody, TsBinaryOp, TsBindingName, TsClassCtor, TsClassField, TsClassMethod,
69    TsDecl, TsDeclarator, TsExpr, TsLit, TsMappedModifier, TsObjectEntry, TsParam, TsProgram,
70    TsStmt, TsSwitchCase, TsType, TsTypeMember, TsUnaryOp, VerbatimOrigin,
71};
72pub use source_map::SourceMapBuilder;