stmt_block

Macro stmt_block 

Source
macro_rules! stmt_block {
    ($stmts:expr) => { ... };
}
Expand description

Creates a block statement ({ ... }) from a vector of statements.

This macro wraps a Vec<Stmt> into a BlockStmt, which represents a { ... } block in JavaScript/TypeScript. Useful when you need to group multiple statements into a single statement.

§Examples

Wrapping multiple statements in a block:

use macroforge_ts_syn::{stmt_block, parse_ts_str};
use swc_core::ecma::ast::Stmt;

let stmt1: Stmt = parse_ts_str("console.log('hello');").unwrap();
let stmt2: Stmt = parse_ts_str("console.log('world');").unwrap();

let block = stmt_block!(vec![stmt1, stmt2]);
// Generates: { console.log('hello'); console.log('world'); }

Using with generated code:

use macroforge_ts_syn::stmt_block;

fn wrap_in_block(statements: Vec<Stmt>) -> Stmt {
    stmt_block!(statements)
}