11import { stitch } from '../core/resolve/stitch.ts' ;
22import { isDisarray , MatrixColumnsAccess } from '../data/dataTypes.ts' ;
33import { derefSnippet } from '../data/ref.ts' ;
4- import { type Origin , snip , type Snippet } from '../data/snippet.ts' ;
4+ import { snip , withSideEffects } from '../data/snippet.ts' ;
5+ import type { Origin , Snippet } from '../data/snippet.ts' ;
56import { vec2f , vec3f , vec4f } from '../data/vector.ts' ;
67import { type BaseData , isPtr , isVec , isWgslArray , isWgslStruct } from '../data/wgslTypes.ts' ;
78import { isKnownAtComptime } from '../types.ts' ;
@@ -44,25 +45,31 @@ export function accessIndex(target: Snippet, indexArg: Snippet | number): Snippe
4445 return target . value . elements [ index . value as number ] ;
4546 }
4647
47- return snip (
48- isKnownAtComptime ( target ) && isKnownAtComptime ( index )
49- ? // oxlint-disable-next-line typescript/no-explicit-any -- it's fine, it's there
50- ( target . value as any ) [ index . value as number ]
51- : stitch `${ target } [${ index } ]` ,
52- elementType ,
53- /* origin */ origin ,
48+ return withSideEffects (
49+ target . possibleSideEffects || index . possibleSideEffects ,
50+ snip (
51+ isKnownAtComptime ( target ) && isKnownAtComptime ( index )
52+ ? // oxlint-disable-next-line typescript/no-explicit-any -- it's fine, it's there
53+ ( target . value as any ) [ index . value as number ]
54+ : stitch `${ target } [${ index } ]` ,
55+ elementType ,
56+ /* origin */ origin ,
57+ ) ,
5458 ) ;
5559 }
5660
5761 // vector
5862 if ( isVec ( target . dataType ) ) {
59- return snip (
60- isKnownAtComptime ( target ) && isKnownAtComptime ( index )
61- ? // oxlint-disable-next-line typescript/no-explicit-any -- it's fine, it's there
62- ( target . value as any ) [ index . value as any ]
63- : stitch `${ target } [${ index } ]` ,
64- target . dataType . primitive ,
65- /* origin */ target . origin ,
63+ return withSideEffects (
64+ target . possibleSideEffects || index . possibleSideEffects ,
65+ snip (
66+ isKnownAtComptime ( target ) && isKnownAtComptime ( index )
67+ ? // oxlint-disable-next-line typescript/no-explicit-any -- it's fine, it's there
68+ ( target . value as any ) [ index . value as any ]
69+ : stitch `${ target } [${ index } ]` ,
70+ target . dataType . primitive ,
71+ /* origin */ target . origin ,
72+ ) ,
6673 ) ;
6774 }
6875
@@ -79,7 +86,10 @@ export function accessIndex(target: Snippet, indexArg: Snippet | number): Snippe
7986 ( target . value . matrix . dataType as BaseData ) . type as keyof typeof indexableTypeToResult
8087 ] ;
8188
82- return snip ( stitch `${ target . value . matrix } [${ index } ]` , propType , /* origin */ target . origin ) ;
89+ return withSideEffects (
90+ target . possibleSideEffects || index . possibleSideEffects ,
91+ snip ( stitch `${ target . value . matrix } [${ index } ]` , propType , /* origin */ target . origin ) ,
92+ ) ;
8393 }
8494
8595 // matrix
0 commit comments