SwitchChain
이 페이지에서

SwitchChain

클래스, 작성 분류

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'

시그니처, 설명, 예제는 커밋 c66579bf의 컴파일러 소스에서 그대로 가져온 영어 원문입니다.

구문

class SwitchChain

설명

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.

예제

예제

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

생성자

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

인스턴스 메서드

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.

함께 보기

소스

src/core/ir/builder.ts, 2090행, 커밋 c66579bf 기준

이 페이지 편집 문제 보고