pub enum TsDecl {
Show 13 variants
Import {
type_only: bool,
names: Vec<String>,
from: String,
},
ImportNamespace {
type_only: bool,
alias: String,
from: String,
},
ImportDefault {
alias: String,
from: String,
},
ReExport {
names: Vec<String>,
from: String,
},
ReExportAll {
from: String,
},
Export(Box<TsDecl>),
Interface {
name: String,
type_params: Vec<String>,
members: Vec<TsTypeMember>,
},
ConstDecl {
name: String,
ty: Option<TsType>,
init: TsExpr,
},
Class {
name: String,
fields: Vec<TsClassField>,
constructor: Option<TsClassCtor>,
methods: Vec<TsClassMethod>,
},
Function {
name: String,
generics: Vec<String>,
params: Vec<TsParam>,
return_type: Option<TsType>,
body: Vec<TsStmt>,
is_async: bool,
inline: bool,
},
TypeAlias {
name: String,
type_params: Vec<String>,
ty: TsType,
},
ExportDefault(TsExpr),
DeclareConst {
name: String,
ty: TsType,
},
}Expand description
A top-level declaration. Import, Export, Interface, ConstDecl,
and Class were events_fanout.rs’s own grounding (P7.8’s own note:
“not the sketch’s Function/TypeAlias — unused in the grounding
file”). #1321 (workers.rs) needed both after all — a real gap the
accepted proposal’s own Framing didn’t name (its own “no other gap
surfaced” checked TsStmt/TsExpr/TsType shapes, not TsDecl ones):
compose.ts’s own export function compose(env: Env, …) { … } is a
top-level function declaration, and (when the Worker has agents or
publishes events) a type DurableObjectNamespace = { … }; fallback
alias sits alongside it. Named explicitly as a deviation from the
accepted proposal’s own catalogue, not silently added — both are
mechanical, direct TsDecl siblings of ConstDecl/Class already
here, the same “small, grounded, same class of gap” this track’s own
history repeatedly found and closed (P7.8’s Assign/Continue/
TryCatch, Arc C slice 1’s Comment).
Variants§
Import
import { a, b } from "spec"; (type_only: false) or
import type { a, b } from "spec"; (type_only: true). Only the
named-imports form — events_fanout.rs never uses a default
import, so none is represented. names entries are pushed verbatim
(printer.rs’s own names.join(", ")), so a renamed import
(messagesLocales as __locale_declaredLocales, workers.rs’s own
locale-negotiation import) is one opaque String entry, not a
structured rename — the same “the field is already a raw-text slot”
reasoning that also covers a type-prefixed single specifier
("type KVNamespace") inside an otherwise non-type_only import.
ImportNamespace
import * as alias from "spec"; — a namespace import, structurally
different from TsDecl::Import’s braced named-imports form (no
{ }, one bound name for the whole module). #1321’s own real gap:
workers.rs’s compose.ts imports handlers.js and each
referenced unit’s binding module this way; events_fanout.rs never
used one. type_only (Arc C, step (10), #1392) mirrors
TsDecl::Import’s own identical field, a parallel gap by
omission, not deliberate design — emit_cross_context_namespace_ imports’s own real import type * as ns from "..."; form (a
Workers-mode consumed-context import reaching the callee’s types
only, #661) had no way to represent the type keyword until now.
ImportDefault
import name from "spec"; — a default import, structurally
different from both TsDecl::Import (braced named-imports form)
and TsDecl::ImportNamespace (* as form) — no braces, no * as,
one bound local name for the module’s own default export. No
type_only form — nothing in the grounding file default-imports a
type. Arc C, slice 37 (#1409, tests_emit.rs’s own slice G): a
per-participant import worker_{ns} from "../workers/{dir}/ index.js"; (the participant’s own Worker entry module’s default
export) is the first real default import anywhere in bynk-emit’s
own converted content — every prior import site is either named
(TsDecl::Import) or namespace (TsDecl::ImportNamespace).
ReExport
export { a, b } from "spec"; — a re-export, structurally distinct
from both TsDecl::Import (which binds locally, carries no
export keyword) and TsDecl::Export (which wraps a whole
declaration, not a braced name list re-pointed at another module).
#1323’s own real gap: workers_entry.rs re-exports each agent’s
Durable Object class from ./handlers.js, and (when the context
publishes events) the fan-out DO’s class from ./events_fanout.js.
No type_only form — nothing in the grounding file re-exports a
type-only name.
ReExportAll
export * from "spec"; — a wildcard re-export, structurally distinct
from TsDecl::ReExport (which always carries a braced name list —
an empty names there would render the ill-formed export { } from "spec";, not this). Mirrors TsDecl::ImportNamespace’s own
“no braces, no name list, one bound target” shape, on the export
side. #1329’s own real gap: emit_commons_barrel
(bynk-emit/src/project/tests_emit.rs) builds a multi-file
commons unit’s barrel module as one export * line per
constituent source file.
Export(Box<TsDecl>)
Marks the wrapped declaration exported — export class Foo { .. }
is Export(Box::new(Class { .. })). A wrapper, not a per-variant
exported: bool field, matching the reference sketch’s own naming
(TsDecl::Export is a peer variant, not a modifier on each other
one).
Interface
type_params/per-member readonly (#1339’s own real gap):
emit_record_type’s own export interface {name}{params} { readonly {field}: {ty}; ... } — bare generic names (matching
ts_type_params’s/TsObjectEntry::Method.generics’s own
convention) and a readonly modifier every real field here
carries. members reuses TsTypeMember (the exact same shape
TsType::Object’s own structural members already use) rather
than a bespoke tuple, since readonly is already that type’s own
field — this interface’s real content has never needed
Method/Index, but nothing about reusing the shared type
forecloses a future slice that does.
ConstDecl
A top-level const — distinct from TsStmtKind::Const (private —
reachable through TsStmt::const_stmt), the local
form.
Class
Function
function name(params): ret { body } (is_async: false) or async function name(params): ret { body } (is_async: true) — a top-level
function declaration. is_async added by #1325: workers.rs’s own
one real site (compose) is never async, so the field didn’t exist
until emit_test_main’s own top-level async function main() {...}
needed it — the exact “extend narrowly, add it when a future slice’s
own grounding needs it” deferral this variant’s own history already
named. generics added by #1351: emit_free_fn’s own v0.20a erased
generics (export function foo<T>(...)) — bare names only, empty
for every non-generic site (compose/main), matching every other
real generics-list precedent in this crate
(TsObjectEntry::Method.generics #1337, TsExpr::Arrow.generics
#1339). inline added by #1369 (Arc C, slice 20, step (9)’s own
second sub-slice): emit_agent’s own zero-factory function
(function __zeroOf{Name}State(): {Name}State { return {...}; }) is
a genuinely single-physical-line declaration — braces and body share
the header’s own line, not render_block_stmts’s always-multi-line
shape. false (every site landed before #1369) renders the ordinary
multi-line body; true reuses render_inline_block’s own compact
{ stmt; stmt; } shape directly at the declaration’s own header
line, the same “one more bool, mirroring an existing precedent”
scope TsObjectEntry::Method.inline (#1337) already set for the
identical single-line-vs-multi-line tension at a different node kind.
Fields
TypeAlias
type name = ty; (non-generic) or type name<T, U> = ty; (via
type_params, #1339’s own real gap: emit_sum_type’s own generic
sum types erase to export type Foo<T> = ...) — a top-level type
alias. workers.rs’s own real site: the DurableObjectNamespace
local fallback type (emitted only when the Worker has agents or
publishes events), never generic — type_params is empty there.
ExportDefault(TsExpr)
export default <expr>; — a default export of an expression, not
a declaration. #1323’s own real gap (workers_entry.rs’s own
top-level shape, export default { fetch, scheduled?, queue? }):
TsDecl::Export wraps a TsDecl (a Class/ConstDecl/etc.,
something with its own name), which cannot represent exporting a
bare, unnamed object-literal expression — so this is its own
variant, not Export(Box::new(ConstDecl { .. })) with a synthetic
name that would print wrong.
DeclareConst
declare const name: ty; — an ambient binding with no initialiser,
narrowing a global TypeScript otherwise doesn’t know about. #1325’s
own real, narrow site: emit_test_main’s own declare const process: { exit(code: number): never; env: { [k: string]: string | undefined } };, narrowing Node’s process global without a @types/node
dependency. Distinct from TsDecl::ConstDecl (always has a real
init expression) — a declare const has none, by definition; a
TsDecl::ConstDecl with a synthetic placeholder init would print
wrong (= <something>; where nothing should appear at all).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for TsDecl
impl RefUnwindSafe for TsDecl
impl Send for TsDecl
impl Sync for TsDecl
impl Unpin for TsDecl
impl UnsafeUnpin for TsDecl
impl UnwindSafe for TsDecl
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);