Skip to main content

print_stmt_and_merge

Function print_stmt_and_merge 

Source
pub fn print_stmt_and_merge(
    out: &mut String,
    stmt: &TsStmt,
    depth: usize,
    map: &mut SourceMapBuilder,
    source_id: usize,
)
Expand description

print_stmt’s own sibling (#1477), the TsDecl::Function-body counterpart to print_class_method_and_merge: identical rendering, but merges any nested_map stmt carries — on stmt itself, or on anything nested inside it (a function’s body, a class’s constructor/ methods, …) — into map as it prints, at the real print-time offset — the same offset bynk-emit’s own emit_free_fn (emitter/emit.rs) used to recover by exact arithmetic over the returned text, guarded by a debug_assert!, before #1480 converted it to set nested_map directly instead. Kept separate from print_stmt itself so every existing caller’s own call sites are untouched. source_id is map’s own registered source this statement’s content belongs to (see this crate’s own private MergeTarget’s own doc for why this can’t just be hardcoded).

Appends to the caller’s own out, unlike print_stmt’s own return-a-fresh-String shape — the merge computes each checkpoint’s absolute offset from out.len() as this statement’s own text is written, so it must be the caller’s real, already-populated buffer, not a throwaway local one starting at 0. Returning a fresh string here (the first shape this function took, caught before merge) would silently record every checkpoint at the wrong offset the moment the caller spliced the returned text anywhere but the very start of its own buffer.