pub enum TsExpr {
Show 18 variants
Ident(String),
Member {
object: Box<TsExpr>,
property: String,
},
OptionalMember {
object: Box<TsExpr>,
property: String,
},
Index {
object: Box<TsExpr>,
index: Box<TsExpr>,
},
OptionalIndex {
object: Box<TsExpr>,
index: Box<TsExpr>,
},
Arrow {
params: Vec<TsParam>,
is_async: bool,
generics: Vec<String>,
return_type: Option<TsType>,
body: Box<TsArrowBody>,
},
Call {
callee: Box<TsExpr>,
args: Vec<TsExpr>,
},
New {
callee: Box<TsExpr>,
args: Vec<TsExpr>,
},
Object {
entries: Vec<TsObjectEntry>,
multiline: bool,
},
Array {
items: Vec<TsExpr>,
multiline: bool,
},
TemplateLit {
parts: Vec<String>,
exprs: Vec<TsExpr>,
},
Await(Box<TsExpr>),
As {
expr: Box<TsExpr>,
ty: TsType,
},
Unary {
op: TsUnaryOp,
expr: Box<TsExpr>,
},
Binary {
op: TsBinaryOp,
left: Box<TsExpr>,
right: Box<TsExpr>,
},
Conditional {
test: Box<TsExpr>,
consequent: Box<TsExpr>,
alternate: Box<TsExpr>,
},
Paren(Box<TsExpr>),
Lit(TsLit),
}Expand description
An expression. Only the shapes events_fanout.rs concretely uses
(Decision B) — not the reference sketch’s full TsExpr list (Arrow,
Cond, TemplateLit, Spread are all unused in the grounding file and
deliberately not built here). Arc C slice 3 (#1321, workers.rs) adds
Arrow, OptionalMember/OptionalIndex (Decision A, gaps 3/4) — this
slice’s own real, grounded needs.
Variants§
Ident(String)
Member
object.property.
OptionalMember
object?.property — the optional-chaining form of TsExpr::Member.
A distinct variant, not an optional: bool flag on Member itself
(#1321’s own Decision A, gap 4, left the mechanism to the
implementation): a flag would touch every one of Member’s
already-many real call sites (events_fanout.rs, this crate’s own
printer tests) that never need one, where a separate variant touches
none of them — narrower, matching this track’s own repeated
“smallest correct scope” judgment. workers.rs’s own secret-probe
idiom (emit_websocket_upgrade/emit_http_wrapper/
emit_secret_lookup, three identical real sites) is the only
grounding.
Index
object[index].
OptionalIndex
object?.[index] — the optional-chaining form of TsExpr::Index,
the same real grounding and the same “separate variant, not a flag”
reasoning as TsExpr::OptionalMember.
Arrow
(params) => body (is_async: false) or async (params) => body
(is_async: true) — an arrow function, expression- or block-bodied
(see TsArrowBody). is_async added by #1327: emit_composition_root’s
own __eventsDispatch closure (async (events: Array<...>) => {...})
is the first real Arrow site that’s async — mirrors
TsDecl::Function’s own is_async field (#1325), added for the same
reason. generics/return_type added by #1339: emit_sum_type’s
own generic payload-constructor arrows (<T>(name: T): Sum<T> => (...)) need both — bare generic names only (empty for every
non-generic site, the overwhelming majority), matching
TsObjectEntry::Method.generics’s own (#1337) identical convention;
return_type mirrors TsDecl::Function.return_type’s own existing
Option<TsType> shape — a real gap the accepted proposal’s own
grounding named generics for but missed: every one of this file’s
own real generic-payload arrows carries an explicit return-type
annotation the arrow itself owns (: {name}{params}), not something
the body’s own type alone determines.
body’s type became TsArrowBody (#1435, Arc E slice 1): from
P7.8 through #1434 this field was a bare Box<TsExpr> — expression-
bodied only, “extend narrowly” (the same posture TsBinaryOp takes
for its own operator table), since every real site up to and
including #1339’s generic payload-constructor arrows had an
expression body. serialisation.rs’s serialise_field_expr_wire
(bynk-emit) is the first real site that doesn’t: its Float
non-finite guard is a genuine statement-bodied IIFE (((v: number) => { if (!Number.isFinite(v)) throw new Error(...); return v as JsonValue; })(value)), not reducible to one expression. Widening the
existing field (TsArrowBody::Expr(Box<TsExpr>) |
TsArrowBody::Block(Vec<TsStmt>)) rather than adding a second
sibling TsExpr variant matches this file’s own repeated
“extend the existing variant when every real site still needs the
same node kind, only the body shape differs” precedent
(TsObjectEntry::Method.inline, #1337) — every prior Arrow
construction site across the workspace wraps its already-correct
expression body in TsArrowBody::Expr(..), a mechanical change with
no behavior difference.
Fields
body: Box<TsArrowBody>Call
New
Object
A value object literal, e.g. { status: 204 } — comma-separated.
multiline: false (the ordinary case, via TsExpr::object)
always prints on one line, matching TsType::Object’s own
(semicolon-separated) single-line convention for the type-position
shape. multiline: true (via TsExpr::multiline_object) is a
real, grounded gap found implementing Arc C’s first slice (#1317):
events_fanout.rs’s own __eventRoutes table is a top-level
const initializer with one entry per line, each with its own
trailing comma, closing brace at the statement’s own indent —
TypeScript’s ordinary multi-line object-literal convention, which
nothing in this crate could represent before this addition. Only
statement/declaration-level renderers (which already carry depth)
can render this correctly — printer.rs’s own render_stmt_level_ expr, and (#1355) render_multiline_object_entry‘s own Prop arm,
for a multiline: true object nested one level inside ANOTHER
multiline object as one of its own entries’ values —
emit_messages_bundle’s own real doubly-nested { locale: { code: expr, ... }, ... } table. A multiline: true object nested any
OTHER way (an array element, a call argument, a Prop’s value
inside a non-multiline object, …) still renders via the ordinary
depth-unaware render_expr recursion, which cannot honour
multiline — not reachable from any real bynk-emit call site
today, but worth knowing before nesting one that way.
Array
An array literal, e.g. [{ binding: "x", service: "y" }].
multiline: false (the ordinary case, via TsExpr::array) always
prints on one line, comma-separated — every real site before this
slice. multiline: true (via TsExpr::multiline_array) is #1325’s
own real gap: emit_test_main’s own modules array (one { name, run } entry per test, one per line, each with its own trailing
comma, closing ] at the statement’s own indent) — the exact same
shape TsExpr::Object’s own multiline field already represents
for object literals, just for an array. Same reachability boundary as
Object’s own multiline field (see its own doc, updated by
#1355): render_stmt_level_expr and render_multiline_object_ entry’s own Prop arm both honour it; nested any other way, a
multiline: true array falls back to single-line via the ordinary
depth-unaware render_expr recursion.
TemplateLit
`text${expr}more text` — a template literal. parts.len() is
always exprs.len() + 1 (parts[0] before the first substitution,
parts[i+1] after exprs[i], …). #1325’s own real, first grounding
for this shape (bynk-ts’s own module doc named TemplateLit
explicitly “unused in the grounding file” until now):
emit_test_main’s own `${m.name}:`/`${passed} passed, ${failed} failed.` lines.
parts are printed verbatim — the printer applies no escaping of
its own. The same “the field is already a raw-text slot” reasoning
TsDecl::Import’s own names field doc already uses, not a new
pattern: emit_test_main’s own two real ✓/✗ substitution lines embed
a literal ✓/✗ JS unicode escape as pre-formed ASCII
text (six literal characters, not the actual glyph) — an escaper
mirroring TsLit::Str’s own (which escapes every \ it sees)
would double that literal backslash into \\u2713, corrupting the
exact byte-golden output this slice must match. Every real part in
emit_test_main is static, compiler-authored text (never Bynk user
data), so there is no real content this boundary loses safety on
today — a future caller passing untrusted/dynamic text into parts
is responsible for pre-escaping backtick/${/\ itself before
constructing one.
Await(Box<TsExpr>)
As
expr as ty.
Unary
Binary
Conditional
test ? consequent : alternate — #1323’s own real gap: method === "HEAD" ? headResponse(__response) : __response (once per GET
route) and method === "OPTIONS" ? 204 : 405 (the method-fallthrough
path). The lowest-precedence expression form after Arrow — needs
the same parenthesization-rule coverage Arrow got in review of
#1322 (needs_parens_as_operand/render_binary_operand/As’s own
local rule), added proactively in this same slice rather than left
for a review round to re-find.
Paren(Box<TsExpr>)
An explicit, printer-preserved parenthesization — distinct from every
other variant’s own precedence-derived parens (render_operand/
render_binary_operand), which the printer adds or omits based on
what the wrapped expression is. Paren instead always prints
(<inner>) regardless of inner’s own shape or precedence. #1323’s
own real, narrow need: workers_entry.rs’s CORS-preflight guard
wraps its own path-match condition in unconditional parens
(&& ({cond})) even when cond reduces to a single equality check
with no operator lower-precedence than the outer && — a real case
the precedence-derived rules correctly do not parenthesize (they’re
answering “is this needed for correctness”, not “did the source
always write parens here”). Not a general escape hatch: every other
real site in this file’s own content still goes through the ordinary
precedence machinery unchanged.
Lit(TsLit)
Implementations§
Source§impl TsExpr
impl TsExpr
Sourcepub fn object(entries: Vec<(String, TsExpr)>) -> Self
pub fn object(entries: Vec<(String, TsExpr)>) -> Self
The ordinary, single-line object literal, Prop-only — every entry
is key: value. events_fanout.rs’s own entries (and this crate’s
own printer tests) are all this shape; kept taking a plain
Vec<(String, TsExpr)> rather than Vec<TsObjectEntry> so none of
those existing call sites needed to change when TsObjectEntry was
added (#1321) — see TsExpr::object_entries for the mixed-entry
form workers.rs itself needs (shorthand/spread/method entries).
Sourcepub fn multiline_object(entries: Vec<(String, TsExpr)>) -> Self
pub fn multiline_object(entries: Vec<(String, TsExpr)>) -> Self
One entry per line, each with its own trailing comma — see
TsExpr::Object’s own doc for the real shape and the
depth-awareness this needs at the print site. Prop-only, the same
convenience TsExpr::object’s own doc explains.
Sourcepub fn object_entries(entries: Vec<TsObjectEntry>) -> Self
pub fn object_entries(entries: Vec<TsObjectEntry>) -> Self
The single-line object literal, taking TsObjectEntry directly —
for a mixed entry list (shorthand/spread/method alongside Prop),
which TsExpr::object’s own Vec<(String, TsExpr)> convenience
can’t represent. #1321’s own real grounding: workers.rs’s local
capability-provider deps object mixes shorthand names
({ cap1, cap2 }) with explicit key: value entries
(__exec: exec) in one literal.
Sourcepub fn multiline_object_entries(entries: Vec<TsObjectEntry>) -> Self
pub fn multiline_object_entries(entries: Vec<TsObjectEntry>) -> Self
TsExpr::multiline_object’s own TsObjectEntry sibling —
#1321’s own real grounding: workers.rs’s compose-returned
surface object is one shorthand-async-Method entry per wrapper,
one per line.
Sourcepub fn array(items: Vec<TsExpr>) -> Self
pub fn array(items: Vec<TsExpr>) -> Self
The ordinary, single-line array literal — every real site before #1325.
Sourcepub fn multiline_array(items: Vec<TsExpr>) -> Self
pub fn multiline_array(items: Vec<TsExpr>) -> Self
One entry per line, each with its own trailing comma — see
TsExpr::Array’s own doc for the real shape and the
depth-awareness this needs at the print site. #1325’s own real
grounding: emit_test_main’s own modules array.
Sourcepub fn template_lit(parts: Vec<String>, exprs: Vec<TsExpr>) -> Self
pub fn template_lit(parts: Vec<String>, exprs: Vec<TsExpr>) -> Self
A template literal — see TsExpr::TemplateLit’s own doc for the
real shape and its no-escaping boundary. The sole caller-facing
invariant (parts.len() == exprs.len() + 1) is asserted here rather
than left to render_expr’s own parts-driven loop, which would
otherwise silently drop trailing exprs on a malformed tree instead
of failing loudly (review of #1326, finding 1).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TsExpr
impl RefUnwindSafe for TsExpr
impl Send for TsExpr
impl Sync for TsExpr
impl Unpin for TsExpr
impl UnsafeUnpin for TsExpr
impl UnwindSafe for TsExpr
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);