pub struct TsStmt {
pub span: Option<Span>,
pub nested_map: Option<SourceMapBuilder>,
pub nested_map_source_id: usize,
pub no_blank_before: bool,
/* private fields */
}Expand description
One statement — a Verbatim-tagged escape hatch (still constructible
only via TsStmt::verbatim, per #1307’s Decision D — the
verbatim_sites probe needs exactly one string to line-scan for), or,
from this slice, a real structured kind. The real kinds have no such
sealing: they’re normal typed constructors, not a “wrap opaque text”
escape hatch, so the verbatim_sites concern that motivates verbatim’s
own single-constructor discipline doesn’t apply to them.
Fields§
§span: Option<Span>Where this statement’s content originated in the .bynk source, if
known. Only a top-level statement’s own span is currently recorded
as a source-map checkpoint (crate::printer::print, unchanged
from P7.5/R7.4’s own scope) — a nested statement (inside a Block,
If, ForOf, TryCatch) still carries this field structurally, for
whichever future slice gives sub-statement source maps real value,
but the printer does not yet record a checkpoint from it. Named here
explicitly (P7.8’s own accepted proposal: “an implementation-time
call within this same shape”) rather than left ambiguous.
nested_map: Option<SourceMapBuilder>#1477’s own real gap: a body-bearing statement — in practice always
a TsStmtKind::Raw/TsStmtKind::Verbatim opaque blob standing in
for a lowered function/method body (ADR 0391’s own permanent
exclusion) — carries its own per-statement source-map checkpoints,
collected by the caller’s own body-local SourceMapBuilder before
this node existed. Before this field, every real bynk-emit caller
that needed to merge those checkpoints into its own module map had to
reverse-engineer this node’s own print-time byte offset from the
outside — bynk-emit’s own emit_class_method_and_merge_source_map
(emitter/emit.rs) recovers it by subtracting known lengths and
string-matching the printed text’s own tail, degrading to a silent
skip if that search fails; still live for emit_service/emit_agent’s
own not-yet-converted call sites (#1481/#1482). emit_free_fn used to
recover it by separate, independent exact arithmetic, guarded by a
debug_assert! — #1480 converted it to set this field directly
instead, the first real bynk-emit caller to do so. Both existed
only because nothing reported this node’s own real print-time
offset directly. Setting this field lets the printer itself do the
merge, at the exact offset it is about to write this node’s text to
— no reverse-engineering, no silent-skip fallback (see this crate’s
own private printer::render_block_stmts for the handling). None
for every real site that predates this field and every node whose own
text carries no nested checkpoints of its own — the overwhelmingly
common case, and the reason this is an Option, not a required
field.
nested_map_source_id: usize#1486’s own second real gap, found converting emit_test_module/
emit_integration_module: crate::printer::print’s own top-level
loop always merges a statement’s nested_map
against parent source id 0 (crate::printer::MergeTarget’s own
review-of-#1488 fix threads a source_id through every manual
merge entry point, but print’s own automatic top-level case never
had a per-statement way to say “not 0”) — correct for every
single-source module (emit_project, every other real caller so
far), but wrong for a test/integration module’s own aggregate map,
which registers one source per fragment file a case’s body came from
(SourceMapBuilder::add_source) and needs each such case’s own
top-level statement merged against that source’s id, not the
module’s primary one. 0 (every site predating this field, and
every single-source module after it) keeps the automatic policy
exactly as it already was; a case/property/attack wrapper statement
sets this to its own registered source id before print sees it.
no_blank_before: bool#1486’s own real gap, found converting emit_project/emit_test_ module/emit_integration_module off a single opaque top-level
Verbatim wrap: crate::printer::print’s own top-level loop
inserts exactly one blank line between every pair of adjacent
top-level statements (its own “readability policy” doc, right below
this field’s own use site) — correct for content that was always
designed against that policy (emit_composition_root/emit_test_ main/workers.rs/workers_entry.rs, every one of them zero-diff
from day one), but emit_agent’s own already-shipped Vec<TsStmt>
(#1482, predating this field) was built against the previous
regime — where every real caller printed via bynk-emit’s own
extend_printed/extend_printed_and_merged (a flat per-stmt loop
with no automatic spacing of its own) — and genuinely needs a
same-registry-then-zero-factory pairing with no blank line
between them, matching the pre-conversion hand-written text this
crate’s own zero-diff discipline requires preserving exactly.
true on a statement suppresses the automatic blank line
crate::printer::print would otherwise insert immediately before
it — the narrow, general escape hatch this real, already-shipped
content needs, not a special case hard-coded into the printer for
one specific pair of TsDecl variants. false (every site
predating this field, and the overwhelming majority after it) keeps
the automatic policy exactly as it already is.
Implementations§
Source§impl TsStmt
impl TsStmt
Sourcepub fn verbatim(
origin: VerbatimOrigin,
text: impl Into<String>,
span: Option<Span>,
) -> Self
pub fn verbatim( origin: VerbatimOrigin, text: impl Into<String>, span: Option<Span>, ) -> Self
The one constructor for a Verbatim-kinded statement.
pub fn decl(decl: TsDecl, span: Option<Span>) -> Self
pub fn const_stmt( name: TsBindingName, ty: Option<TsType>, init: TsExpr, span: Option<Span>, ) -> Self
pub fn let_stmt( name: TsBindingName, ty: Option<TsType>, init: Option<TsExpr>, span: Option<Span>, ) -> Self
pub fn expr_stmt(expr: TsExpr, span: Option<Span>) -> Self
pub fn return_stmt(expr: Option<TsExpr>, span: Option<Span>) -> Self
pub fn throw_stmt(expr: TsExpr, span: Option<Span>) -> Self
pub fn if_stmt(cond: TsExpr, then_branch: TsStmt, span: Option<Span>) -> Self
pub fn if_else_stmt( cond: TsExpr, then_branch: TsStmt, else_branch: TsStmt, span: Option<Span>, ) -> Self
Sourcepub fn if_else_same_line_stmt(
cond: TsExpr,
then_branch: TsStmt,
else_branch: TsStmt,
span: Option<Span>,
) -> Self
pub fn if_else_same_line_stmt( cond: TsExpr, then_branch: TsStmt, else_branch: TsStmt, span: Option<Span>, ) -> Self
TsStmt::if_else_stmt’s own sibling with } else { on one line —
#1325’s own real gap, emit_test_main’s own real else spacing. See
TsStmtKind::If’s own doc for why this needs to be a distinct
constructor rather than a change to the existing default.
pub fn for_of( binding: impl Into<String>, iter: TsExpr, body: TsStmt, span: Option<Span>, ) -> Self
Sourcepub fn for_stmt(
name: impl Into<String>,
init: TsExpr,
test: TsExpr,
body: TsStmt,
span: Option<Span>,
) -> Self
pub fn for_stmt( name: impl Into<String>, init: TsExpr, test: TsExpr, body: TsStmt, span: Option<Span>, ) -> Self
for (let <name> = <init>; <test>; <update>++) <body> — see
TsStmtKind::For’s own doc for exactly what this construct does
and does not represent.
pub fn try_catch( try_block: TsStmt, catch_param: Option<impl Into<String>>, catch_block: TsStmt, span: Option<Span>, ) -> Self
pub fn block(stmts: Vec<TsStmt>, span: Option<Span>) -> Self
pub fn continue_stmt(span: Option<Span>) -> Self
pub fn assign(target: TsExpr, value: TsExpr, span: Option<Span>) -> Self
pub fn comment(text: impl Into<String>, span: Option<Span>) -> Self
pub fn doc_comment(text: impl Into<String>, span: Option<Span>) -> Self
pub fn blank(span: Option<Span>) -> Self
pub fn switch_stmt( discriminant: TsExpr, cases: Vec<TsSwitchCase>, span: Option<Span>, ) -> Self
pub fn inline_block(stmts: Vec<TsStmt>, span: Option<Span>) -> Self
pub fn increment(expr: TsExpr, span: Option<Span>) -> Self
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TsStmt
impl RefUnwindSafe for TsStmt
impl Send for TsStmt
impl Sync for TsStmt
impl Unpin for TsStmt
impl UnsafeUnpin for TsStmt
impl UnwindSafe for TsStmt
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);