Skip to content

Commit 8a82eb0

Browse files
committed
fix(glsl): static arrays running
1 parent 22e3ee3 commit 8a82eb0

File tree

2 files changed

+4
-6
lines changed

2 files changed

+4
-6
lines changed

src/glsl/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ function handleAlloc(init, typeAnnotation, name) {
339339
if (init.arguments.length === 1) {
340340
const [first] = init.arguments;
341341
if (first.type === 'ArrayExpression') {
342-
allocation = `; ${first.elements.map((n, i) => `${name}[${i}] = ${handleNode(n)}`).join('; ')};`;
342+
const els = first.elements.map((n) => `${handleNode(n)}`).join(', ');
343+
allocation = ` = ${name}[${first.elements.length}](${els});`;
343344
} else {
344345
allocation = ` = ${handleNode(init.arguments[0])}`;
345346
}

test/glsl/index.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ float bar = float(foo[x][1]);
212212
});
213213

214214
const expected = `
215-
float[2] foo; foo[0] = 1.0; foo[1] = 2.0;
215+
float[2] foo = foo[2](1.0, 2.0);
216216
`;
217217

218218
assert.equal(glsl.trim(), expected.trim());
@@ -224,7 +224,7 @@ float[2] foo; foo[0] = 1.0; foo[1] = 2.0;
224224
});
225225

226226
const expected = `
227-
vec2[2] foo; foo[0] = vec2(1.0, 2.0); foo[1] = vec(3.0, 4.0);
227+
vec2[2] foo = foo[2](vec2(1.0, 2.0), vec(3.0, 4.0));
228228
`;
229229

230230
assert.equal(glsl.trim(), expected.trim());
@@ -252,11 +252,9 @@ vec2 bar(vec2 x, float y) {
252252
}
253253
`;
254254

255-
256255
assert.equal(glsl.trim(), expected.trim());
257256
});
258257

259-
260258
it('throw an error when type is forgotten.', () => {
261259
assert.throws(() => {
262260
buildGLSL(() => {
@@ -406,7 +404,6 @@ vec2 bar() {
406404
}
407405
`;
408406

409-
410407
assert.equal(glsl.trim(), expected.trim());
411408
});
412409

0 commit comments

Comments
 (0)