---
title: "rawStmt(): function in Authoring, TypeShade API reference"
description: "rawStmt, a function in Authoring. Author a raw statement, the escape hatch that splices verbatim text into a function body."
url: https://typeshade.dev/api/rawstmt/
language: en
---

# `rawStmt()`

Function in Authoring

Author a raw statement, the escape hatch that splices verbatim text into a function body.

`import { rawStmt } from 'typeshade/core/ir'`

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

## Syntax

```ts
function rawStmt(payload: RawPayload): RawStmt
```

## Parameters

**`payload` `RawPayload`**

the per-target spellings, at least one of `wgsl` and `glsl`.

## Return value

`RawStmt`

the raw statement node, ready to place in a body array.

## Exceptions

**[`SD0030`](https://typeshade.dev/reference/errors/sd0030/)**

One side may be omitted, and the other backend then throws SD0030 naming the missing side and quoting the side you did give, so leaving a side out states that the module does not build for that target.

## Description

Reach for it when a statement has to be hand-written: a string from another generator, or a construct the IR does not model.

The payload carries one spelling per target, `{ wgsl, glsl }`. The meaning is fixed, only the spelling differs, and each backend splices its own side. One side may be omitted, and the other backend then throws [`SD0030`](https://typeshade.dev/reference/errors/sd0030/) naming the missing side and quoting the side you did give, so leaving a side out states that the module does not build for that target. At least one side is required at the type level: `rawStmt({})` does not compile.

Only the first line receives the enclosing body’s indent. The emitter prepends that indent to the payload as a whole, so line two onward of a multi-line payload lands at column zero. Indent the continuation lines yourself when the output shape matters.

Identifiers inside the payload are yours to keep valid. Nothing reads into raw text, so nothing rewrites it, and the GLSL backend renames params and locals that collide with GLSL reserved words (`in`, `sample`, `filter`, `texture`, and the rest); a `glsl` payload naming the pre-rename identifier references a variable the renamed text does not have. Only the GLSL backend renames, so the risk is one-sided even though the contract is the same on both. For the same reason a module holding a raw statement makes `mangle` a no-op module-wide, and the CPU oracle, the same module run in double precision on the CPU, throws when it reaches raw text it cannot evaluate.

This factory returns the `Stmt`, which is what you want when assembling a `Stmt[]` body by hand. Inside a fluent [`fn`](https://typeshade.dev/api/fn/) body use `b.raw(payload)` instead: a bare `rawStmt(...)` call there is a discarded expression, since the returned statement is never pushed and nothing is emitted.

## Examples

### Example

```ts
import { fn, rawStmt, vec4fT } from 'typeshade/core/ir'

// Inside a fn body, through the builder:
const fs = fn('fs_main', {}, vec4fT, (_p, b) => {
  b.raw({ wgsl: 'return vec4<f32>(1.0, 0.0, 0.0, 1.0);', glsl: 'return vec4(1.0, 0.0, 0.0, 1.0);' })
}, { stage: 'fragment' })

// Assembling a Stmt[] by hand:
const stmt = rawStmt({ wgsl: 'discard;', glsl: 'discard;' })
```

## See also

- [`fn`](https://typeshade.dev/api/fn/)
- [`RawPayload`](https://typeshade.dev/api/rawpayload/)

## Source

[`src/core/ir/builder.ts`, line 1184](https://github.com/typeshade/typeshade/blob/af54ddad5/src/core/ir/builder.ts#L1184), at commit af54ddad5
