IfChain
Class in Authoring
The chain object Builder.if and If(/api/if/) return, so .elif(...) and .else(...) read top to bottom in authored order.
import { IfChain } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
class IfChainDescription
The chain object Builder.if and If return, so .elif(...) and
.else(...) read top to bottom in authored order. It is reached only through the call
that starts a chain. Its methods extend the same if statement in place, pushed once on
the first arm, so a chain without a trailing .else still emits a valid if / else if
with no else block.
Examples
Example
If(p.idx.eq(1), () => { pos.assign(vec2(3, -1))}).elif(p.idx.eq(2), () => { pos.assign(vec2(-1, 3))})Constructor
new IfChain(private readonly parent: Builder, private readonly arms: Array<{ cond: Expr; body: Stmt[] }>, private readonly setElse: (body: Stmt[]) => void)
Instance methods
elif(cond: ReadonlyNode<'bool'>, body: (b: Builder) => ReadonlyNode | void): IfChainAdd an
else if (cond) { body }arm. Returns the chain. A body that returns a value is rejected withSD0115, as forBuilder.if.else(body: (b: Builder) => ReadonlyNode | void): voidAdd the
else { body }block and end the chain. A body that returns a value is rejected withSD0115, as forBuilder.if.
See also
Source
src/core/ir/builder.ts, line 388, at commit 26de7be8