Skip to content

Commit 63c4faf

Browse files
committed
fix(glsl): fix member expression
1 parent a0842d8 commit 63c4faf

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/glsl/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,13 @@ function ident(node) {
181181
}
182182

183183
function memExp(node) {
184-
const { object, property } = node;
184+
const { object, property, computed } = node;
185185
if (property.type === 'Literal' || property.type === 'CallExpression') {
186186
return `${handleNode(object)}[${handleNode(property)}]`;
187187
}
188-
// console.log('memExp', object.name, node);
188+
if (computed) {
189+
return `${handleNode(object)}[${handleNode(property)}]`;
190+
}
189191
return `${handleNode(object)}.${handleNode(property)}`;
190192
}
191193

test/glsl/index.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,22 @@ MyType bar;
190190
assert.equal(glsl.trim(), expected.trim());
191191
});
192192

193+
it('works with mat access arrays', () => {
194+
const { glsl } = buildGLSL(() => {
195+
let foo = mat4(1.0);
196+
let x = int(3);
197+
let bar = float(foo[x][1]);
198+
});
199+
200+
const expected = `
201+
mat4 foo = mat4(1.0);
202+
int x = int(3);
203+
float bar = float(foo[x][1]);
204+
`;
205+
206+
assert.equal(glsl.trim(), expected.trim());
207+
});
208+
193209
it('works with float arrays', () => {
194210
const { glsl } = buildGLSL(() => {
195211
let foo = float([1.0, 2.0]);

0 commit comments

Comments
 (0)