@@ -158,7 +158,7 @@ function operatorToType<
158158
159159const unaryOpCodeToCodegen = {
160160 '-' : neg [ $gpuCallable ] . call ,
161- 'void' : ( ) => snip ( '' , wgsl . Void , 'constant' ) ,
161+ 'void' : ( ) => snip ( undefined , wgsl . Void , 'constant' ) ,
162162} satisfies Partial <
163163 Record < tinyest . UnaryOperator , ( ...args : never [ ] ) => unknown >
164164> ;
@@ -196,6 +196,7 @@ class WgslGenerator implements ShaderGenerator {
196196 try {
197197 this . ctx . indent ( ) ;
198198 const body = statements . map ( ( statement ) => this . statement ( statement ) )
199+ . filter ( ( statement ) => statement . length > 0 )
199200 . join ( '\n' ) ;
200201 this . ctx . dedent ( ) ;
201202 return `{
@@ -264,6 +265,10 @@ ${this.ctx.pre}}`;
264265 if ( ! id ) {
265266 throw new Error ( 'Cannot resolve an empty identifier' ) ;
266267 }
268+ if ( id === 'undefined' ) {
269+ return snip ( undefined , wgsl . Void , 'constant' ) ;
270+ }
271+
267272 const res = this . ctx . getById ( id ) ;
268273
269274 if ( ! res ) {
@@ -849,8 +854,9 @@ ${this.ctx.pre}}`;
849854 statement : tinyest . Statement ,
850855 ) : string {
851856 if ( typeof statement === 'string' ) {
852- const resolved = this . ctx . resolve ( this . identifier ( statement ) . value ) . value ;
853- return resolved . length === 0 ? '' : `${ this . ctx . pre } ${ resolved } ;` ;
857+ const id = this . identifier ( statement ) ;
858+ const resolved = id . value && this . ctx . resolve ( id . value ) . value ;
859+ return resolved ? `${ this . ctx . pre } ${ resolved } ;` : '' ;
854860 }
855861
856862 if ( typeof statement === 'boolean' ) {
@@ -1123,8 +1129,9 @@ ${this.ctx.pre}else ${alternate}`;
11231129 return `${ this . ctx . pre } break;` ;
11241130 }
11251131
1126- const resolved = this . ctx . resolve ( this . expression ( statement ) . value ) . value ;
1127- return resolved . length === 0 ? '' : `${ this . ctx . pre } ${ resolved } ;` ;
1132+ const expr = this . expression ( statement ) ;
1133+ const resolved = expr . value && this . ctx . resolve ( expr . value ) . value ;
1134+ return resolved ? `${ this . ctx . pre } ${ resolved } ;` : '' ;
11281135 }
11291136}
11301137
0 commit comments