Skip to content

Commit efa358b

Browse files
authored
Merge pull request #8414 from processing/fix/strands-named-function
Fix p5.strands parsing of named function callbacks
2 parents e5566ec + 9584786 commit efa358b

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/strands/strands_transpiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1197,7 +1197,7 @@ const ASTCallbacks = {
11971197
recursive(ast, { varyings: {}, inControlFlow: 0 }, postOrderControlFlowTransform);
11981198
const transpiledSource = escodegen.generate(ast);
11991199
const scopeKeys = Object.keys(scope);
1200-
const match = /\(?\s*(?:function)?\s*\(([^)]*)\)\s*(?:=>)?\s*{((?:.|\n)*)}\s*;?\s*\)?/
1200+
const match = /\(?\s*(?:function)?\s*\w*\s*\(([^)]*)\)\s*(?:=>)?\s*{((?:.|\n)*)}\s*;?\s*\)?/
12011201
.exec(transpiledSource);
12021202
if (!match) {
12031203
console.log(transpiledSource);

test/unit/webgl/p5.Shader.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,26 @@ suite('p5.Shader', function() {
408408
});
409409
});
410410
suite('p5.strands', () => {
411+
test('handles named function callbacks', () => {
412+
myp5.createCanvas(5, 5, myp5.WEBGL);
413+
function myMaterial() {
414+
myp5.getPixelInputs(inputs => {
415+
inputs.color = [
416+
1,
417+
0,
418+
0,
419+
1
420+
];
421+
return inputs;
422+
});
423+
}
424+
const myShader = myp5.baseMaterialShader().modify(myMaterial, { myp5 });
425+
expect(() => {
426+
myp5.shader(myShader);
427+
myp5.plane(myp5.width, myp5.height);
428+
}).not.toThrowError();
429+
});
430+
411431
test('does not break when arrays are in uniform callbacks', () => {
412432
myp5.createCanvas(5, 5, myp5.WEBGL);
413433
const myShader = myp5.baseMaterialShader().modify(() => {

0 commit comments

Comments
 (0)