autoVars()
Function in Emit
Turns every value that is later assigned to into a WGSL var.
import { autoVars } from 'typeshade'
The signature, the description and the examples come from the compiler's own source at commit 26de7be8.
Syntax
function autoVars(m: ModuleDecl): ModuleDeclParameters
mModuleDeclThe module to process.
Return value
A new module with the rewritten functions; m itself is unchanged.
Description
A shader author writes a mutable value as a plain const x = expr and then calls
x.assign(...) or a compound assignment such as += on it; nothing marks x as a
variable up front. This pass finds each such value in every function of m, declares a
var for it just before the first statement that uses it, and rewrites every reference
to that value, including the assignment targets themselves, to read and write the new
var. An assignment through a member or index access (c.a, m[i]) declares the var
for the base value c or m. Values that already have a name (function parameters,
constants, override constants and existing var or let bindings) are left alone.
Source
src/core/passes/opt/auto-vars.ts, line 188, at commit 26de7be8