SwitchChain
On this page

SwitchChain

Class in Authoring

switch (scrut) { case n: …; default: … } as a chainable statement builder, mirroring the If(…).elif(…).else(…) surface so integer dispatch reads the familiar imperative way: declare a Var(/api/var/) holding the default, then assign it inside the case arms.

import { SwitchChain } from 'typeshade'

The signature, the description and the examples come from the compiler's own source at commit 26de7be8.

Syntax

class SwitchChain

Description

Emits a real switch on both targets. .case(n, body) adds a case label; .default(body?) adds the optional default arm and ends the chain, pushing the statement.

Examples

Example

const radiusPx = Var(rawRadius)
Switch(sizeMode)
.case(1, () => radiusPx.assign(rawRadius.div(viewport.z)))
.case(2, () => radiusPx.assign(rawRadius.mul(2)))
.default(() => {})

Constructor

new SwitchChain(private readonly scrut: ReadonlyNode<'i32' | 'u32'>)

Instance methods

case (value: number, body: () => void): SwitchChain

Add a case value: arm. Returns the chain.

default (body?: () => void): void

Add the optional default: arm and end the chain. The switch statement is pushed onto the innermost scope here, so a chain without .default() emits nothing.

See also

Source

src/core/ir/builder.ts, line 2090, at commit 26de7be8

Edit this page Report a problem